In my iOS app I need an option to change language. Can we change it without changing the language in the device settings
Asked
Active
Viewed 2,044 times
-1
-
1go through link .This will solve your problem http://createdineden.com/blog/post/language-changer-in-app-language-selection-in-ios/ – Kuldeep Singh Jun 01 '16 at 12:21
3 Answers
2
You can use following code to set the language
- (void) setLanguage:(NSString*) lang {
NSString *path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"];
if (path == nil) {
myBundle = [NSBundle mainBundle];
} else {
myBundle = [NSBundle bundleWithPath:path];
}
if (myBundle == nil) {
myBundle = [NSBundle mainBundle];
}
}
And after that you can get the localizations with
- (NSString*) localizedStringForKey:(NSString*) key {
return [myBundle localizedStringForKey:key value:@"" table:nil];
}

Ketan Parmar
- 27,092
- 9
- 50
- 75

Miro
- 97
- 3
0
For example store different static json/plist and etc in your app with different languages strings and when you switch option parse this and set to labels.

iSashok
- 2,326
- 13
- 21
-
-
In UI you can add a switch button in some settings page or in code check in code `[NSLocale currentLocale]` or `[NSLocale systemLocale]` but for it better use a standard localized.strings – iSashok Jun 01 '16 at 12:36
0
i am not sure but try this code once using NSUserDefaults
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableArray* languages = [userDefaults objectForKey:@"AppleLanguages"];
[languages insertObject:@"de" atIndex:0]; // ISO639-1
[[NSUserDefaults standardUserDefaults] synchronize];