Improved usability of multilingual pages/articles
authorMarcel Werk <burntime@woltlab.com>
Tue, 21 Jun 2016 10:56:51 +0000 (12:56 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 21 Jun 2016 10:56:51 +0000 (12:56 +0200)
com.woltlab.wcf/templates/article.tpl
com.woltlab.wcf/templates/cms.tpl
com.woltlab.wcf/templates/pageHeaderUser.tpl
wcfsetup/install/files/js/WoltLab/WCF/Language/Chooser.js
wcfsetup/install/files/lib/page/AbstractArticlePage.class.php
wcfsetup/install/files/lib/page/CmsPage.class.php

index ba470e47798022ed7c20f356afa26d50235bc9ff..b7629cdfca7f0cccba2dc3eaa5b28d62a2954ffd 100644 (file)
@@ -37,7 +37,7 @@
                        <nav class="contentHeaderNavigation">
                                <ul>
                                        {content}
-                                               {if $article->isMultilingual}
+                                               {if $article->isMultilingual && $__wcf->user->userID}
                                                        <li class="dropdown">
                                                                <a class="dropdownToggle boxFlag box24 button">
                                                                        <span><img src="{$articleContent->getLanguage()->getIconPath()}" alt="" class="iconFlag"></span>
index 7c803e016099617a4549ac4de9b563700cc73841..2681ff76d531d481aa5a631945f3d0ad266308c6 100644 (file)
        {/if}
 {/capture}
 
+{capture assign='contentHeaderNavigation'}
+       {if $page->isMultilingual && $__wcf->user->userID}
+               <li class="dropdown">
+                       <a class="dropdownToggle boxFlag box24 button">
+                               <span><img src="{$activePageLanguage->getIconPath()}" alt="" class="iconFlag"></span>
+                               <span>{$activePageLanguage->languageName}</span>
+                       </a>
+                       <ul class="dropdownMenu">
+                               {foreach from=$page->getPageLanguages() item='pageLanguage'}
+                                       {if $pageLanguage->getLanguage()}
+                                               <li class="boxFlag">
+                                                       <a class="box24" href="{$pageLanguage->getLink()}">
+                                                               <span><img src="{$pageLanguage->getLanguage()->getIconPath()}" alt="" class="iconFlag"></span>
+                                                               <span>{$pageLanguage->getLanguage()->languageName}</span>
+                                                       </a>
+                                               </li>
+                                       {/if}
+                               {/foreach}
+                       </ul>
+               </li>
+       {/if}
+       
+       {if $__wcf->getSession()->getPermission('admin.content.cms.canManagePage')}<li><a href="{link controller='PageEdit' id=$page->pageID isACP=true}{/link}" class="button"><span class="icon icon16 fa-pencil"></span> <span>{lang}wcf.acp.page.edit{/lang}</span></a></li>{/if}
+{/capture}
+
 {include file='header'}
 
 {if $content[content]}
index 611f94473a2ce7e037abd693252c6dc71422dcfd..94f280dcbc4a7d7f90223651631cbdf8235b6568 100644 (file)
                                                                {implode from=$__wcf->getLanguage()->getLanguages() item=__language}
                                                                        '{@$__language->languageID}': {
                                                                                iconPath: '{@$__language->getIconPath()|encodeJS}',
-                                                                               languageName: '{@$__language|encodeJS}'
+                                                                               languageName: '{@$__language|encodeJS}',
+                                                                               languageCode: '{@$__language->languageCode|encodeJS}'
                                                                        }
                                                                {/implode}
                                                        };
-                                                       
+                                                               
                                                        var callback = function(listItem) {
-                                                               var location = window.location.toString().replace(/#.*/, '').replace(/(\?|&)l=[0-9]+/g, '');
-                                                               var delimiter = (location.indexOf('?') == -1) ? '?' : '&';
+                                                               var location;
+                                                               var languageCode = elData(listItem, 'language-code');
+                                                               var link = elBySel('link[hreflang="' + languageCode + '"]');
+                                                               if (link !== null) {
+                                                                       location = link.href;
+                                                               }
+                                                               else {
+                                                                       location = window.location.toString().replace(/#.*/, '').replace(/(\?|&)l=[0-9]+/g, '');
+                                                               }
                                                                
+                                                               var delimiter = (location.indexOf('?') == -1) ? '?' : '&';
                                                                window.location = location + delimiter + 'l=' + elData(listItem, 'language-id') + window.location.hash;
                                                        };
                                                        
index 89b58422a50b74cab69c900ae694d9d0e01c14e0..5f6198ba83341bed9f1d6163bc4fb980f841925b 100644 (file)
@@ -117,6 +117,7 @@ define(['Dictionary', 'Language', 'Dom/Traverse', 'Dom/Util', 'ObjectMap', 'Ui/S
                                        listItem.className = 'boxFlag';
                                        listItem.addEventListener(WCF_CLICK_EVENT, callbackClick);
                                        elData(listItem, 'language-id', availableLanguageId);
+                                       if (language.languageCode !== undefined) elData(listItem, 'language-code', language.languageCode);
                                        dropdownMenu.appendChild(listItem);
                                        
                                        a = elCreate('a');
index 4f40f476ac6fb0771171968a98abefaf5ee51f95..b7a62d2ddfe69288078bedd9633655e4631956ad 100644 (file)
@@ -1,10 +1,11 @@
 <?php
 namespace wcf\page;
 use wcf\data\article\AccessibleArticleList;
-use wcf\data\article\CategoryArticleList;
+use wcf\data\article\category\ArticleCategory;
 use wcf\data\article\content\ViewableArticleContent;
 use wcf\data\article\ArticleEditor;
 use wcf\data\article\ViewableArticle;
+use wcf\data\tag\Tag;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
@@ -77,6 +78,11 @@ abstract class AbstractArticlePage extends AbstractPage {
                }
                $this->article = ViewableArticle::getArticle($this->articleContent->articleID);
                $this->category = $this->article->getCategory();
+               
+               // update interface language
+               if (!WCF::getUser()->userID && $this->article->isMultilingual && $this->articleContent->languageID != WCF::getLanguage()->languageID) {
+                       WCF::setLanguage($this->articleContent->languageID);
+               }
        }
        
        /**
index b13f00c0f1b8345699e2e12c6f8ca71e50385183..bde08f27cd6490f6f0cbd9394f6bb9c23bb73943 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\page;
 use wcf\data\page\Page;
 use wcf\system\exception\IllegalLinkException;
+use wcf\system\language\LanguageFactory;
 use wcf\system\request\LinkHandler;
 use wcf\system\request\RequestHandler;
 use wcf\system\WCF;
@@ -68,6 +69,11 @@ class CmsPage extends AbstractPage {
                }
                
                $this->canonicalURL = LinkHandler::getInstance()->getCmsLink($this->pageID, $this->languageID);
+               
+               // update interface language
+               if (!WCF::getUser()->userID && $this->page->isMultilingual && $this->languageID != WCF::getLanguage()->languageID) {
+                       WCF::setLanguage($this->languageID);
+               }
        }
        
        /**
@@ -81,7 +87,8 @@ class CmsPage extends AbstractPage {
                        'content' => $this->content,
                        'contentLanguageID' => $this->languageID,
                        'page' => $this->page,
-                       'pageID' => $this->pageID
+                       'pageID' => $this->pageID,
+                       'activePageLanguage' => ($this->languageID ? LanguageFactory::getInstance()->getLanguage($this->languageID) : null)
                ]);
        }
 }