i18n now working for textareas
authorAlexander Ebert <ebert@woltlab.com>
Thu, 29 Sep 2011 19:25:23 +0000 (21:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 29 Sep 2011 19:25:23 +0000 (21:25 +0200)
Changes some more fields to support i18n. Meanwhile textareas with enabled i18n support may look a bit weird, @Luzifr will be fixing this within time.

com.woltlab.wcf/option.xml
wcfsetup/install/files/acp/templates/optionTypeTextareaI18n.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/option/TextI18nOptionType.class.php
wcfsetup/install/files/lib/system/option/TextareaI18nOptionType.class.php [new file with mode: 0644]

index 17fcb33fe1e7007f74688df33365f87d7359d4a3..b1e5d6a5c4a69b8d6950e6bc0593cf312ae87640 100644 (file)
                        </option>
                        <option name="page_description">
                                <categoryname>general.page</categoryname>
-                               <optiontype>text</optiontype>
+                               <optiontype>texti18n</optiontype>
+                               <supporti18n>1</supporti18n>
                        </option>
                        <option name="page_url">
                                <categoryname>general.page</categoryname>
@@ -258,8 +259,9 @@ imagick:wcf.acp.option.image_adapter_type.imagick]]>
                        </option>
                        <option name="mail_signature">
                                <categoryname>general.mail.general</categoryname>
-                               <optiontype>textarea</optiontype>
+                               <optiontype>textareai18n</optiontype>
                                <defaultvalue><![CDATA[]]></defaultvalue>
+                               <supporti18n>1</supporti18n>
                        </option>
                        <!-- /mail.general -->
                        
diff --git a/wcfsetup/install/files/acp/templates/optionTypeTextareaI18n.tpl b/wcfsetup/install/files/acp/templates/optionTypeTextareaI18n.tpl
new file mode 100644 (file)
index 0000000..ecc8981
--- /dev/null
@@ -0,0 +1,10 @@
+<script type="text/javascript">
+       //<![CDATA[
+       $(function() {
+               var $availableLanguages = { {implode from=$availableLanguages key=languageID item=languageName}{@$languageID}: '{$languageName}'{/implode} };
+               var $optionValues = { {implode from=$i18nValues[$option->optionName] key=languageID item=value}'{@$languageID}': '{$value}'{/implode} };
+               new WCF.MultipleLanguageInput('{$option->optionName}', false, $optionValues, $availableLanguages);
+       });
+       //]]>
+</script>
+<textarea id="{$option->optionName}" name="{$option->optionName}" cols="40" rows="10">{$i18nPlainValues[$option->optionName]}</textarea>
index 05a2bf2c8abce0cf7703a9352593329f1bcc4f7b..5283210001575e3a6793810be5236f0092eed355 100644 (file)
@@ -4,6 +4,16 @@ use wcf\data\option\Option;
 use wcf\system\language\I18nHandler;
 use wcf\system\WCF;
 
+/**
+ * TextI18nOptionType is an implementation of IOptionType for 'input type="text"' tags with i18n support.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.option
+ * @category   Community Framework
+ */
 class TextI18nOptionType extends TextOptionType {
        /**
         * @see wcf\system\option\AbstractOptionType::$supportI18n
diff --git a/wcfsetup/install/files/lib/system/option/TextareaI18nOptionType.class.php b/wcfsetup/install/files/lib/system/option/TextareaI18nOptionType.class.php
new file mode 100644 (file)
index 0000000..b63366f
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace wcf\system\option;
+use wcf\data\option\Option;
+use wcf\system\language\I18nHandler;
+use wcf\system\WCF;
+
+/**
+ * TextareaI18nOptionType is an implementation of IOptionType for 'textarea' tags with i18n support.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.option
+ * @category   Community Framework
+ */
+class TextareaI18nOptionType extends TextareaOptionType {
+       /**
+        * @see wcf\system\option\AbstractOptionType::$supportI18n
+        */
+       protected $supportI18n = true;
+       
+       /**
+        * @see wcf\system\option\IOptionType::getFormElement()
+        */
+       public function getFormElement(Option $option, $value) {
+               $useRequestData = (count($_POST)) ? true : false;
+               I18nHandler::getInstance()->assignVariables($useRequestData);
+               
+               WCF::getTPL()->assign(array(
+                       'option' => $option,
+                       'value' => $value
+               ));
+               return WCF::getTPL()->fetch('optionTypeTextareaI18n');
+       }
+       
+       /**
+        * @see wcf\system\option\IOptionType::validate()
+        */
+       public function validate(Option $option, $newValue) {
+               if (!I18nHandler::getInstance()->validateValue($option->optionName)) {
+                       throw new UserInputException($option->optionName, 'validationFailed');
+               }
+       }
+}