From: Alexander Ebert Date: Thu, 25 Apr 2019 13:43:05 +0000 (+0200) Subject: The devtools language switch did not work with i18n pages X-Git-Tag: 5.2.0_Alpha_1~117 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=643603eb0925264d2f6e69a4ab4cfef0495960d1;p=GitHub%2FWoltLab%2FWCF.git The devtools language switch did not work with i18n pages Fixes #2904 --- diff --git a/com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl b/com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl index fe8e59f50b..91864470cc 100644 --- a/com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl +++ b/com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl @@ -17,6 +17,22 @@ }; var callback = function(listItem) { + var languageCode = elData(listItem, 'language-code'); + if (languageCode === '{$__wcf->getLanguage()->getFixedLanguageCode()}') { + window.location.reload(); + return; + } + + var alternateLink = elBySel('link[rel="alternate"][hreflang="' + languageCode + '"]'); + if (alternateLink) { + // Check if the page does not have unique links per language, such as for the landing page. + var currentLink = elBySel('link[rel="alternate"][hreflang="{$__wcf->getLanguage()->getFixedLanguageCode()}"]'); + if (!currentLink || currentLink.href !== alternateLink.href) { + window.location = alternateLink.href; + return; + } + } + Ajax.apiOnce({ data: { actionName: 'devtoolsSetLanguage',