Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Svinja

macrumors newbie
Original poster
Oct 27, 2008
27
0
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...
 

Svinja

macrumors newbie
Original poster
Oct 27, 2008
27
0
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...
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

infoplist_editor.jpg


from the documentation.
 

Svinja

macrumors newbie
Original poster
Oct 27, 2008
27
0
Thx for you answer but this was the first thing i tried, along with Localizations key...doesnt work
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.