1
votes

I have an iOS application that is localized in multiple languages. I have Localizable.strings files for English, Dutch and Dutch (Belgium). The problem is that when Dutch is set as the device language and Belgium as the country, the Dutch strings are used and NOT the Dutch-Belgium strings.

I've added some logging to make sure that the correct language is set on the device, and it appears to be correct:

NSLocale *locale = [NSLocale currentLocale];    
NSString *language = [locale displayNameForKey:NSLocaleIdentifier
                                             value:[locale localeIdentifier]];
NSLog(@"language %@", language);

This prints out

2015-04-09 11:49:26.227 MyTestApp[222:7459] language Nederlands (Belgiƫ)

But if I try to get a string using NSLocalizedString I get the Dutch resource, not the Dutch Belgium one.

I've tested this on an iPhone 5s running 8.1 and on several 7.1/8.1 simulators and I can't get it to work. The interesting thing is that if I forcefully set the language to Dutch (Belgium) in XCode under Edit Scheme -> Application Language, the correct language is used.

1

1 Answers

0
votes

It turns out that the problem is that Xcode creates resource folders for each language with a hyphen separating the language and region, e.g. nl-BE.proj. However, the locale code uses an underscore, e.g. nl_BE, so the region is never matched. This appears to be an XCode bug.

The solution is to change the locale so that it includes a hyphen as discussed here https://stackoverflow.com/a/14357315/416214