2
votes

In our project we have multiple build targets which each use an English, French and Base (English) localization files. Some of these are string files while others are localized storyboard files that have been constructed to include both of these languages.

What is the best way to, on a single build target, restrict the localization so that it only uses English and not French while at the same time keeping it so all the other build targets still have both English and French localizations working? I try to not include the French localizations for that specific build but that removes the entire localization file since this seems to be done at project level.

I found a few posts here but nothing that worked for disabling a single localization language from a specific build target while leaving the others alone.

We are working in Xcode 6 currently.

1

1 Answers

1
votes

I'm not sure it's exactly what you're looking for, but if you want to force your app to be displayed in a specific language, you can do that without removing the other localizations from your project. You can change your main.m implementation to:

int main(int argc, char *argv[])
{
    @autoreleasepool
    {
        if (/*Some condition for this build*/)
        {
            NSString *newLanguage = [[NSUserDefaults standardUserDefaults] objectForKey:kNewLanguageCode];

            [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:newLanguage, nil] forKey:@"AppleLanguages"];
        }
        else // If you want other conditions, or just do nothing if you want to support the device's current localization settings
        {
            [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
        }

        [[NSUserDefaults standardUserDefaults] synchronize];

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

I know it's not exactly what you asked about, but I thought that it may solve your problem from a slightly different direction, so I hope this helps. Good Luck!