Sunday, July 10, 2011

Find User's Language in iPhone

If you are writing an application where you want to know what language is set in user's setting, then you can use following code snippet. This will give you an idea how to check for any other language, this code only checks for German and English.

              NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
    if([currentLanguage compare:@"de"] == NSOrderedSame
        NSLog(@"Its German");
    else if([currentLanguage compare:@"en"] == NSOrderedSame
        NSLog(@"Its English");

No comments:

Post a Comment