Eng waleed qaffaf
Eng waleed qaffaf

Reputation: 152

IOS application Force to use English as Language

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

Answers (1)

nmh
nmh

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

Related Questions