10

I want to localize strings in my iphone app for en_GB and other 'en' sub-languages, but XCode and the iphone refuse to let this happen. I have created a localization of "Localizable.strings" for en_GB and en_US (I tried both hyphens and underscores) for testing purposes, but they just aren't recognized. The only language code that works is simply "en" (displayed as "English" in XCode).

I can't believe this isn't possible, so what am I doing wrong? I'm also hoping to get the typical 'cascading' behaviour where if a string isn't found in the sub-language e.g. "en_GB" then it should be taken from "en" if possible. Help?

Mike Weller
  • 45,401
  • 15
  • 131
  • 151

6 Answers6

6

When you choose 'English' from the list of languages on the iPhone preferences, that actually means the 'en_US' language.

So until apple update their software with additional sublanguages like "English (British)" etc. we are left with going by the locale region setting, and loading strings manually from another string table.

However, the language and regional locale are separated for a reason: a Spanish user in the UK may want dates/times formatted according to the local customs, but program strings in their native tongue. It would be incorrect to detect the regional locale (UK) and therefore display UK strings.

So basically there is no way to do this currently.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • Good answer! However, this raises the question: just what good is the Region Setting format for, if not for localizing strings? – Apophenia Overload Jul 22 '11 at 21:07
  • The region setting is used to format dates, currencies, to choose which characters separate fractional digits in a number, etc. – Mike Weller Jul 25 '11 at 11:47
4

What you're doing should work according to the docs. But it appears that the iPhoneOS implementation is at odds with the documentation. According to Radar 6158876, there's no support for en_GB language, only locale (date formats and the like).

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
2

This can actually be done - check my solution here - iPhone App Localization - English problems?

Community
  • 1
  • 1
rickerbh
  • 9,731
  • 1
  • 31
  • 35
  • 1
    This is now broken on iOS 8.1. [NSLocale preferredLanguages] returns zero results in main(). – Mike Oct 24 '14 at 14:53
2

I found the same problem.

BTW, if you look at the iPhone Settings -> General -> International menu, it makes the distinction between language and region quite clear:

Languages:
-English

Region Format:
-United States
-United Kingdom

The localization framework only appears to pay attention to the language, not the region.

I'm tempted to raise an enhancement request for this with Apple, as IMO it is reasonable that a user might want to use British English (for the text) whilst being in the United States (where, say, phone numbers should be in US format).

Dan J
  • 25,433
  • 17
  • 100
  • 173
1

Create a separate string resource, say UKLocalization.strings, and create localizations for each of your supported languages. For all localizations other than en this file is empty. For en, it contains only the strings that have unique en_GB spelling.

Next, you create a replacement for NSLocalizationString that will first check the UKLocalization table before falling back to the standard localization table.

e.g.:

static NSString* _locTable = nil;
void RTLocalizationInit()
{
    _locTable = nil;

    NSString* country = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
    if ([country isEqual:@"GB"])
    {
        _locTable = @"UKLocalization";
    }
}

NSString* RTLocalizedString(NSString* key, NSString* ignored)
{
    NSString* value = nil;
    value = [[NSBundle mainBundle] localizedStringForKey:key value:nil table: _locTable];
    if (value == key)
    {
        value = NSLocalizedString(key, @"");
    }
    return value;
}
Darren
  • 25,520
  • 5
  • 61
  • 71
1

I’m not sure in which version of iOS it was introduced, but iOS 7 definitely has a ‘British English’ language preference that will pick up resources from the en_GB.lproj directory. The various hacks floating around the web shouldn’t be necessary unless you’re after a more specialised* dialect.

*see what I did there ;)

Sam
  • 4,694
  • 2
  • 36
  • 47
  • Are you sure this works? I used one of the hacks: http://stackoverflow.com/questions/3308519/iphone-app-localization-english-problems. But ios 8.1 broke that hack. So, I'm attempting to implement your solution. My en_GB.lproj localizations are not being picked up. – Mike Oct 24 '14 at 14:51
  • The problem is where the user is in Britain but (reasonably) selects their language as "English" rather than "British English". The app is then localized for US English – Jonathon Horsman Feb 11 '15 at 16:17