0

I have an iOS 5 app that supports 3 different languages. Localizing an storyboard creates a copy in each language and each one must be translated.

The language selection depends on system settings, so if my iPhone has 'English' as a system language the choosen storyboard in my application will be the English one. If I change to Catalan, my app will show Catalan words.

This approach has several drawbacks in my opinion:

  • An app cannot be translated to languages not supported by Apple. This could be important for moniroty languages ( Catalan has not been supported until iOS 5 ).

  • If a user wants to have my app in Catalan but the rest of the system in English ?

So my question is how can I select the storyboard language at app startup time ? Is it possible at all ? Also it will work for strings localized using NSLocalizedString ?

Regards, JoanBa

Mansfield
  • 14,445
  • 18
  • 76
  • 112
joanba
  • 281
  • 2
  • 15

2 Answers2

0

It seems like you can split the storyboard into localized versions just like localized.strings as to how to do it?

This question has been answered before although I haven't tried from experience.

Community
  • 1
  • 1
SushiGrass Jacob
  • 19,425
  • 1
  • 25
  • 39
0

After reading the Jacob answer and testing a little bit, this is the code that has worked for me:

    int main(int argc, char *argv[])
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    // Reset system defaults to get the complete language list.
    [defaults removeObjectForKey:@"AppleLanguages"];
    // Default language choosen by user.
    NSString *defLanguage = [defaults objectForKey:@"Language"];
    NSArray *sysLangugages = [defaults arrayForKey:@"AppleLanguages"];
    // System default language: first element of array.
    NSString *sysLanguage = [sysLangugages objectAtIndex:0];
    NSArray *array = [NSArray arrayWithObjects:defLanguage, sysLanguage, nil];
    [defaults setObject:array forKey:@"AppleLanguages"];

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

Just restarting the app after changing the default language, all localized resources are changed: strings and storyboards.

Also tried this code in AppDelegate.m, in method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

but it doesn't work. Only in main.m works fine. I don't know why.

Note that with this code you can have an application with a language not supported by iOS.

Regards,

JoanBa

joanba
  • 281
  • 2
  • 15