krish
krish

Reputation: 479

how does a browser will pick the client Locale value.?

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

Upvotes: 1

Views: 64

Answers (1)

Robert I
Robert I

Reputation: 1527

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

  1. Windos XP : GetSystemDefaultLCID()
  2. If QT library is available QLocale::system().name().toUtf8()
  3. Fallback is C++ getenv("LANG") very raw
  4. 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()

Upvotes: 1

Related Questions