diff --git a/bedrock/tabzilla/templates/tabzilla/tabzilla.js b/bedrock/tabzilla/templates/tabzilla/tabzilla.js index 32d5f734d8..b93ee6cf9f 100644 --- a/bedrock/tabzilla/templates/tabzilla/tabzilla.js +++ b/bedrock/tabzilla/templates/tabzilla/tabzilla.js @@ -388,73 +388,85 @@ var Tabzilla = (function (Tabzilla) { return false; } + // Normalize the user language in the form of ab or ab-CD + var normalize = function (lang) { + return lang.replace(/^(\w+)(?:-(\w+))?$/, function (m, p1, p2) { + return p1.toLowerCase() + ((p2) ? '-' + p2.toUpperCase() : ''); + }); + }; + + // Normalize every language for easier comparison + userLangs = $.map(userLangs, function (lang) { return normalize(lang); }); + pageLang = normalize(pageLang); + + // If the page language is the user's primary language, there is nothing + // to do here + if (pageLang === userLangs[0]) { + return false; + } + var offeredLang; - var langLinks = []; - var langOptions = []; + var availableLangs = {}; + var $links = $('link[hreflang]'); + var $options = $('#language option'); - // Compare the user's accept languages against the available languages - // to find the best language. Use an alternate URL in or a - // language option in
+ // Make a dictionary from alternate URLs or a language selector. The key + // is a language, the value is the relevant or