From: Siora Date: Wed, 4 Apr 2012 20:21:58 +0000 (+0200) Subject: Added language multilingualism X-Git-Tag: 2.0.0_Beta_1~616^2~26^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fb8aaccbcd3adf1e2120f19bbb40c244cb8933aa;p=GitHub%2FWoltLab%2FWCF.git Added language multilingualism --- diff --git a/acpMenu.xml b/acpMenu.xml index d4e3af27b5..0721d2cf86 100644 --- a/acpMenu.xml +++ b/acpMenu.xml @@ -17,6 +17,12 @@ admin.language.canAddLanguage + + wcf.acp.menu.link.language + index.php/LanguageMultilingualism/ + admin.language.canEditLanguage + + wcf.acp.menu.link.language diff --git a/acptemplates/languageMultilingualism.tpl b/acptemplates/languageMultilingualism.tpl new file mode 100644 index 0000000000..56a1636655 --- /dev/null +++ b/acptemplates/languageMultilingualism.tpl @@ -0,0 +1,67 @@ +{include file='header'} + + + +
+ +
+

{lang}wcf.acp.language.multilingualism{/lang}

+
+
+ +{if $errorField} +

{lang}wcf.global.form.error{/lang}

+{/if} + +{if $success|isset} +

{lang}wcf.acp.language.multilingualism.success{/lang}

+{/if} + +
+
+
+
+
+ + {lang}wcf.acp.language.multilingualism.enable.description{/lang} +
+
+ + +
+
+
+ {lang}wcf.acp.language.multilingualism.languages{/lang} + +
+ {htmlCheckboxes options=$languages name=languageIDs selected=$languageIDs disableEncoding=true} +
+
+ + {if $errorField == 'languageIDs'} + + {if $errorType == 'empty'}{lang}wcf.acp.language.multilingualism.languages.error.empty{/lang}{/if} + + {/if} +
+ + + {event name='additionalFields'} +
+ +
+ + + +
+
+ +{include file='footer'} diff --git a/files/lib/acp/form/LanguageMultilingualismForm.class.php b/files/lib/acp/form/LanguageMultilingualismForm.class.php new file mode 100644 index 0000000000..149301f197 --- /dev/null +++ b/files/lib/acp/form/LanguageMultilingualismForm.class.php @@ -0,0 +1,151 @@ + + * @package com.woltlab.wcf.acp.language + * @subpackage acp.form + * @category Community Framework + */ +class LanguageMultilingualismForm extends ACPForm { + /** + * @see wcf\acp\form\ACPForm::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.language.multilingualism'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.language.canEditLanguage'); + + // data + public $enable = 0; + public $languageIDs = array(); + public $languages = array(); + public $languageList = array(); + + /** + * @see wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + $this->languages = LanguageFactory::getInstance()->getLanguages(); + } + + /** + * @see wcf\form\IForm::readFormParameters() + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST['enable'])) $this->enable = intval($_POST['enable']); + if (isset($_POST['languageIDs']) && is_array($_POST['languageIDs'])) $this->languageIDs = ArrayUtil::toIntegerArray($_POST['languageIDs']); + } + + /** + * @see wcf\form\IForm::validate() + */ + public function validate() { + parent::validate(); + + if ($this->enable == 1) { + // add default language + if (!in_array(LanguageFactory::getInstance()->getDefaultLanguageID(), $this->languageIDs)) { + $this->languageIDs[] = LanguageFactory::getInstance()->getDefaultLanguageID(); + } + + // validate language ids + $contentLanguages = 0; + foreach ($this->languageIDs as $languageID) { + if (isset($this->languages[$languageID])) { + $contentLanguages++; + } + } + + if ($contentLanguages < 2) { + throw new UserInputException('languageIDs'); + } + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + parent::save(); + + // save + LanguageEditor::enableMultilingualism(($this->enable == 1 ? $this->languageIDs : array())); + + // clear cache + CacheHandler::getInstance()->clear(WCF_DIR.'cache/', 'cache.languages.php'); + $this->saved(); + + // show success message + WCF::getTPL()->assign('success', true); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + if (!count($_POST)) { + // default values + $contentLanguages = 0; + foreach ($this->languages as $languageID => $language) { + if ($language->hasContent) { + $contentLanguages++; + $this->languageIDs[] = $languageID; + } + } + + // add default language + if (!in_array(LanguageFactory::getInstance()->getDefaultLanguageID(), $this->languageIDs)) { + $this->languageIDs[] = LanguageFactory::getInstance()->getDefaultLanguageID(); + } + + if ($contentLanguages > 1) { + $this->enable = 1; + } + } + + $this->languageList = LanguageFactory::getInstance()->getLanguages(); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'enable' => $this->enable, + 'languageIDs' => $this->languageIDs, + 'languages' => $this->languageList + )); + } + + /** + * @see wcf\page\IPage::show() + */ + public function show() { + // check master password + WCFACP::checkMasterPassword(); + + parent::show(); + } +} diff --git a/language/de.xml b/language/de.xml index a9767b82d2..eff59908e4 100644 --- a/language/de.xml +++ b/language/de.xml @@ -36,5 +36,12 @@ + + + + + + + \ No newline at end of file