iOS Localization: How to localize your app with Transifex
When it comes to iOS and localization, Apple offers an integrated experience right within Xcode. Adding new locales and separating the localizable strings from code or the UI is mostly an automatic and easy process. Most of the issues emerge when teams want to translate, update and maintain those strings throughout the lifetime of the product.
Xcode allows developers to export all of the localizable strings of a project into a .xliff file, which they can hand over to a translation team or service for localization. After localization for a target locale is complete, they can add the new translations to the application by importing the updated .xliff file back to Xcode.
The current state of iOS localization leaves a lot of room for improvement: Issuing an App Store application update just to amend some translations can be quite a lengthy process. Furthermore, having to deal with .xliff files manually can introduce several issues, such as versioning or missing translations. Fortunately, as we are going to see in this post, Transifex Native SDK provides quick and easy solutions to streamline to mobile app localization process.
This post will go over the most important features, highlighting ways you and your team can improve the iOS localization process of your application(s).
Over-the-air Translation Delivery
The essence of the over-the-air translation delivery is that teams can now update the translated strings without issuing a new application update.
When using the Transifex Native SDK, you -as the developer- can bundle the translated strings within your app so that the SDK can use them as soon as it initializes.
You can also control when the SDK will attempt to update the stored translations from Transifex using the asynchronous fetchTranslations method. Although we recommend calling this method when the application launches, that part is completely up to you and your application’s needs. Your application might want to update its translations under different circumstances, for example when the user explicitly requests it, or when there is only a WiFi connection active.
When the SDK downloads the new strings, the translation cache is updated and those translations are available on the next application launch. The fetchTranslations method will also notify you of its completion via a completion handler, and it is up to you to handle this event in your application, for example informing the users that an update is available.
Real-Life Example
Let’s see how this works in practice:
- Developers of the “Awesome” app push the strings to Transifex via the txios-cli tool (more on that below).
- The localization team translates the pushed strings.
- Developers use the pull command of txios-cli, to download and store those translations in a file (txstrings.json).
- Developers bundle the file with the application so that as soon as the SDK initializes it will attempt to load the stored translations from this file.
- The developer team adds a call to the fetchTranslations method in the application launch, so that the application can update the cached translations if a new version is available.
- The team releases a new version on the App Store, but soon after, the support team identifies a couple of missing strings and incorrect translations.
- Without having to re-bundle those translations and issue a new update, the team can just add the missing translations and fix the incorrect ones from the Transifex web interface. The application will then automatically download and update said translations and will serve them on the next application launch! 🍾
Note: As of May 2022, Transifex Native comes with automatic CDS cache invalidation, which means that translations should be pushed automatically to the app without developer involvement.
Pushing Source Strings to and Pulling Translations from Transifex
Alongside the Transifex Native SDK, Transifex offers a new command-line tool so that iOS developers can interface with Transifex CDS directly, without needing to deal with intermediate files (.xliff) and containers (.xcloc).
Pushing Source Strings
Using the push command of the command-line tool, you can point to your application’s Xcode project and have the tool export, package and send all of the source strings of the application to Transifex.
To achieve that, just install txios-cli following the instructions found on the repository and execute a command similar to the one below:
txios-cli push --token <your_transifex_token> --secret <your_transifex_secret> --project <Awesome.xcodeproj>
The push command behavior can be controlled via a number of different arguments. You can learn more about the arguments here or by executing the following: txios-cli push –help
Pulling Translations
As mentioned above, developers can also use the command-line tool to download (or pull) the translations from Transifex into a file that can later be bundled within the app. Just like the push command, the pull command is also a one-liner:
txios-cli pull --token <your_transifex_token> --translated-locales <comma_separated_list_of_locale_codes> --output <output_directory>
For a full argument list of the pull command, you can execute the following: txios-cli pull –help
The pull command requires a list of the translated locales that will be downloaded from Transifex and an output directory where the resulting txstrings.json file will reside.
After downloading the txstrings.json file, you can drag and drop it within your application’s Xcode project, making sure that the ‘Copy Bundle Resources’ build phase of the main application target includes it.
Ability to Change the Localization Locale in-app
Since iOS 13, users can specify a different localization for each application via a setting found under each application’s settings in the Settings app.
The above behavior is supported with Transifex Native SDK via its default TXPreferredLocaleProvider, but developers can take it a step further: The SDK provides the option to offer your own in-app locale selector or override the locale preference if another source is to be used (for example from a remote server). The TXCurrentLocaleProvider is the protocol to be used to override the current locale to be used by the SDK.
Handling Pluralization in the Transifex UI
The Transifex Native SDK for iOS also supports pluralization out of the box. The command-line tool will detect, parse and push to Transifex any existing pluralization rules found in the source locale. At the same time, the SDK will properly render the translated pluralization strings in the iOS application.
This feature minimizes the risk of incorrect translations due to the difficult structure of the pluralization files (.stringdict), as the team will handle all of the pluralization translations directly within the user-friendly Transifex web interface.
The above iOS localization guide covers the most impactful features that Transifex Native iOS SDK offers. Leveraging those features for your team will drastically improve the localization process and eliminate any of the aforementioned limitations that you may be currently facing.