From 643603eb0925264d2f6e69a4ab4cfef0495960d1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 25 Apr 2019 15:43:05 +0200 Subject: [PATCH] The devtools language switch did not work with i18n pages Fixes #2904 --- .../templates/__devtoolsLanguageChooser.tpl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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', -- 2.20.1