Default langauage for localized string

Discussion in 'iOS Programming' started by Svinja, May 19, 2010.

  1. Svinja macrumors newbie

    Oct 27, 2008

    i have 3 languages in my app, fr, it and de. I created .string files and everything works ok. But what if current iphone language is some other language, like spanish? I would like that if current language is something else then fr, it and de, then use "fr" strings as default. So basically the question is how to set some of those languages to be defualt one?
    i am using this to show langage:
    NSLog(@"Welcome Text: %@", NSLocalizedString(@"WelcomeKey", @""));
    Currently if the current langage is some other, then it uses "it"(italian) strings but i want it to use french.
    Any help would be appreciated...
  2. Svinja thread starter macrumors newbie

    Oct 27, 2008
    i found a solution to this:
    @implementation Language
    static NSBundle *bundle = nil;
    +(void)initialize {
     NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
     NSArray* languages = [defs objectForKey:@"AppleLanguages"];
     NSString *current = [[languages objectAtIndex:0] retain];
     [self setLanguage:current];
      example calls:
      [Language setLanguage:@"it"];
      [Language setLanguage:@"de"];
    +(void)setLanguage:(NSString *)l {
     NSLog(@"preferredLang: %@", l);
     NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
     bundle = [[NSBundle bundleWithPath:path] retain];
    +(NSString *)get:(NSString *)key alter:(NSString *)alternate {
     return [bundle localizedStringForKey:key value:alternate table:nil];
    it works great, but then i couldnt use NSLocalizedString simply...

    i tried with this:
    [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]];
    but that doesnt work...
    so the workaround is found but original question still stands...
  3. robbieduncan Moderator emeritus


    Jul 24, 2002
    It should default to the development language you set in your Info.plist. This is shown in with the key "Localization native development re" (I think this has been truncated) in this image


    from the documentation.
  4. Svinja thread starter macrumors newbie

    Oct 27, 2008
    Thx for you answer but this was the first thing i tried, along with Localizations key...doesnt work

Share This Page