Language switch for the developement mode
authorAlexander Ebert <ebert@woltlab.com>
Sun, 6 Jan 2019 17:16:40 +0000 (18:16 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 6 Jan 2019 17:16:40 +0000 (18:16 +0100)
See #2819

com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
syncTemplates.json
wcfsetup/install/files/acp/templates/__devtoolsLanguageChooser.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/lib/data/user/UserAction.class.php

diff --git a/com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl b/com.woltlab.wcf/templates/__devtoolsLanguageChooser.tpl
new file mode 100644 (file)
index 0000000..fe8e59f
--- /dev/null
@@ -0,0 +1,37 @@
+{if ENABLE_DEBUG_MODE && ENABLE_DEVELOPER_TOOLS && $__wcf->user->userID}
+       <script data-relocate="true">
+               require(['Ajax', 'WoltLabSuite/Core/Language/Chooser'], function(Ajax, LanguageChooser) {
+                       var item = elCreate('li');
+                       item.id = 'pageLanguageContainer';
+                       var userPanelItems = elBySel('.userPanelItems');
+                       userPanelItems.insertBefore(item, userPanelItems.firstChild);
+                       
+                       var languages = {
+                               {implode from=$__wcf->getLanguage()->getLanguages() item=_language}
+                               '{@$_language->languageID}': {
+                                       iconPath: '{@$_language->getIconPath()|encodeJS}',
+                                       languageName: '{@$_language|encodeJS}',
+                                       languageCode: '{@$_language->languageCode|encodeJS}'
+                               }
+                               {/implode}
+                       };
+                       
+                       var callback = function(listItem) {
+                               Ajax.apiOnce({
+                                       data: {
+                                               actionName: 'devtoolsSetLanguage',
+                                               className: 'wcf\\data\\user\\UserAction',
+                                               parameters: {
+                                                       languageID: elData(listItem, 'language-id')
+                                               }
+                                       },
+                                       success: function() {
+                                               window.location.reload();
+                                       }
+                               });
+                       };
+                       
+                       LanguageChooser.init('pageLanguageContainer', 'pageLanguageID', {@$__wcf->getLanguage()->languageID}, languages, callback);
+               });
+       </script>
+{/if}
index 677bc2ca04ba440787a88247f1dd121229458018..32d332fb1bae20f9d548011cb62b20170abdbfe5 100644 (file)
@@ -148,6 +148,8 @@ requirejs.config({
        define.amd = undefined;
 </script>
 
+{include file='__devtoolsLanguageChooser'}
+
 {js application='wcf' lib='jquery' hasTiny=true}
 {js application='wcf' lib='jquery-ui' hasTiny=true}
 {js application='wcf' lib='jquery-ui' file='touchPunch' bundle='WCF.Combined' hasTiny=true}
index d49a5662b7e555e398194dd94a6c75d185dbb634..1cab808a5516ab9c2947474f8859b253b04c9c1c 100644 (file)
@@ -7,6 +7,7 @@
     "__aclFormField",
     "__booleanFormField",
     "__dateFormField",
+    "__devtoolsLanguageChooser",
     "__dialogForm",
     "__form",
     "__formContainer",
diff --git a/wcfsetup/install/files/acp/templates/__devtoolsLanguageChooser.tpl b/wcfsetup/install/files/acp/templates/__devtoolsLanguageChooser.tpl
new file mode 100644 (file)
index 0000000..fe8e59f
--- /dev/null
@@ -0,0 +1,37 @@
+{if ENABLE_DEBUG_MODE && ENABLE_DEVELOPER_TOOLS && $__wcf->user->userID}
+       <script data-relocate="true">
+               require(['Ajax', 'WoltLabSuite/Core/Language/Chooser'], function(Ajax, LanguageChooser) {
+                       var item = elCreate('li');
+                       item.id = 'pageLanguageContainer';
+                       var userPanelItems = elBySel('.userPanelItems');
+                       userPanelItems.insertBefore(item, userPanelItems.firstChild);
+                       
+                       var languages = {
+                               {implode from=$__wcf->getLanguage()->getLanguages() item=_language}
+                               '{@$_language->languageID}': {
+                                       iconPath: '{@$_language->getIconPath()|encodeJS}',
+                                       languageName: '{@$_language|encodeJS}',
+                                       languageCode: '{@$_language->languageCode|encodeJS}'
+                               }
+                               {/implode}
+                       };
+                       
+                       var callback = function(listItem) {
+                               Ajax.apiOnce({
+                                       data: {
+                                               actionName: 'devtoolsSetLanguage',
+                                               className: 'wcf\\data\\user\\UserAction',
+                                               parameters: {
+                                                       languageID: elData(listItem, 'language-id')
+                                               }
+                                       },
+                                       success: function() {
+                                               window.location.reload();
+                                       }
+                               });
+                       };
+                       
+                       LanguageChooser.init('pageLanguageContainer', 'pageLanguageID', {@$__wcf->getLanguage()->languageID}, languages, callback);
+               });
+       </script>
+{/if}
index 7ea46208ddbecd33ea517fd1552ef78794033913..bafdb5ad740c2a64cef79455d79a7c2ebd9c3b79 100644 (file)
                });
        </script>
        
+       {include file='__devtoolsLanguageChooser'}
+       
        <script>
                // prevent jQuery and other libraries from utilizing define()
                __require_define_amd = define.amd;
index c2fd6279a0ecd449da4f6df9020c5646ae8ebae0..44c25a3ccdd9c41c0685e69d45e3f3c3fffb9c95 100644 (file)
@@ -18,6 +18,7 @@ use wcf\system\event\EventHandler;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
+use wcf\system\language\LanguageFactory;
 use wcf\system\request\RequestHandler;
 use wcf\system\WCF;
 use wcf\util\UserRegistrationUtil;
@@ -1012,4 +1013,28 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                
                $this->unmarkItems($this->objectIDs);
        }
+       
+       /**
+        * @since 3.2
+        */
+       public function validateDevtoolsSetLanguage() {
+               if (!ENABLE_DEBUG_MODE || !ENABLE_DEVELOPER_TOOLS) {
+                       throw new PermissionDeniedException();
+               }
+               
+               $this->readInteger('languageID');
+               
+               if (LanguageFactory::getInstance()->getLanguage($this->parameters['languageID']) === null) {
+                       throw new UserInputException('languageID', 'invalid');
+               }
+       }
+       
+       /**
+        * @since 3.2
+        */
+       public function devtoolsSetLanguage() {
+               (new UserEditor(WCF::getUser()))->update([
+                       'languageID' => $this->parameters['languageID']
+               ]);
+       }
 }