Set another Development Region / Language


#1

I have built an app with german strings in source code because we don’t need any translations now or in the future for this product. In order to tell Xcode about that I set CFBundleDevelopmentRegion to “de” in my Plist file. This however didn’t do the trick. The only language that iTunes recognizes is English. (Even thought there’s no English localization available)

My 2nd attempt was to create a after prepare hook to manipulate the project.pbxproj file and set the developmentRegion and knownRegions to be both “de” as well. Unfortunately without success. It still lists “English” as the only available Localization in iTunes.

How can I publish my App with a single Language other than English?


#2

I found a workaround which requires a manual step in Xcode when building archives.

You still need to manipulate the project.pbxproj file and set the CFBundleDevelopmentRegion key thought.

Hopefully someone can come up with some solution that can be automated.


#3

Might want to look at https://github.com/rborn/nativescript-i18n


#4

So I have implemented nativescript-localize since nativescript-i18n is no longer maintained.

Here’s what my i18n directory looks like:
05

(I have added only one json file because I don’t need and want to provide any other languages.)

In the Info.plist I’ve added following key:

<key>CFBundleDevelopmentRegion</key>
<string>de</string>

The result in iTunes Connect:

My guess is that it still would require a change in project.pbxproj.
Isn’t there any practical solution to this problem?


#5

You could use xcodebuild to modify your project from the command line, and just script it into your build process.

Look at the Exporting and Importing Localizations Using Command-Line Utilities section of https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html.


#6

Thank you @jzgoda in the meanwhile I’ve came up with a very similar solution:

I think the combination of my attempt using nativescript-localize above and a hook to update project.pbxproj will most likely do the trick.

Here’s the hook hooks/after-prepare/set-xcode-development-region.js I’ve came up with:

var xcode = require('xcode');
var path = require('path');
var fs = require('fs');

// Insert your desired region here...
var targetRegion = 'de';

module.exports = function (hookArgs) {
    var platform = hookArgs.platform.toLowerCase();
    var platformPath = path.join(hookArgs.projectData.platformsDir, platform);
    var xcodeProjFileName = hookArgs.projectData.projectName + '.xcodeproj';

    return new Promise(function (resolve, reject) {
        if (platform === 'ios') {
            try
            {
                var projectPath = path.join(platformPath, xcodeProjFileName, 'project.pbxproj');
                var xcodeproj = xcode.project(projectPath);

                xcodeproj.parse(function(error) {
                    xcodeproj.pbxProjectSection()[xcodeproj.getFirstProject()['uuid']]['developmentRegion'] = targetRegion;
                    xcodeproj.removeKnownRegion('en');
                    xcodeproj.addKnownRegion(targetRegion);

                    fs.writeFileSync(projectPath, xcodeproj.writeSync());
                });
            }
            catch (error)
            {
                reject();
            }
        }

        resolve();
    });
};

You need to install one additional dependency to use it: npm i xcode@^0.9.3

I’ve uploaded the build to iTunes Connect and am still waiting for it to get processed so I can see if it works. I will let you guys know here.

Btw. I would like to create a hook-plugin for this. Unfortunately I have no idea, how I could allow the user to provide the targetRegion in a clean and elegant way. Is there a common solution for this problem?


#7

It’s still showing English, German even thought the contents of my .xcodeproj now look like this:

...
developmentRegion = de;
hasScannedForEncodings = 0;
knownRegions = (
    de,
);
...

I will try what I can get accomplished using the xcodebuild CLI Utilities you suggested @jzgoda tomorrow. This is really frustrating and something that the framework should solve thought. :-/


#8

@jzgoda I just have had a look at the documentation you referred to. Also I tried to find more information about it but I’m stuck. These commands are just providing functionality to export import localizations? It wont help me replacing the default english with a single german language or am I mistaken? How would I apply these commands? The only suggestions on how to solve this I found tell that I should manually manipulate the .xcodeproj file which I’ve done.

I’ve now found a directory that looks like it would cause my issue: platforms/ios/appname/en.lproj
I have tried to delete this directory recursively inside my after prepare hook. Unfortunately that caused the following error:

/~/app/platforms/ios/appname/en.lproj/InfoPlist.strings:0: error: The file “InfoPlist.strings” couldn’t be opened because there is no such file.

Please can anyone help?


#9

Sorry about that, I guess that page isn’t going to help you.

However, your idea of the hook seems good, but did you try adding it to before-prepare instead of after-prepare? It looks like that is where nativescript-localize is attempting to set it: https://github.com/lfabreges/nativescript-localize/blob/f3a34e7413378f9ed2fffb211cca95a1333d7163/hooks/converter.ios.ts#L53


#10

@jzgoda Thank you for the follow up. I’ve used an after-prepare hook because I’m not manipulating the Info.plist file. Instead I’m manipulating platforms/ios/app-name.xcodeproj/project.pbxproj which needs to be generated first. (Which happens during prepare phase)

I’ve came up with a NativeScript plugin that solves this issue: https://www.npmjs.com/package/nativescript-plugin-regions

It still requires a manual step if you target a single language but you will only have to do that when you are publishing a new version to the App Store.

I’m looking for help to automate this manual step: https://github.com/hettiger/nativescript-plugin-regions/issues/1