From a74df36bcfed54a1111c28f1515a4a2d17ffe9e7 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 22 Sep 2011 16:31:24 +0200 Subject: [PATCH] Added "real" language name --- .../files/lib/acp/form/UserAddForm.class.php | 4 +- .../lib/acp/form/UserOptionListForm.class.php | 34 ----- .../lib/acp/form/UserSearchForm.class.php | 3 +- .../form/UsersMassProcessingForm.class.php | 5 +- .../lib/acp/page/CronjobListPage.class.php | 2 +- .../data/language/LanguageEditor.class.php | 22 ++- .../system/language/LanguageFactory.class.php | 128 +++++++----------- wcfsetup/install/lang/de-informal.xml | 2 +- wcfsetup/install/lang/de.xml | 9 +- wcfsetup/install/lang/en.xml | 2 +- wcfsetup/setup/db/install.sql | 1 + 11 files changed, 89 insertions(+), 123 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/UserAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserAddForm.class.php index 3ec1fa8f79..758199587b 100644 --- a/wcfsetup/install/files/lib/acp/form/UserAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserAddForm.class.php @@ -304,10 +304,10 @@ class UserAddForm extends UserOptionListForm { 'groupIDs' => $this->groupIDs, 'optionTree' => $this->optionTree, 'availableGroups' => $this->getAvailableGroups(), - 'availableLanguages' => $this->getAvailableLanguages(), + 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), 'languageID' => $this->languageID, 'visibleLanguages' => $this->visibleLanguages, - 'availableContentLanguages' => $this->getAvailableContentLanguages(), + 'availableContentLanguages' => LanguageFactory::getInstance()->getContentLanguages(), 'action' => 'add' )); } diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php index c6dfe35704..8685a4b3a9 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionListForm.class.php @@ -32,40 +32,6 @@ abstract class UserOptionListForm extends AbstractOptionListForm { return UserGroup::getAccessibleGroups(array(), array(UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS)); } - /** - * Returns a list of all available languages. - * - * @return array - */ - protected function getAvailableLanguages() { - $availableLanguages = array(); - foreach (LanguageFactory::getInstance()->getAvailableLanguages(PACKAGE_ID) as $language) { - $availableLanguages[$language['languageID']] = WCF::getLanguage()->get('wcf.global.language.'.$language['languageCode']); - } - - // sort languages - StringUtil::sort($availableLanguages); - - return $availableLanguages; - } - - /** - * Returns a list of all available content languages. - * - * @return array - */ - public static function getAvailableContentLanguages() { - $availableLanguages = array(); - foreach (LanguageFactory::getInstance()->getAvailableContentLanguages(PACKAGE_ID) as $language) { - $availableLanguages[$language['languageID']] = WCF::getLanguage()->get('wcf.global.language.'.$language['languageCode']); - } - - // sort languages - StringUtil::sort($availableLanguages); - - return $availableLanguages; - } - /** * Returns the default-form language id * diff --git a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php index 14a421a406..f9f18b19c8 100755 --- a/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php @@ -7,6 +7,7 @@ use wcf\form\AbstractForm; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\event\EventHandler; use wcf\system\exception\UserInputException; +use wcf\system\language\LanguageFactory; use wcf\system\wcf; use wcf\util\ArrayUtil; use wcf\util\HeaderUtil; @@ -165,7 +166,7 @@ class UserSearchForm extends UserOptionListForm { 'languageIDs' => $this->languageIDs, 'optionTree' => $this->optionTree, 'availableGroups' => $this->getAvailableGroups(), - 'availableLanguages' => $this->getAvailablelanguages(), + 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), 'invertGroupIDs' => $this->invertGroupIDs, 'sortField' => $this->sortField, 'sortOrder' => $this->sortOrder, diff --git a/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php b/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php index 40296f7f07..157cb6ec51 100644 --- a/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php @@ -11,6 +11,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\event\EventHandler; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; +use wcf\system\language\LanguageFactory; use wcf\util\ArrayUtil; use wcf\util\StringUtil; @@ -52,7 +53,6 @@ class UsersMassProcessingForm extends UserOptionListForm { // data public $availableGroups = array(); - public $availableLanguages = array(); public $options = array(); public $availableActions = array('sendMail', 'exportMailAddress', 'assignToGroup', 'delete'); public $affectedUsers = 0; @@ -335,7 +335,6 @@ class UsersMassProcessingForm extends UserOptionListForm { } $this->availableGroups = $this->getAvailableGroups(); - $this->availableLanguages = $this->getAvailableLanguages(); foreach ($this->activeOptions as $name => $option) { if (isset($this->values[$name])) { @@ -359,7 +358,7 @@ class UsersMassProcessingForm extends UserOptionListForm { 'languageIDArray' => $this->languageIDArray, 'invertGroupIDs' => $this->invertGroupIDs, 'availableGroups' => $this->availableGroups, - 'availableLanguages' => $this->availableLanguages, + 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), 'options' => $this->options, 'availableActions' => $this->availableActions, // assign to group diff --git a/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php b/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php index 7b14a8d50f..e99f7dd955 100755 --- a/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php @@ -38,7 +38,7 @@ class CronjobListPage extends SortablePage { /** * @see wcf\page\MultipleLinkPage::$objectListClassName - */ + */ public $objectListClassName = 'wcf\data\cronjob\CronjobList'; /** diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index 60d2c4ff0f..0c487c7a8e 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -328,6 +328,24 @@ class LanguageEditor extends DatabaseObjectEditor { throw new SystemException("missing attribute 'languagecode' in language file"); } + /** + * Takes an XML object and returns the specific language name. + * + * @param wcf\util\XML $xml + * @return string language name + */ + public static function readLanguageNameFromXML(XML $xml) { + $rootNode = $xml->xpath()->query('/ns:language')->item(0); + $attributes = $xml->xpath()->query('attribute::*', $rootNode); + foreach ($attributes as $attribute) { + if ($attribute->name == 'languagename') { + return $attribute->value; + } + } + + throw new SystemException("missing attribute 'languagename' in language file"); + } + /** * Imports language items from an XML file into a new or a current language. * Updates the relevant language files automatically. @@ -344,8 +362,10 @@ class LanguageEditor extends DatabaseObjectEditor { // create new language if ($language === null) { + $languageName = self::readLanguageNameFromXML($xml); $language = self::create(array( - 'languageCode' => $languageCode + 'languageCode' => $languageCode, + 'languageName' => $languageName )); } diff --git a/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php b/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php index 37a1d9fb21..1beae1e20f 100644 --- a/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php +++ b/wcfsetup/install/files/lib/system/language/LanguageFactory.class.php @@ -1,6 +1,7 @@ languages[$languageID]; } + /** + * Returns an instance of Language or NULL for a given language code. + * + * @param string $languageCode + * @return wcf\data\language\Language + */ + public function getLanguageByCode($languageCode) { + // called within WCFSetup + if ($this->cache === false || !count($this->cache['codes'])) { + $sql = "SELECT languageID + FROM wcf".WCF_N."_language + WHERE languageCode = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($languageCode)); + $row = $statement->fetchArray(); + if (isset($row['languageID'])) return new Language($row['languageID']); + } + else if (isset($this->cache['codes'][$languageCode])) { + return $this->getLanguage($this->cache['codes'][$languageCode]); + } + + return null; + } + /** * Returns true if the language category with the given name exists. * @@ -104,8 +129,8 @@ class LanguageFactory extends SingletonFactory { protected function findPreferredLanguage() { // get available language codes $availableLanguageCodes = array(); - foreach ($this->getAvailableLanguages(PACKAGE_ID) as $language) { - $availableLanguageCodes[] = $language['languageCode']; + foreach ($this->getLanguages(PACKAGE_ID) as $language) { + $availableLanguageCodes[] = $language->languageCode; } // get default language @@ -146,48 +171,6 @@ class LanguageFactory extends SingletonFactory { return $defaultLanguageCode; } - /** - * Returns infos (code, id, encoding, etc) about all available languages - * for package with the given id. - * - * @param integer $packageID - * @return array - */ - public function getAvailableLanguages($packageID = PACKAGE_ID) { - // get list of all available languages - $availableLanguages = array(); - if (isset($this->cache['packages'][$packageID])) { - foreach ($this->cache['packages'][$packageID] as $availableLanguageID) { - $availableLanguages[] = $this->cache['languages'][$availableLanguageID]; - } - } - return $availableLanguages; - } - - /** - * Returns an instance of Language or NULL for a given language code. - * - * @param string $languageCode - * @return wcf\data\language\Language - */ - public function getLanguageByCode($languageCode) { - // called within WCFSetup - if ($this->cache === false || !count($this->cache['codes'])) { - $sql = "SELECT languageID - FROM wcf".WCF_N."_language - WHERE languageCode = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($languageCode)); - $row = $statement->fetchArray(); - if (isset($row['languageID'])) return new Language($row['languageID']); - } - else if (isset($this->cache['codes'][$languageCode])) { - return $this->getLanguage($this->cache['codes'][$languageCode]); - } - - return null; - } - /** * Returns the active scripting compiler object. * @@ -256,22 +239,42 @@ class LanguageFactory extends SingletonFactory { return $this->cache['default']; } + /** + * Returns all available languages for package with the given id. + * + * @param integer $packageID + * @return array + */ + public function getLanguages($packageID = PACKAGE_ID) { + // get list of all available languages + $availableLanguages = array(); + if (isset($this->cache['packages'][$packageID])) { + foreach ($this->cache['packages'][$packageID] as $availableLanguageID) { + $availableLanguages[$availableLanguageID] = $this->getLanguage($availableLanguageID); + } + } + + DatabaseObject::sort($availableLanguages, 'languageName'); + return $availableLanguages; + } + /** * Returns all available content languages for given package. * * @param integer $packageID - * @return array $availableLanguages infos about each language (code, id, encoding, etc) + * @return array */ - public function getAvailableContentLanguages($packageID = PACKAGE_ID) { + public function getContentLanguages($packageID = PACKAGE_ID) { $availableLanguages = array(); if (isset($this->cache['packages'][$packageID])) { foreach ($this->cache['packages'][$packageID] as $availableLanguageID) { if ($this->cache['languages'][$availableLanguageID]['hasContent']) { - $availableLanguages[$availableLanguageID] = $this->cache['languages'][$availableLanguageID]; + $availableLanguages[$availableLanguageID] = $this->getLanguage($availableLanguageID); } } } + DatabaseObject::sort($availableLanguages, 'languageName'); return $availableLanguages; } @@ -298,35 +301,4 @@ class LanguageFactory extends SingletonFactory { // rebuild language cache $this->clearCache(); } - - /** - * Returns an ordered list of the names of all installed languages in the - * active language. - * - * @return array - */ - public function getLanguages() { - $languages = array(); - foreach ($this->cache['codes'] as $languageCode => $languageID) { - $languages[$languageID] = WCF::getLanguage()->getDynamicVariable('wcf.global.language.'.$languageCode); - } - - StringUtil::sort($languages); - return $languages; - } - - /** - * Returns an ordered list of all installed language codes. - * - * @return array - */ - public function getLanguageCodes() { - $languageCodes = array(); - foreach ($this->cache['codes'] as $languageCode => $languageID) { - $languageCodes[$languageID] = $languageCode; - } - - StringUtil::sort($languageCodes); - return $languageCodes; - } } diff --git a/wcfsetup/install/lang/de-informal.xml b/wcfsetup/install/lang/de-informal.xml index d4cda1134d..f734405fd8 100644 --- a/wcfsetup/install/lang/de-informal.xml +++ b/wcfsetup/install/lang/de-informal.xml @@ -1,5 +1,5 @@ - + diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 26d2fd6e58..a5022e7721 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1,5 +1,5 @@  - + @@ -586,6 +586,13 @@ + + + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 3a79090ae9..dc5939752b 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1,5 +1,5 @@ - + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 368053ce57..ac23cc6bf7 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -192,6 +192,7 @@ DROP TABLE IF EXISTS wcf1_language; CREATE TABLE wcf1_language ( languageID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, languageCode VARCHAR(20) NOT NULL DEFAULT '', + languageName VARCHAR(255) NOT NULL DEFAULT '', isDefault TINYINT(1) NOT NULL DEFAULT 0, hasContent TINYINT(1) NOT NULL DEFAULT 0, UNIQUE KEY languageCode (languageCode) -- 2.20.1