apache / cordova-ios

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

How to add localisation to Location, Camera permissions #1111

Closed ir2pid closed 3 months ago

ir2pid commented 3 years ago

I can add the permission request explanation by adding the information in config.xml

        <platform name="ios">
        .
        .
        .
        <edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
            <string>Take pictures of ID</string>
        </edit-config>
        .
        .
        .
          </platform>

But how can I localise the Take pictures of ID for other languages.

erisu commented 3 months ago

Something like this will help you set localization for NSCameraUsageDescription:

In config.xml you will have the following defined.

<!-- setup your NSCameraUsageDescription message for the default language. (English) -->
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
    <string>need camera access to take pictures</string>
</edit-config>

<!-- 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.strings" target="ja.lproj/InfoPlist.strings" />

Create the InfoPlist.strings file and place it in a resource directory. This file will be the development file. When you run cordova prepare it will be copied into your iOS project. The copying is handled by the resource-file tag in config.xml.

Content of InfoPlist.strings

"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 or use a hook script to search for the file and update.