Get the Current Language in Device

Get the current language in device

If you want to get the selected language of your device, this might help you:

Locale.getDefault().getDisplayLanguage();

You can use Locale.getDefault().getLanguage(); to get the usual language code (e.g. "de", "en")

How to get application language and device language separately in android?

Get system language

Resources.getSystem().getConfiguration().locale.getLanguage();

Get app language

String currentLang = Locale.getDefault().getLanguage();

Getting current device language in iOS?

The solutions provided will actually return the current region of the device - not the currently selected language. These are often one and the same. However, if I am in North America and I set my language to Japanese, my region will still be English (United States). In order to retrieve the currently selected language, you can do:

NSString * language = [[NSLocale preferredLanguages] firstObject];

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):

List of ISO 639-1 codes

Then it's a simple matter of converting the two letter codes to the string you would like to display. So if it's "en", display "English".

EDIT

Worth to quote the header information from NSLocale.h:

+ (NSArray *)preferredLanguages NS_AVAILABLE(10_5, 2_0); // note that this list does not indicate what language the app is actually running in; the [NSBundle mainBundle] object determines that at launch and knows that information

People interested in app language take a look at @mindvision's answer

How to get system device language, swift iOS

Try this

UserDefaults.standard.stringArray(forKey: "AppleLanguages")

The output will be like - ["en-US"].

It'll return an array with language codes, first index is the current language set in iPhone's setting (it'll be a single item array if the preferred language order in settings is empty.)

Get the current language of the application not the device Android

Try this:

getResources().getConfiguration().locale

https://stackoverflow.com/a/12530405/6371926

How can I get the current device language on iOS/Android?

To get the language programmatically, on Android you can use:

Locale.Default.GetDisplayLanguage(Locale.Default)

On iOS :

var userLang = NSLocale.CurrentLocale.LocaleIdentifier;

Android get current Locale, not default

The default Locale is constructed statically at runtime for your application process from the system property settings, so it will represent the Locale selected on that device when the application was launched. Typically, this is fine, but it does mean that if the user changes their Locale in settings after your application process is running, the value of getDefaultLocale() probably will not be immediately updated.

If you need to trap events like this for some reason in your application, you might instead try obtaining the Locale available from the resource Configuration object, i.e.

Locale current = getResources().getConfiguration().locale;

You may find that this value is updated more quickly after a settings change if that is necessary for your application.



Related Topics



Leave a reply



Submit