0
votes

I have a question on how to set the default language in an Xcode project. My Mac OS X App supports German and English.

Everytime English is not selected in Systemsettings, default language is German. I want to switch default language to English, so that non-german users get an English UI. Changing "Localization native development region" in Plist file to English didn't solve the problem. I tried to do it within the code but this is not what Apple recommends in their HIGs.

Sampleproject is hosted on Github.

https://github.com/christian123456/xcodelocalization

Xcode Version is 5.1.1

I recently added the screenshots to the repository. As you can see in the "german incorrect.png" screenshot, French and Portuguese languages are chosen but Mac OS picked German as language. I want the language to be English.

2
Please add some screenshots and provide further informations. - imizeropt

2 Answers

0
votes

Testing and analyzing

I've added -NSShowNonLocalizedStrings YES into scheme-editor > Run .app > Arguments > Arugments Passed On Launch. This turns any string it cannot find a localized variant for into uppercase. The result is, I see all uppercase.

To switch language for developing use -AppleLanguages (it). As result, the en localization appears.

To switch the language of an app, you can also use the following app: https://itunes.apple.com/de/app/app-language-chooser/id451732904?l=en&mt=12

For more information read here.

Solution

After a little searching and testing, I found this solution:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", @"de", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

This would set the language english as default.

0
votes

Another option is to create your own localization class. Call your class, and it can force localization into any language you want:

- (NSString*) MyLocalizedString:(NSString*) label;
{
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSString* preferredLanguage = [defs objectForKey:@"LocalizedLanguage"];
    NSString *path = [[NSBundle mainBundle] pathForResource:preferredLanguage ofType:@"lproj"];

    NSBundle* languageBundle = [NSBundle bundleWithPath:path];
    NSString *result = [NSString stringWithFormat:@"%@",[languageBundle localizedStringForKey:label value:@"" table:nil]];

    return(result);
}

- (NSLocale *) forceEnglishLocalization;
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];     
    [defaults setObject:@"en" forKey:@"LocalizedLanguage"];  

    NSLocale * currentLocale;

    currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];

    return(currentLocale);
}

Need help localizing your Xcode apps?

https://itunes.apple.com/mg/app/generate-localizable-strings/id890673579?mt=12