Language negotiation – how our redirect feature works

For our users, one of the most important features of Multilingual Press is the HTTP redirect. Each visitor should be sent to the page she understands best.

This is hard.

Example: Maryam (مري) visits your site for the first time. She understands Arabic, English and Latin. Arabic is her native language.
You have three language versions of your content: English, Arabic and Russian. The original content is written in English, the other sites are translations.

Which page should Maryam see? Arabic or English? It depends on two factors: The quality of your Arabic translation and Maryam’s capability to read English.

Multilingual Press cannot judge the quality of your translation, but you can give each language a weight, or as we say: a priority. There is a field for that in our language manager.

Screen shot: Language Manager priorities

Maryam can do the same in her browser. If her English is not very good, she can add a weight to that preference, and her browser will send that in a q value:

Accept-Language: ar,en;q=0.7,la;q=0.4

We read that as:

Arabic   ar = 1.0 (omitted values equal 1)
English  en = 0.7
Latin    la = 0.4

Multilingual Press will now multiply your priority for each language with Maryam’s preference for that language. The highest number wins. This is called Language negotiation. If there are two highest numbers or the highest number matches the current language, or Maryam selects one language per widget (an URL with a noredirect parameter), she will not be redirected.

Our algorithm is clever enough to handle subsets: If your only English content is in Belizean English (en-bz), but your visitor’s preference is Canadian English (en-ca), Multilingual Press will strip the second part and find the matching English content.

What does that mean for you?

You should always know the quality of your translations. Set the priority for the original language to the highest value, weight the translations lower.

In our example: If you set the priority for English to 10 and for Arabic to 7, Maryam will not be redirected when she visits the English or the Arabic site. She will be sent to the Arabic site (her first preference) if she visits the Russian site.

But if you set English to 10 and Arabic to 6, the result of Multilingual Press’ calculation will be:

Arabic   ar = 1.0 x  6 = 6
English  en = 0.7 x 10 = 7
Latin    la = 0.4 (not calculated = 0)
Russian  ru = 0.4 (not calculated = 0)

Maryam will get the English site.

We will also use your priorities to sort the languages in our switcher widget in one of the next releases.

Conclusion: Set the language priorities carefully. They can decide how good your visitors will understand your message. But always provide a way for your visitors to override automatic content negotiation manually, because not everyone uses a browser which is configured to their needs, or the browser’s user interface is very poor. And sometimes your translation is not as good as you think it is.

Screenshot: Google Chrome language settings

Google Chrome language settings

For developers

You can override our selection per filter:

/**
 * Change the URL for redirects. You might add support for other types
 * than singular posts and home here.
 * If you return an empty value, the redirect will not happen.
 * The result will be validated with esc_url().
 *
 * @param string $url
 * @param array  $match 'blog_id'  (int)    target blog ID
 *                      'language' (string) target language
 * @param int    $current_blog_id
 */
$url = apply_filters( 'mlp_redirect_url', $url, $match, $current_blog_id );

Links