I want to detect a user's locale (not their location). The problem is that none of the methods seem reliable.
Pros
Cons
Conclusion
Pros
Cons
Conclusion
Pros
Cons
Conclusion
Pros
Cons
Conclusion
It now seems like detecting a user's locale is harder than ever while detecting their physical location has become easier. The big offender is Safari which should at least reflect the OS settings by default on OSX but Chrome isn't setting any examples either. Even if people install their local dictionary to Chrome I really doubt they will also drag it to the top of the list.
I can't blame Mozilla and Opera for getting dragged down by other browsers misreporting to their download pages. However it would mitigate the problem if they would switch their download pages to use geolocation instead of presumably looking at Accept-Language.
But really, what options are left to detect a user's locale now that IE is no longer dominant? Is there anything left?
To get the user's locale in the browser, access the first element of the languages property on the navigator object, e.g. navigator. languages[0] . The property returns an array of strings that represent the user's preferred languages.
A locale is a location-based language setting that determines which conversational settings and strings to display. The user specifies their locale using settings on their device. They may change this setting whenever they wish, including during a conversation with a Business Messages agent.
A user locale specifies the default settings that a user wants to use for formatting dates, times, currency, and numbers. IBM Cognos software uses this information to present data to the user. IBM Cognos software obtains a value for user locale by checking these sources, in the order listed: user preference settings.
Press the Win + R hotkeys together on the keyboard and type the following command in your Run box: msinfo32 . Click the System Summary section on the left. On the right, see the Locale value.
This depends on what you mean by “user’s locale”. The possibilities listed in the question reflect different meanings for “user’s locale”. None of them reflects the adequate meaning in modern localization, namely the set of cultural conventions preferred by the user (including a list of human languages in order of preference). The way to find that is to ask the user about them.
Naturally, you should only ask about conventions that really matter in the context, and you may consider storing the preferences, once expressed by the user, in a cookie, in HTML5 storage, in a user database, or somewhere else.
Browsers generally allow the user to specify a list of preferred languages, to be sent in Accept-Language
headers. This however relates to a single aspect of locale concept only, it is unknown to most users, and it is known to have incorrect defaults very often.
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