Created
August 27, 2012 21:01
-
-
Save mundstein/3492187 to your computer and use it in GitHub Desktop.
Easy way to localize independent of user setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The main localization class that does the hard work | |
-(NSString *) localized:(NSString *) key | |
{ | |
// langCode should be set as a global variable somewhere | |
NSString *path = [[NSBundle mainBundle] pathForResource:langCode ofType:@"lproj"]; | |
NSBundle* languageBundle = [NSBundle bundleWithPath:path]; | |
return [languageBundle localizedStringForKey:key value:@"" table:nil];; | |
} | |
// Assuming you have this function in a global class called utils, | |
// call this function with the following code (for example to output the word Settings | |
NSLog( [utils localized:@"Settings"] ); | |
// To change the language | |
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:langCode, nil] forKey:@"AppleLanguages"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment