InfoPlist.strings and iOS Push Notification Localization Automation

InfoPlist.strings and iOS Push Notification Localization Automation

One of the key features that sets Applanga apart from other localization platforms are its SDKs which allow synchronizing strings from apps without the need to send files around and even without Appstore updates.
But there are a few strings that the Applanga SDK cannot change at runtime because they are used by iOS directly without the running app e.g. strings for localizing push notifications and the several usage descriptions as well as the App Name defined in your Info.plist file. To automate the localization of these strings you should use the Applanga Command Line Interface (CLI). With the CLI you can up- and download .string files for your app from the command line and you can integrate that into your build or continuous integration platform.
To install and to get a basic understanding of how the CLI works please look at the Applanga CLI Documentation.
After you've done that the next 2 paragraphs will explain how to configure it to automate the localization process for these kinds of strings.

Localizing Push Notifications

I'll not explain the full process of how to set up and send push notifications for your iOS app so for that please have a look at the Apple Push Notification Documentation but in a nutshell you just need to provide a "loc-key" with your Push Notification payload and that key, as well as its translations, need to be in your Localizable.strings file to be localized.
If you've read the Applanga CLI Documentation you know that in order to localize files with it you need to specify them in the configuration file (.applanga.json) and for your Localizable.strings to be included in the configuration you're config should look something like this:

{
    "app": {
        "access_token": "5b1f..!..2ab", 
        "base_language": "en", 
        "pull": {
            "target": [
                {
                    "language": "en",
                    "file_format": "ios_strings",
                    "export_empty": true,
                    "tag": "Localizable_strings",
                    "path": "./Base.lproj/Localizable.strings"
                },
                {
                    "exclude_languages": ["en"],
                    "file_format": "ios_strings",
                    "tag": "Localizable_strings",
                    "path": "./<language>.lproj/Localizable.strings"
                }
            ]
        }, 
        "push": {
            "source": [
                {
                    "language": "en",
                    "file_format": "ios_strings", 
                    "tag": "Localizable_strings",
                    "path": "./Base.lproj/Localizable.strings"
                },
                {
                    "exclude_languages": ["en"],
                    "file_format": "ios_strings", 
                    "tag": "Localizable_strings",
                    "path": "./<language>.lproj/Localizable.strings"
                }
            ]
        }
    }
}

So, now on the Applanga Dashboard all strings that are under the tag Localizable_strings will be put in the respective Localizable.strings file whenever you're calling applanga pull and you can release them with the next app update.

Localizing the App Name

To localize app name and other things defined in Info.plist file you need an InfoPlist.strings file for your Base Language strings and put it in your Base.lproj folder.
Go to File->New->File , select Strings File under Resource tab for iOS , name it InfoPlist.strings. Select the Base.lproj folder as the location of InfoPlist.strings file. (By doing this, this InfoPlist.strings file is recognized as the one for the base language by XCode.)

Usually, there are two values in the Info.plist file that you want to localize for that.

  • CFBundleDisplayName  —  App name shown on the home screen
  • NSHumanReadableCopyright  —  Copyright message for your app

Set an app name and copyright for these two keys like below.

"CFBundleDisplayName" = "My App Name";
"NSHumanReadableCopyright" = "2018 Mbaas Development GmbH. All rights reserved.";

In order to have the Info.plist as well as the Localizable.strings updated via the CLI you need to modify the configuration file (.applanga.json) as follows:

{
    "app": {
        "access_token": "5b1f..!..2ab", 
        "base_language": "en", 
        "pull": {
            "target": [
                {
                    "language": "en",
                    "file_format": "ios_strings", 
                    "tag": "Localizable_strings",
                    "export_empty": true,
                    "path": "./Base.lproj/Localizable.strings"
                },
                {
                    "exclude_languages": ["en"],
                    "file_format": "ios_strings", 
                    "tag": "Localizable_strings",
                    "path": "./<language>.lproj/Localizable.strings"
                },
                {
                    "language": "en",
                    "file_format": "ios_strings", 
                    "tag": "info_plist",
                    "export_empty": true,
                    "path": "./Base.lproj/InfoPlist.strings"
                },
                {
                    "exclude_languages": ["en"],
                    "file_format": "ios_strings", 
                    "tag": "info_plist",
                    "path": "./<language>.lproj/InfoPlist.strings"
                }
            ]
        }, 
        "push": {
            "source": [
                {
                    "language": "en",
                    "file_format": "ios_strings", 
                    "tag": "Localizable_strings",
                    "path": "./Base.lproj/Localizable.strings"
                },
                {
                    "exclude_languages": ["en"],
                    "file_format": "ios_strings",
                    "tag": "Localizable_strings",
                    "path": "./<language>.lproj/Localizable.strings"
                },
                {
                    "language": "en",
                    "file_format": "ios_strings", 
                    "tag": "info_plist",
                    "export_empty": true,
                    "path": "./Base.lproj/InfoPlist.strings"
                },
                {
                    "exclude_languages": ["en"],
                    "file_format": "ios_strings", 
                    "tag": "info_plist",
                    "path": "./<language>.lproj/InfoPlist.strings"
                }
            ]
        }
    }
}

Now if you use the applanga push command all strings from the InfoPlist.strings will be pushed to the dashboard where you can translate them and then use applanga pull to fetch the translated .string files.

Localizing iOS Usage Descriptions

Besides the app name, there are a few more strings that are not localizable via the Applanga iOS SDK e.g. the several usage descriptions for the camera, location, calendar, photos and health usage. (NSCameraUsageDescription, NSLocationAlwaysUsageDescription, NSLocationUsageDescription, NSCalendarsUsageDescription, NSPhotoLibraryUsageDescription, NSHealthShareUsageDescription, NSHealthUpdateUsageDescription)
You can localize them with the CLI the same way as you localize the app name simple put the string keys into your InfoPlist.strings and use applanga push to upload and applanga pull to download them after the translators did their work.

So as you can see the CLI finally helps you to get rid of the last few manual localization steps to a fully automated app translation workflow.

NOTE: One thing you need to make sure in the CLI process is that you add all the languages that you're updating to your app target in xcode since else they will not be released with the app.