if (!isset($this->items[$item])) {
// load category file
$explodedItem = explode('.', $item);
- if (count($explodedItem) < 2) {
+ if (count($explodedItem) < 3) {
return $item;
}
- if (count($explodedItem) < 4 || !$this->loadCategory($explodedItem[0].'.'.$explodedItem[1].'.'.$explodedItem[2].'.'.$explodedItem[3])) {
- if (count($explodedItem) < 3 || !$this->loadCategory($explodedItem[0].'.'.$explodedItem[1].'.'.$explodedItem[2])) {
- $this->loadCategory($explodedItem[0].'.'.$explodedItem[1]);
- }
+ // attempt to load all categories beginning with the most specific
+ if (isset($explodedItem[4])) {
+ $this->loadCategory($explodedItem[0].'.'.$explodedItem[1].'.'.$explodedItem[2].'.'.$explodedItem[3]);
}
+ if (isset($explodedItem[3])) {
+ $this->loadCategory($explodedItem[0].'.'.$explodedItem[1].'.'.$explodedItem[2]);
+ }
+ $this->loadCategory($explodedItem[0].'.'.$explodedItem[1]);
}
// return language variable
// rebuild language file
$languageCategory = LanguageFactory::getInstance()->getCategory($category);
- $this->editor->updateCategory(array($languageCategory->languageCategoryID));
+ if ($languageCategory === null) {
+ return false;
+ }
+
+ $this->editor->updateCategory($languageCategory);
}
// include language file
/**
* Updates the language files for the given category.
*
- * @param array<integer> $categoryIDs
+ * @param wcf\data\language\category\LanguageCategory $languageCategory
*/
- public function updateCategory(array $categoryIDs = array()) {
- if (empty($categoryIDs)) {
- // get all categories
- $sql = "SELECT languageCategoryID
- FROM wcf".WCF_N."_language_category";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute();
- while ($row = $statement->fetchArray()) {
- $categoryIDs[] = $row['languageCategoryID'];
- }
- }
-
- $this->writeLanguageFiles($categoryIDs);
+ public function updateCategory(LanguageCategory $languageCategory) {
+ $this->writeLanguageFiles(array($languageCategory->languageCategoryID));
}
/**
* Write the languages files.
*
- * @param array $categoryIDs
+ * @param array<integer> $languageCategoryIDs
*/
- protected function writeLanguageFiles(array $categoryIDs) {
- // get categories
+ protected function writeLanguageFiles(array $languageCategoryIDs) {
$conditions = new PreparedStatementConditionBuilder();
- $conditions->add("languageCategoryID IN (?)", array($categoryIDs));
+ $conditions->add("languageID = ?", array($this->languageID));
+ $conditions->add("languageCategoryID IN (?)", array($languageCategoryIDs));
- $sql = "SELECT *
- FROM wcf".WCF_N."_language_category
+ // get language items
+ $sql = "SELECT languageItem, languageItemValue, languageCustomItemValue,
+ languageUseCustomValue, languageCategoryID
+ FROM wcf".WCF_N."_language_item
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- while ($category = $statement->fetchArray()) {
- $categoryName = $category['languageCategory'];
- $categoryID = $category['languageCategoryID'];
-
- $conditions = new PreparedStatementConditionBuilder();
- $conditions->add("languageID = ?", array($this->languageID));
- $conditions->add("languageCategoryID = ?", array($categoryID));
-
- // get language items
- $sql = "SELECT languageItem, languageItemValue, languageCustomItemValue, languageUseCustomValue
- FROM wcf".WCF_N."_language_item
- ".$conditions;
+ $items = array();
+ while ($row = $statement->fetchArray()) {
+ $languageCategoryID = $row['languageCategoryID'];
+ if (!isset($items[$languageCategoryID])) {
+ $items[$languageCategoryID] = array();
+ }
- $statement2 = WCF::getDB()->prepareStatement($sql);
- $statement2->execute($conditions->getParameters());
- $items = array();
- while ($row = $statement2->fetchArray()) {
- if ($row['languageUseCustomValue'] == 1) {
- $items[$row['languageItem']] = $row['languageCustomItemValue'];
- }
- else {
- $items[$row['languageItem']] = $row['languageItemValue'];
- }
+ $items[$languageCategoryID][$row['languageItem']] = ($row['languageUseCustomValue']) ? $row['languageCustomItemValue'] : $row['languageItemValue'];
+ }
+
+ foreach ($items as $languageCategoryID => $languageItems) {
+ $category = LanguageFactory::getInstance()->getCategoryByID($languageCategoryID);
+ if ($category === null) {
+ continue;
}
- if (!empty($items)) {
- $content = "<?php\n/**\n* WoltLab Community Framework\n* language: ".$this->languageCode."\n* encoding: UTF-8\n* category: ".$categoryName."\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n";
+ $content = "<?php\n/**\n* WoltLab Community Framework\n* language: ".$this->languageCode."\n* encoding: UTF-8\n* category: ".$category->languageCategory."\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n";
+ foreach ($languageItems as $languageItem => $languageItemValue) {
+ $content .= "\$this->items['".$languageItem."'] = '".str_replace("'", "\'", $languageItemValue)."';\n";
- foreach ($items as $languageItem => $languageItemValue) {
- $content .= "\$this->items['".$languageItem."'] = '".str_replace("'", "\'", $languageItemValue)."';\n";
-
- // compile dynamic language variables
- if ($categoryName != 'wcf.global' && strpos($languageItemValue, '{') !== false) {
- $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue);
- $content .= "\$this->dynamicItems['".$languageItem."'] = '".str_replace("'", "\'", $output['template'])."';\n";
- }
+ // compile dynamic language variables
+ if ($category->languageCategory != 'wcf.global' && strpos($languageItemValue, '{') !== false) {
+ $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue);
+ $content .= "\$this->dynamicItems['".$languageItem."'] = '".str_replace("'", "\'", $output['template'])."';\n";
}
-
- $file = new File(WCF_DIR.'language/'.$this->languageID.'_'.$categoryName.'.php');
- @$file->chmod(0777);
- $file->write($content . '?>');
- $file->close();
}
+
+ $file = new File(WCF_DIR.'language/'.$this->languageID.'_'.$category->languageCategory.'.php');
+ @$file->chmod(0777);
+ $file->write($content . '?>');
+ $file->close();
}
}