apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 987 forks source link

Localization in InfoPlist.strings #1094

Closed shanlin2dltk closed 3 months ago

shanlin2dltk commented 3 years ago

We have certain entries in *-Info.plist file needing localizations in different languages. Currently cordova-ios generate 12 languages by specifying 12 entries in , 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.

noahcooper commented 3 years ago

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

erisu commented 3 months ago

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.