<!-- general.page -->
<option name="page_title">
<categoryname>general.page</categoryname>
- <optiontype>text</optiontype>
+ <optiontype>texti18n</optiontype>
+ <supporti18n>1</supporti18n>
</option>
<option name="page_description">
<categoryname>general.page</categoryname>
--- /dev/null
+<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>
+<input type="{@$inputType}" id="{$option->optionName}" name="{$option->optionName}" value="{$i18nPlainValues[$option->optionName]}" class="medium" />
use wcf\system\cache\CacheHandler;
use wcf\system\exception\SystemException;
use wcf\system\exception\UserInputException;
+use wcf\system\language\I18nHandler;
use wcf\util\ClassUtil;
use wcf\util\StringUtil;
* @var array
*/
public $typeObjects = array();
+
+ /**
+ * language item pattern
+ * @var string
+ */
+ protected $languageItemPattern = '';
/**
* @see wcf\form\IForm::readFormParameters()
parent::readFormParameters();
if (isset($_POST['values']) && is_array($_POST['values'])) $this->rawValues = $_POST['values'];
+
+ foreach ($this->options as $option) {
+ if ($option->supportI18n) {
+ I18nHandler::getInstance()->register($option->optionName);
+ I18nHandler::getInstance()->setOptions($option->optionName, $option->packageID, $option->optionValue, $this->languageItemPattern);
+ }
+ }
+ I18nHandler::getInstance()->readValues();
}
/**
}
}
}
-
+
return $tree;
}
return $children;
}
+
+ public function readData() {
+ parent::readData();
+
+ if (!count($_POST)) {
+ foreach ($this->options as $option) {
+ if ($option->supportI18n) {
+ I18nHandler::getInstance()->register($option->optionName);
+ I18nHandler::getInstance()->setOptions($option->optionName, $option->packageID, $option->optionValue, $this->languageItemPattern);
+ }
+ }
+ }
+ }
}
use wcf\data\option\OptionAction;
use wcf\data\option\Option;
use wcf\system\exception\IllegalLinkException;
+use wcf\system\language\I18nHandler;
use wcf\system\WCF;
use wcf\system\WCFACP;
*/
public $optionTree = array();
+ /**
+ * @see wcf\acp\form\AbstractOptionListForm::$languageItemPattern
+ */
+ protected $languageItemPattern = 'wcf.option.option\d+';
+
/**
* @see wcf\page\IPage::readParameters()
*/
// save options
$saveOptions = array();
foreach ($this->options as $option) {
- $saveOptions[$option->optionID] = $this->optionValues[$option->optionName];
+ // handle i18n support
+ if ($option->supportI18n) {
+ if (I18nHandler::getInstance()->isPlainValue($option->optionName)) {
+ I18nHandler::getInstance()->remove('wcf.option.option' . $option->optionID, $option->packageID);
+ $saveOptions[$option->optionID] = I18nHandler::getInstance()->getValue($option->optionName);
+ }
+ else {
+ I18nHandler::getInstance()->save($option->optionName, 'wcf.option.option' . $option->optionID, 'wcf.option', $option->packageID);
+ $saveOptions[$option->optionID] = 'wcf.option.option' . $option->optionID;
+ }
+ }
+ else {
+ $saveOptions[$option->optionID] = $this->optionValues[$option->optionName];
+ }
}
$optionAction = new OptionAction(array(), 'updateAll', array('data' => $saveOptions));
$optionAction->executeAction();
$this->optionValues[$option->optionName] = $option->optionValue;
}
}
+
+ // load option tree
$this->optionTree = $this->getOptionTree($this->category->categoryName);
+
if (!count($_POST)) {
$this->activeTabMenuItem = $this->optionTree[0]['object']->categoryName;
}
return false;
}
}
+ else if (!isset($this->i18nValues[$elementID]) || empty($this->i18nValues[$elementID])) {
+ return false;
+ }
else {
foreach ($this->i18nValues[$elementID] as $value) {
if (empty($value)) {
* @param string $value
* @param string $pattern
*/
- public function setOptions($elementID, $value, $pattern) {
+ public function setOptions($elementID, $packageID, $value, $pattern) {
$this->elementOptions[$elementID] = array(
+ 'packageID' => $packageID,
'pattern' => $pattern,
'value' => $value
);
/**
* Assigns element values to template. Using request data once reading
- * initial database data is explicitly disallowed. Restrictions on package
- * id apply as explained in save().
+ * initial database data is explicitly disallowed.
*
- * @param integer $packageID
* @param boolean $useRequestData
*/
- public function assignVariables($packageID, $useRequestData = true) {
+ public function assignVariables($useRequestData = true) {
+ $elementValues = array();
+ $elementValuesI18n = array();
+
foreach ($this->elementIDs as $elementID) {
- $elementValue = '';
- $elementI18nValues = array();
+ $value = '';
+ $i18nValues = array();
// use POST values instead of querying database
if ($useRequestData) {
if ($this->isPlainValue($elementID)) {
- $elementValue = $this->getValue($elementID);
+ $value = $this->getValue($elementID);
}
else {
if ($this->hasI18nValues($elementID)) {
- $elementI18nValues = $this->i18nValues[$elementID];
+ $i18nValues = $this->i18nValues[$elementID];
}
else {
- $elementI18nValues = array();
+ $i18nValues = array();
}
}
}
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(
$this->elementOptions[$elementID]['value'],
- $packageID
- ));
+ $this->elementOptions[$elementID]['packageID']
+ ));
while ($row = $statement->fetchArray()) {
- $elementI18nValues[$row['languageID']] = $row['languageItemValue'];
+ $i18nValues[$row['languageID']] = $row['languageItemValue'];
}
-
}
else {
// use data provided by setOptions()
- $elementValue = $this->elementOptions[$elementID]['value'];
+ $value = $this->elementOptions[$elementID]['value'];
}
}
- WCF::getTPL()->assign(array(
- 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
- $elementID => $elementValue,
- $elementID.'_i18n' => $elementI18nValues
- ));
+ $elementValues[$elementID] = $value;
+ $elementValuesI18n[$elementID] = $i18nValues;
}
+
+ WCF::getTPL()->assign(array(
+ 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
+ 'i18nPlainValues' => $elementValues,
+ 'i18nValues' => $elementValuesI18n
+ ));
}
}
* @category Community Framework
*/
abstract class AbstractOptionType implements IOptionType {
+ /**
+ * internationalization support
+ * @var boolean
+ */
+ protected $supportI18n = false;
+
/**
* @see wcf\system\option\IOptionType::validate()
*/
public function getCSSClassName() {
return '';
}
+
+ /**
+ * @see wcf\system\option\IOptionType::supportI18n()
+ */
+ public function supportI18n() {
+ return $this->supportI18n;
+ }
}
* @return string
*/
public function getCSSClassName();
+
+ /**
+ * Returns true, if options supports internationalization .
+ *
+ * @return boolean
+ */
+ public function supportI18n();
}
--- /dev/null
+<?php
+namespace wcf\system\option;
+use wcf\data\option\Option;
+use wcf\system\language\I18nHandler;
+use wcf\system\WCF;
+
+class TextI18nOptionType extends TextOptionType {
+ /**
+ * @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,
+ 'inputType' => $this->inputType,
+ 'value' => $value
+ ));
+ return WCF::getTPL()->fetch('optionTypeTextI18n');
+ }
+
+ /**
+ * @see wcf\system\option\IOptionType::validate()
+ */
+ public function validate(Option $option, $newValue) {
+ if (!I18nHandler::getInstance()->validateValue($option->optionName)) {
+ throw new UserInputException($option->optionName, 'validationFailed');
+ }
+ }
+}