hyn
hyn

Reputation: 473

Obtaining localized strings for a particular language

I am trying to obtain localized strings for the English language (in en.lproj/Localizable.strings) for use as default values when the localized string for the user's preferred language is not found.

I want to pass in that default value to this method:

[[NSBundle mainBundle] localizedStringForKey:key value:defaultValue table:nil]

But I haven't found an easy way to obtain that value. I can create a dictionary from the strings file but I was wondering if there is a more convenient way?

Upvotes: 1

Views: 727

Answers (2)

user557219
user557219

Reputation:

Is English your development region (language)? If so, by default any localisable string that hasn’t been translated to the user’s preferred language will fallback to English. This is governed by the CFBundleDevelopmentRegion key in your application plist. From the official documentation,

CFBundleDevelopmentRegion

CFBundleDevelopmentRegion (String - iOS, Mac OS X) specifies the native region for the bundle. This key contains a string value that usually corresponds to the native language of the person who wrote the bundle. The language specified by this value is used as the default language if a resource cannot be located for the user’s preferred region or language.

This key is automatically added to the Info.plist file create by Xcode’s templates. Its ‘friendly’ representation is Localization native development region.

Upvotes: 1

Mel
Mel

Reputation: 2299

I think it Cocoa uses the english strings as fallbacks automatically.

Upvotes: 1

Related Questions