The devtools language switch did not work with i18n pages
authorAlexander Ebert <ebert@woltlab.com>
Thu, 25 Apr 2019 13:43:05 +0000 (15:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 25 Apr 2019 13:43:05 +0000 (15:43 +0200)
Fixes #2904

com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl

index fe8e59f50bff6b2b74f4f0904f51391124d62925..91864470ccbe7bc2163fa685e07fb6ac85262b6d 100644 (file)
                        };
                        
                        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',