How a browser will get the client machine locale value. I am curious about internal process of how an browser picks up the Operating System locale value of the client machine. (i.e for the Browser/any app that is running on the client OS, which variable value does these apps/browser will fetch and send as the request header info?)
Asked
Active
Viewed 58 times
1 Answers
1
Fascinating question.
Firefox has shown how it gets this according to different Operating Systems here : https://dxr.mozilla.org/mozilla-esr45/source/intl/locale/nsLocaleService.cpp?q=nslocaleservice&redirect_type=direct#69
From that I have created a list for you
- Windos XP : GetSystemDefaultLCID()
- If QT library is available QLocale::system().name().toUtf8()
- Fallback is C++ getenv("LANG") very raw
- Mac uses this CFLocaleRef cflocale = CFLocaleCopyCurrent(); see here for more info How to get the locale of the current user in OSX using C++
Also, Androids Chromium browser which was built in c++ makes a call to Java.LocaleUtils which uses Java's Locale.getDefault()
std::string GetDefaultLocaleString() {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jstring> locale =
Java_LocaleUtils_getDefaultLocaleString(env);
return ConvertJavaStringToUTF8(locale);
}
https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#getDefault()

Robert I
- 1,509
- 2
- 11
- 18