Reputation: 152
now my app needs to be running in english but when i run the application for the first time the default language of the device is used .
i tried this code :
@autoreleasepool {
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSUserDefaults standardUserDefaults] setObject:@"en_US" forKey:@"AppleLocale"];
[[NSUserDefaults standardUserDefaults] setObject:@"en_EN" forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
the problem remains , the first run of the application is wrong , but if you close the application and reopen it english is the default language any help ?
Upvotes: 1
Views: 546
Reputation: 2503
You should customize LocalizedString like this. When you start application, use UserDefaults to get language key, not use by default system
typedef enum{
e_language_japanese,
e_language_english
}ENUM_LANGUAGE;
NSString* NSCustomLocalizedString( NSString *key , NSString *comment)
{
NSString *rs = nil;
if( [[NSUserDefaults standardUserDefaults] integerForKey:KEY_LANGUAGE ] == e_language_japanese)
{
rs = NSLocalizedStringFromTable(key,@"Localizable.strings-ja",nil);
}
else
{
rs = NSLocalizedStringFromTable(key,@"Localizable.strings-en",nil);
}
return rs;
}
Upvotes: 2