cordova-ios icon indicating copy to clipboard operation
cordova-ios copied to clipboard

Localization in InfoPlist.strings

Open shanlin2dltk opened this issue 4 years ago • 1 comments

We have certain entries in *-Info.plist file needing localizations in different languages. Currently cordova-ios generate 12 languages by specifying 12 entries in <CFBundleLocalizations>, which in turn generates 12 folders under Resources like: da.lproj de.lproj en.lproj ... zh.lproj Under each of these folders, there is InfoPlist.strings file, which according to this Apple documentation should store all localized strings in key value pairs.

However, the current cordova generated 12 InfoPlist.strings files don't follow the key value paradigm, instead they have a long paragraph with English and other language mixed.

My question is: how do I specify key value pair in those files so that they can be localized?

cordova client 9.0.0, cordova-ios 6.2.0, xcode 11.6.

shanlin2dltk avatar Mar 29 '21 19:03 shanlin2dltk

You can use the plugin cordova-plugin-localization-strings to accomplish this.

noahcooper avatar Apr 08 '21 16:04 noahcooper

I think localization is probaly out of scope but you could try either using that plugin or maybe something like this in config.xml.

<!-- enable the supporting languages CFBundleLocalizations (e.g. English & Japanese) -->
<config-file parent="CFBundleLocalizations" target="*-Info.plist" mode="overwrite">
    <array>
        <string>en</string>
        <string>ja</string>
    </array>
</config-file>

<!-- copy the Japanese localization file InfoPlist.strings file -->
<resource-file  src="resource/ios/InfoPlist-ja.strings" target="ja.lproj/InfoPlist.strings" />

Create the development file InfoPlist-ja.strings and place it in a resource directory.

When you run cordova prepare it will be copy this file (resource-file) into the target path which resides in the iOS project. Note that the target file name does not match source. I recall the file name must match InfoPlist.strings in the iOS project to work.

Example InfoPlist.strings content:

"NSCameraUsageDescription" = "写真撮影のためのアクセス";

One important note is that if a third-party plugins also creates the InfoPlist.strings file for the same locale, this change might overwrite its content. In this case you might need to manually manage the InfoPlist.strings for all plugins or maybe use hook scripts instead of resource-file.

erisu avatar Mar 08 '24 15:03 erisu