Cordova Localization String Plugin
This plugin helps you to manage string files that you need natively, namely on Localizable.strings and InfoPlist.strings on iOS, and strings.xml on Android.
This plugin also lets you localize your app name on both iOS and Android.
How to Use
Install the plugin by fetching the dependencies
$ cordova plugin add cordova-plugin-localization-strings --save
Modify your project root to have the following structure:
Cordova Project Root | |__ translations | |__ app | |__ en.json |__ es.json |__ ja.json
A JSON file may look like this (Note: Breaking change from 1.0.0 onwards - new JSON format).
By default, the language for the Localizable.strings, InfoPlist.strings or strings.xml is taken from the filename.
For example, if the filename is es.json, the language is hence "es", and the plugin will create "/Resources/es.lproj/Localizable.strings" or "/values-es/strings.xml".
Install iOS or Android platform
cordova platform add ios cordova platform add android
Run the code
cordova prepare ios
Platform Specific Localizations
There are some platform specific localizations which differ for Android and iOS, for example for Android:
and for iOS:
In this case, you can use the locale in the json file to specify the platform localizations as in the following examples.
N.B. The "locale" key is optional (if platform localization is not required).
This plugin relies on node-xcode >= 0.9.0, node >= 5.0.0, cordova >= 6.0.0.
Do remember to install the other dependencies via the --fetch when installing the plugin.
This plugin helps in native localization in the following use cases:
Localizing App Name
The plugin will help to localize your app name if you require it to be named differently in different languages. Use the following json file format.
Localizing iOS Permissions
This plugin will help in localize the iOS permission descriptions, for example NSCameraUsageDescription. A full list of iOS permissions and other infoPlist strings that can be found here. (https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html "CocoaKeys")
Push notifications messages
Typically, there are 2 main ways push notifications can be localised:
- your app saves your user's selected language on the server, and pushes a localised string in the push notification to your user.
- your server pushes a key to the phone, and the app displays a localised version based on the key in the localization bundle, as determined from the user's phone OS's languauge.
This plugin helps in the latter approach.
More information about the respective string localizations and formatting here:
- Storing Localized Content in Your App Bundle (https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9)
- Formatting strings (https://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling)
The plugin will automatically generate Localizable.strings file using the following entry on iOS:
"HAVE_MAIL_TITLE" = "You have mail."; "HAVE_INVITE_MSG" = "%1$@ has invited you to game room %2$@";
And on Android, the respective locale's strings.xml:
You have mail.%1$s has invited you to game room %2$s
The plugin reads the assumed directory structure. The plugin reads from all the fields in config_ios and writes into the InfoPlist.strings, which will be placed in the respective locale.lproj directory. The rest of the strings in "app" will be placed in the Localizable.strings file and placed in the locale directory.
The plugin reads the assumed directory structure, the plugin will combine all properties in "config_android" and "app", and inserted into the strings.xml of the locale's /res/val-locale/strings.xml
Override platform specific translations:
app_android are detected they will be used and override keys from