How do I get current application locale?

locale.current.language code always en
how to get current language code
ios get locale programmatically
nslocale
swift get locale code
ios get current locale identifier
swift get locale of device
ios get current region

I need to get current locale. Not user locale but my application locale.

Let's say my application has two localizations (in project settings): English (default) and French. If user sets French language on iPhone then my application will display French interface. If user sets German language on iPhone then my application will display English interface (because English is default).

So how do I get current application locale that is showing right now? Thanks in advance.

The selected answer returns the current device language, but not the actual language used in the app. If you don't provide a localization for the preferred language in your app:

NSString *language = NSBundle.mainBundle.preferredLocalizations.firstObject;

NSLocale *locale = NSLocale.currentLocale;
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString *country = [usLocale displayNameForKey:NSLocaleCountryCode 
                                          value:countryCode];

NSLog(@"country: %@", country);

How to Get the current language in Android device?, While doing internalization in android application, we should know what is the current language in android device. Locale; public class MainActivity extends AppCompatActivity { TextView language; @Override protected� _locale_t _get_current_locale(void); Return Value. A locale object representing the current locale. Remarks. The _get_current_locale function gets the currently set locale for the thread and returns a locale object representing that locale. The previous name of this function, __get_current_locale (with two leading underscores) has been deprecated.

There may be an easier way than this (see other answers), but this one is most robust, and as long as the general principle of localizing an app through a strings-file doesn't get obsoleted, this method will work.

Generally, you don't need to get the application locale (but read on, it's possible!) If you want localized text, you use NSLocalizedString(). If you need to localize images you use localized resources, and so on. However, there are reasons that I can think of which would make it nice to get the "application locale", as you call it: for example for analytics (you want to know in which language your app is used), or for providing a consistent one-language interface to the user if you use server-based communication (e.g. to localize the server error messages in the same language that the user is seeing inside the app.)

If you want to get the localization of the app that is currently visible, I suppose you have a Localizable.strings file for each supported locale. So, in the Englisch strings-file you can add the line

"lang" = "en";

and in the French string-file you add the line

"lang" = "fr";

then, you can always get the application-locale by calling NSLocalizedString("lang") (swift) or NSLocalizedString(@"lang") (objective-C). And of course, whenever you add a new localization to your app, you have to set a "lang" entry into the new localizations strings-file.

NSLocale returns different current…, +(NSLocale*)deviceLocale; //Device locale, even if the app is not localized in the given language. My app displays dates and I've had a couple users complain that � Use setlocale(LC_ALL, NULL) to get the current locale – Kishan Vaishnav Nov 30 '18 at 8:57. Compiling an application for use in highly radioactive environments.

In Swift 3 use:

let language = Bundle.main.preferredLocalizations.first

Android localization: Step-by-step, Change Application Locale Programmatically that returns a wrapper Context holding a modified locale of the current activity context, like so:. The system locale defines the bitmap fonts and code pages (ANSI or DOS) that are used on the system by default. The system locale setting affects only ANSI (non-Unicode) applications. The language for non-Unicode programs is a per-system setting. To Find Current System Locale in Windows 10, do the following. Open Settings. Go to Time & Language.

You can get country code from locale, this way,

NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];

Get country code, e.g. es (Spain), fr (France), etc.

You can map this code for your interface selection.

Hope this help you.

Language and locale resolution overview, Your app's default language is en_US (US English), and it also has Spanish strings localized in es_ES resource files. A device is set to es_MX. I need to get current locale. Not user locale but my application locale. Let's say my application has two localizations (in project settings): English (default) and French. If user sets French language on iPhone then my application will display French interface. If user sets German language on iPhone then my application will display English

you can get selected language using following code.

NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];

if ([language isEqualToString:@"fr"]){//French
    [do  your stuff]
}
else{//English

   [do  your stuff]
}

List_of_ISO_639-1_codes

Hope this will help you.

kony.i18n Namespace, The current locale that is being used by the application is returned. Exceptions. 1300 - i18n error or Locale not supported error. Implementation Details. The current� In .NET 4.0, new threads do not inherit the locale of the thread they are created from. I did set CurrentCulture and CurrentUICulture per the MSDN documentation and all of the tests yesterday passed, so that's a good thing.

What Are Locales and How Do I Use Them?, The application-specific data is contained in resource bundles. The program uses a Locale object to identify what the current locale is and to decide which� The application must be able to retrieve and set specific information about available locales and languages. Each element of locale information, such as the name of a particular day of the week or the character used as a decimal separator, has a corresponding constant. The available constants are defined in Locale Information Constants.

Setting a Current Locale for Your Application, All ILE COBOL applications running on the AS/400 and using locales of type * LOCALE have a current locale that is scoped to the activation group of the program� LOCALE_USER_DEFAULT which identifies the locale of the current user; it can be changed via the Control Panel's Default Locale setting. An application can retrieve these two predefined locale identifiers by calling the GetSystemDefaultLCID and GetUserDefaultLCID functions, respectively. The Thread Locale is maintained on a per-application thread

get current locale in app service provider, Hi, I'm using Laravel 5.6 with with Laravel localization package, what am trying to is to get current selected language in app service provider App::g locale Locale object to free. Remarks. The _free_locale function is used to free the locale object obtained from a call to _get_current_locale or _create_locale. The previous name of this function, __free_locale (with two leading underscores) has been deprecated. By default, this function's global state is scoped to the application.

Comments
  • Great! Is there a way i can convert it to NSLocale?
  • Stealing other people's answer is not something we do on Stack Overflow, especially without credit. If an answer to another question can solve it then vote to close as duplicate. Don't steal the answer.
  • As mentioned, this gives you he iPhone System language. [[NSBundle mainBundle] preferredLocalizations].firstObject gives the "best match" of the apps languages with the users prioritised languages list.