Localize the `Info.plist` permission descriptions for cordova ios build

I need a structure that can automatically define permission descriptions for localize that xcode supports when building with cordova via Meteor. I am open to your suggestions.

Description:
In our Meteor project, we are getting the mobile build with cordova. And we need certain permissions for ios build. For these, this addition has been made in mobile-config.js:

App.appendToConfig(`
  <platform name="ios">
    <edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
      <string>We use your location information to make it easier for you to select your service area.</string>
    </edit-config>

    <edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
      <string>We use it to save the files you download from the application.</string>
    </edit-config>

    <edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
      <string>We use your camera during image and video sending.</string>
    </edit-config>

    <edit-config target="NSMicrophoneUsageDescription" file="*-Info.plist" mode="merge">
      <string>We use your microphone to send voice recordings.</string>
    </edit-config>
  </platform>
`)

But as you can see the descriptions here are in English and I want to define them with 4 different language codes as en,tr,ar,fr. In order to display the appropriate description according to the user’s phone language.

What I tried to do this:
1- I tried to add different language codes by doing appendToConfig but I guess I was not successful because there is no such usage on cordova side.

2- In my research I saw that cordova-plugin-localization-strings - npm plugin is used for this localization. I added this cordova plugin to the project. But as a requirement. Creating a translations/app folder in the root directory of the cordova-build folder and language files such as en.json,tr.json,en.json,ar.json,fr.json for each language.
I couldn’t find a structure that moves this folder from meteor during the build phase into cordova-build in meteor.
I tried App.addResourceFile('') but it moves it to resource-file folder but I need to move it to root directory.

{
  "config_ios": {
    "NSLocationWhenInUseUsageDescription": "We use your location information to make it easier for you to select your service area.",
    "NSPhotoLibraryAddUsageDescription": "We use it to save the files you download from the application.",
    "NSCameraUsageDescription": "We use your camera during image and video sending.",
    "NSMicrophoneUsageDescription": "We use your microphone to send voice recordings."
  }
}
App.addResourceFile('translations/app/en.json', 'translations/app')
App.addResourceFile('translations/app/tr.json', 'translations/app')

I tried to set the moved folder to the plugin but that didn’t work either.

App.appendToConfig(`
  <plugin name="cordova-plugin-localization-strings" spec="~5.0.5">
    <variable name="TRANSLATION_PATH" value="/resource-files/Users/username/Repos/Test/meteor-blaze-cordova-test/translations/app" />
  </plugin>
`)

When I manually move the translations folder, I can see the variables on x-code but it does not change the descriptions for the relevant permissions.

You can do this via xCode. Once you build the app and open it in xCode, copy everything you need in the folder structure you find in Cordova. This was (not sure if it still is) the normal way to add sound files for notifications for IOS.

Doing this in xCode is a workaround. I don’t want to do this on xCode every time. We are doing multiple deployments and doing it every time is extra work and everyone should be able to do it.

Ok … an idea.
In the past this has been done in Meteor: Add a special 'cordova-build-override' folder. · meteor/meteor@0b6cf4f · GitHub
I suppose this still works, I still find this structure in some of my old projects which I no longer need/maintain. Simply put, in your root folder (e.g. app/) create the cordova-build-override folder. This will help you to commit those translations files to your code repo for all other users.
As you can read in the link above, those files will be automatically copied to resources based on the folder structure you use inside cordova-build-override folder.
Then you can fork the plugin in your own repo, amend this default path to your convenience to read from resources: https://github.com/kelvinhokk/cordova-plugin-localization-strings/blob/b5332bc9bf34f42aa08d20964fe8d8c2b98cb241/plugin.xml#L13
and install the plugin from your git commit (e.g. cordova-plugin-facebook4@GitHub - Basgrani-Org/cordova-plugin-facebook4: Use the latest Facebook SDK in your Cordova and Ionic projects)

1 Like