Default langauage for localized string

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

  1. Svinja macrumors newbie

    Joined:
    Oct 27, 2008
    #1
    Hi,

    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:
    Code:
    	
    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

    Joined:
    Oct 27, 2008
    #2
    i found a solution to this:
    Code:
    @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];
    }
    
    @end
    
    it works great, but then i couldnt use NSLocalizedString simply...

    i tried with this:
    Code:
    [[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

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    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

    [​IMG]

    from the documentation.
     
  4. Svinja thread starter macrumors newbie

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

Share This Page