Skip to content

Commit

Permalink
Merge 10fa98f into fcef360
Browse files Browse the repository at this point in the history
  • Loading branch information
Pchelolo committed Aug 1, 2018
2 parents fcef360 + 10fa98f commit be637a0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/mwUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,24 @@ mwUtil.canConvertLangVariant = (hyper, req, pageLanguage) => {
* a page in a requested language on a particular wiki.
* @param {HyperSwitch} hyper
* @param {Object} req
* @param {string} pageLanguage the language of the requested page.
* @param {string} acceptLanguage the language variant accepted by the client.
* @param {string} pageLang the language of the requested page.
* @param {string} acceptLang the language variant accepted by the client.
* @return {Promise<boolean>}
*/
mwUtil.shouldConvertLangVariant = (hyper, req, pageLanguage, acceptLanguage) => {
if (!acceptLanguage) {
mwUtil.shouldConvertLangVariant = (hyper, req, pageLang, acceptLang) => {
if (!acceptLang) {
return P.resolve(false);
}
return mwUtil.getSiteInfo(hyper, req)
.then((siteInfo) => {
const pageLangWithFallback = pageLang ? pageLang.toLowerCase() : siteInfo.general.lang;
// First, whether specialized variants exist for the page lang on a wiki
const pageLangVariants = siteInfo.languagevariants[pageLanguage.toLowerCase()];
const pageLangVariants = siteInfo.languagevariants[pageLangWithFallback];
if (!pageLangVariants) {
return false;
}
// Second, if the requested language variant exist for page language
return pageLangVariants.indexOf(acceptLanguage.toLowerCase()) !== -1;
return pageLangVariants.indexOf(acceptLang.toLowerCase()) !== -1;
});
};

Expand Down

0 comments on commit be637a0

Please sign in to comment.