Skip to content

How language matching works

Pierre Stoffe edited this page Apr 26, 2024 · 1 revision

Languages matches are made between the array of languages you define in the language-redirector.php configuration file (referred to as config languages here under) and the list of languages set in the visitor's browser preferences (referred to as browser languages here under). The way the matches are made should feel quite natural but here are a few examples, just for clarity's sake.

The examples below make the assumption that the config languages are defined as follows

'languages' => [
    'en' => 'english',
    'en-us' => 'american-english',
    'fr' => 'french',
],

With this in mind:

  1. a redirection to the english Site will occur if any of these assumptions is true:

    • the browser languages array only contains "en" or any "en" country-based code (eg. "en-ca") except for "en-us"
    • the browser languages array contains "en" and any other language except for "fr" and "en-us"
    • the browser languages array contains an "en" country-based code (eg. "en-ca") except for "en-us" and doesn't contain "fr"
    • the browser languages array contains an "en" country-based code (eg. "en-ca") and at least one "fr" country-based code (eg. "fr-be") and the "en" country-based code has a lower index than any "fr" country-based code in the browser languages array
    • the visitor's "lang" session key is set to "en" (this value would have been set when the plugin triggered a redirection earlier)
    • the "lang" URL query parameter is set to "en"
  2. a redirection to the american-english Site will occur if any of these assumptions is true:

    • the browser languages array only contains "en-us"
    • the browser languages array contains "en-us" and any other language except for "en" and "fr"
    • the visitor's "lang" session key is set to "en-us" (this value would have been set when the plugin triggered a redirection earlier)
    • the "lang" URL query parameter is set to "en-us"
  3. a redirection to the french Site will occur if any of these assumptions is true:

    • the browser languages array only contains "fr" or any "fr" country-based code (eg. "fr-be)
    • the browser languages array contains "fr" and any other language except for "en" and "en-us"
    • the browser languages array contains a "fr" country-based code (eg. "fr-be") and doesn't contain "en" nor "en-us" nor any other "en" country-based code (eg. "en-ca")
    • the browser languages array contains a "fr" country-based code (eg. "fr-be") and at least one "en" country-based code (eg. "en-ca") except for "en-us" and the "fr" country-based code has a lower index than any "en" country-based code in the browser languages array
    • the visitor's "lang" session key is set to "fr" (this value would have been set when the plugin triggered a redirection earlier)
    • the "lang" URL query parameter is set to "fr"

Should you encounter any unexpected behaviour, check out the Troubleshooting section.

Clone this wiki locally