Question

My application need to be localised in 2 languages: German and English. German should be Base language. It means that app should always localize to German except the language on device is english (in this case it should be on english)

I have custom *.string files for localisation and use localizedStringForKey:value:table to localise strings.

When I have only base localisation everything works fine. But in case if I add english localisation, in some reason localizedStringForKey:value:table just ignore Base localisation and always use English (for all languages)

Here how it looks like after I've added english: enter image description here

and here is how I localise strings:

[[NSBundle mainBundle] localizedStringForKey:@"key" value:@"" table:@"Shared"]

I'm testing on simulator and here is my language screen: enter image description here

Does anybody know what could be a problem? Thanks in advance!

Était-ce utile?

La solution

As I mentioned in the comments, you need to set the Localization native development region (CFBundleDevelopmentRegion) in the Info.plist to your language code. Xcode seems to set it to a en_GB or de_DE style region code, setting it to de (no region) will fix it. Note that by default it is en, but selecting United Kingdom or Germany will change it to use the longer codes.

Autres conseils

I have another solution, I think it works for you:

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;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top