1. Home
  2. Google Language Switcher
  3. Configuration
  4. Browser Language Detection

Browser Language Detection

When enabled, the frontend JavaScript reads the visitor’s browser language and normalizes it to a 2-letter ISO code:

navigator.language  →  "en-US"  →  "en"
navigator.userLanguage  →  "fr-FR"  →  "fr"

If the normalized code differs from your Default Site Language setting, the module can:

  • Automatically open a suggestion popup offering the visitor a choice to switch or stay
  • Remember their choice using localStorage so the popup does not appear again on subsequent visits
  • Allow the visitor to still manually pick any language from the Google Translate dropdown regardless of their earlier choice

How Language Preference is Persisted

The module stores the selected language under the key hb_translate_lang in localStorage. If localStorage is unavailable, it falls back to cookie storage. It also monitors the googtrans cookie that Google Translate sets, so translated state is correctly preserved across page loads and reset when the visitor selects Show original.