How iOS Checks this
For native iOS project, the process is actually quite similar to how we manage localization in web-based apps. We setup a string file that is for the languages we want to support and create a mapping of keywords and their translated version. Then the translated value can be accessed in the app via
NSLocalizedString. But for hybrid apps that do not use native code, what do we do?
Well turns out, we can trick Xcode/iOS App store by declaring supported languages in a plist file.
In this plist file, we have an entry called
Localizations, which is an array. With this entry, we can add list out the languages our app supports.
Perfect! Now we can just add the languages we want to support in there and be off to the races! But we can take this even further and make the whole process simpler.
For some people, opening up xcode is not ideal, and I am one of those people. Plus, once we add the language support in XCode, we need to commit the entire project in git, which isn’t ideal. Instead, we can rely on a plugin to do the work for us. Enter the localized-strings plugin.
This plugin, has zero native code, no JS interface, and is not loaded at runtime (how sweet is that), but instead is a simple hook that runs during
cordova build. To install this plugin you can run:
cordova plugin add cordova-plugin-ios-localized-strings --variable MAIN_LANGUAGE=English --variable ADDITIONAL_LANGUAGES=en-US,es,it
Now our two variables are:
MAIN_LANGUAGE: The projects main language
ADDITIONAL_LANGUAGES: The locales we want to support
Once this plugin is installed and we build iOS, it will take care of all that manual work we would have had to do before.