Added 'countrycode' attribute for languages
authorAlexander Ebert <ebert@woltlab.com>
Sat, 14 Jul 2012 16:37:25 +0000 (18:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 14 Jul 2012 16:37:25 +0000 (18:37 +0200)
wcfsetup/install/files/lib/data/language/LanguageEditor.class.php
wcfsetup/install/files/lib/system/cache/builder/LanguageCacheBuilder.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml
wcfsetup/setup/db/install.sql

index a87b94a1cbf8cf33e76d536eec1f0f529a89a6d4..f1090157734932da12f476975b3ff301fa501375 100644 (file)
@@ -418,6 +418,24 @@ class LanguageEditor extends DatabaseObjectEditor {
                throw new SystemException("missing attribute 'languagename' in language file");
        }
        
+       /**
+        * Takes an XML object and returns the specific country code.
+        *
+        * @param       wcf\util\XML    $xml
+        * @return      string          country code
+        */
+       public static function readCountryCodeFromXML(XML $xml) {
+               $rootNode = $xml->xpath()->query('/ns:language')->item(0);
+               $attributes = $xml->xpath()->query('attribute::*', $rootNode);
+               foreach ($attributes as $attribute) {
+                       if ($attribute->name == 'countrycode') {
+                               return $attribute->value;
+                       }
+               }
+               
+               throw new SystemException("missing attribute 'countrycode' in language file");
+       }
+       
        /**
         * Imports language items from an XML file into a new or a current language.
         * Updates the relevant language files automatically.
@@ -434,8 +452,10 @@ class LanguageEditor extends DatabaseObjectEditor {
                
                // create new language
                if ($language === null) {
+                       $countryCode = self::readCountryCodeFromXML($xml);
                        $languageName = self::readLanguageNameFromXML($xml);
                        $language = self::create(array(
+                               'countryCode' => $countryCode,
                                'languageCode' => $languageCode,
                                'languageName' => $languageName
                        ));
index 22044f981d2b83d2795f5d4b44bd0fed4182541d..92412c4ff17a7ee420fca3f81fb31c79121d7183 100644 (file)
@@ -22,6 +22,7 @@ class LanguageCacheBuilder implements ICacheBuilder {
        public function getData(array $cacheResource) {
                $data = array(
                        'codes' => array(),
+                       'countryCodes' => array(),
                        'languages' => array(), 
                        'packages' => array(),
                        'default' => 0,
@@ -58,6 +59,9 @@ class LanguageCacheBuilder implements ICacheBuilder {
                        
                        // language code to language id
                        $data['codes'][$language->languageCode] = $language->languageID;
+                       
+                       // country code to language id
+                       $data['countryCode'][$language->languageID] = $language->countryCode;
                }
                
                // get language categories
index 714518ba73a42acf3944e2160d04e55801d9c27a..4a4acdfa4771599d5576b081e58ab742175327c5 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/language.xsd" languagecode="de" languagename="Deutsch">
+<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/language.xsd" languagecode="de" languagename="Deutsch" countrycode="de">
        <category name="wcf.acp.cronjob">
                <item name="wcf.acp.cronjob.list"><![CDATA[Cronjobs]]></item>
                <item name="wcf.acp.cronjob.add"><![CDATA[Cronjob hinzufügen]]></item>
index 22d31dd27e2b221921a570dfd9e901e53d5f85e6..fba2be3d1e3bd60e443b8a1d37c81f125bdce048 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/language.xsd" languagecode="en" languagename="English">
+<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/language.xsd" languagecode="en" languagename="English" countrycode="gb">
        <category name="wcf.acp.cronjob">
                <item name="wcf.acp.cronjob.list"><![CDATA[Cron jobs]]></item>
                <item name="wcf.acp.cronjob.add"><![CDATA[Add a new cron job]]></item>
index 82b04cfec94d6588608aac5c54661fb3683b3a28..689b6ffa0e4fb3db1c6bd2bb4b401bd5780bdc8a 100644 (file)
@@ -197,6 +197,7 @@ 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 '',
+       countryCode VARCHAR(10) NOT NULL DEFAULT '',
        isDefault TINYINT(1) NOT NULL DEFAULT 0,
        hasContent TINYINT(1) NOT NULL DEFAULT 0,
        UNIQUE KEY languageCode (languageCode)