Connected issue: Non-English default language for iOS App?
I am wondering how to check the current localization of my app in code. For example: I want to check if the app is running with German localization (.strings, storyboard) This line of code:
[[[NSLocale preferredLanguages] objectAtIndex:0] isEqualToString:@"de"]
doesn't provide the correct answer. Because if a user's language list in device settings looks like this for example (french, german, english) and we have only localization for english and german, application is launched in german but the above condition isn't fulfilled.
Localization is the process of translating and adapting your app into multiple languages and regions. Localize your app to provide access for users who speak a variety of languages, and who download from different App Store territories.
lproj folder is a directory that stores language-specific resources. See Localized Resources in Bundles and Language and Locale IDs for details. If none of the user's preferred languages are supported by your app, iOS chooses the language matching your app's development region ( CFBundleDevelopmentRegion ).
My naive solution would be to create a localized string "LanguageCode" which is set to "de" in the german string file and to "en" in the english string file
e.g.:
if ([NSLocalizedString(@"LanguageCode", @"en, de etc.") isEqualToString:@"de"]) {
// german
}
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
This will return a two letter code for the currently selected language. "en" for English, "es" for Spanish, "de" for German, etc. For more examples, please see this Wikipedia entry (in particular, the 639-1 column):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With