/** * @see PackageInstallationPlugin::install() */ public function install() { $instructions = $this->installation->getInstructions(); $languages = $instructions['languages']; // Install each <language>-tag from package.xml foreach ($languages as $language) { if ($xml = $this->readLanguage($language)) { // check required attributes if (!isset($language['languagecode'])) { throw new SystemException("required 'languagecode' attribute for 'languages' tag is missing in '" . PackageArchive::INFO_FILE . "'", 13001); } // check language encoding if (!Language::isSupported($language['languagecode'])) { // unsupported encoding continue; } // Get language $language = LanguageEditor::getLanguageByCode($language['languagecode']); if ($language === null) { // unknown language continue; } // import xml // don't update language files if package is standalone $language->updateFromXML($xml, $this->installation->getPackageID(), !$this->installation->getPackage()->isStandalone()); // add language to this package. $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_language_to_packages\n\t\t\t\t\t\t\t\t(languageID, packageID)\n\t\t\t\t\tVALUES\t\t\t(" . $language->getLanguageID() . ", \n\t\t\t\t\t\t\t\t" . $this->installation->getPackageID() . ")"; WCF::getDB()->sendQuery($sql); } } }
/** * @see Form::validate() */ public function validate() { parent::validate(); if ($this->mode == 'copy') { // language code if (empty($this->languageCode)) { throw new UserInputException('languageCode'); } // if (LanguageEditor::getLanguageByCode($this->languageCode)) { throw new UserInputException('languageCode', 'notUnique'); } // source language id if (empty($this->sourceLanguageID)) { throw new UserInputException('sourceLanguageID'); } // get language $this->sourceLanguage = new LanguageEditor($this->sourceLanguageID); if (!$this->sourceLanguage->getLanguageID()) { throw new UserInputException('sourceLanguageID'); } } else { // check file if (!file_exists($this->filename)) { throw new UserInputException('languageFile'); } // try to import try { // open xml document $xml = new XML($this->filename); // import xml document $this->language = LanguageEditor::importFromXML($xml, PACKAGE_ID); } catch (SystemException $e) { throw new UserInputException($this->importField, $e->getMessage()); } } }
/** * Installs the selected languages. */ protected function installLanguage() { $this->initDB(); foreach (self::$selectedLanguages as $language) { // get language.xml file name $filename = TMP_DIR . TMP_FILE_PREFIX . $language . '.xml'; // check the file if (!file_exists($filename)) { throw new SystemException("unable to find language file '" . $filename . "'", 11002); } // open the file $xml = new XML($filename); // import xml LanguageEditor::importFromXML($xml, 0); } // set default language $language = LanguageEditor::getLanguageByCode(in_array(self::$selectedLanguageCode, self::$selectedLanguages) ? self::$selectedLanguageCode : self::$selectedLanguages[0]); $language->makeDefault(); // assign all languages to package id 0 $sql = "INSERT INTO\twcf" . WCF_N . "_language_to_packages\n\t\t\t\t\t(languageID, packageID)\n\t\t\tSELECT \t\tlanguageID, 0\n\t\t\tFROM\t\twcf" . WCF_N . "_language"; WCF::getDB()->sendQuery($sql); // rebuild language cache WCF::getCache()->clearResource('languages'); // go to next step $this->gotoNextStep('createUser'); }