From 93f4707b483ca49c90928a45ece320290ab3b17f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 28 Jul 2017 14:43:30 +0200 Subject: [PATCH] Added i18n support for categories See WoltLab/com.woltlab.wcf.exporter#24 --- .../AbstractCategoryImporter.class.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php index c670316ae5..2e16460bb7 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractCategoryImporter.class.php @@ -2,6 +2,9 @@ namespace wcf\system\importer; use wcf\data\category\Category; use wcf\data\category\CategoryEditor; +use wcf\data\object\type\ObjectTypeCache; +use wcf\data\package\Package; +use wcf\data\package\PackageCache; /** * Imports categories. @@ -37,6 +40,47 @@ class AbstractCategoryImporter extends AbstractImporter { $category = CategoryEditor::create(array_merge($data, ['objectTypeID' => $this->objectTypeID])); + // handle i18n values + if (!empty($additionalData['i18n'])) { + $values = []; + + foreach (['title', 'description'] as $property) { + if (isset($additionalData['i18n'][$property])) { + $values[$property] = $additionalData['i18n'][$property]; + } + } + + if (!empty($values)) { + /** @var Package $package */ + $package = null; + if ($this->objectTypeID) { + $objectType = ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); + $package = PackageCache::getInstance()->getPackage($objectType->packageID); + } + + if ($package !== null) { + $updateData = []; + if (isset($values['title'])) $updateData['title'] = 'wcf.category.category.title.category' . $category->categoryID; + if (isset($values['description'])) $updateData['description'] = 'wcf.category.category.description.category' . $category->categoryID; + + $items = []; + foreach ($values as $property => $propertyValues) { + foreach ($propertyValues as $languageID => $languageItemValue) { + $items[] = [ + 'languageID' => $languageID, + 'languageItem' => 'wcf.category.category.' . ($property === 'description' ? 'description' : 'title') . '.category' . $category->categoryID, + 'languageItemValue' => $languageItemValue + ]; + } + } + + $this->importI18nValues($items, 'wcf.category', $package->package); + + (new CategoryEditor($category))->update($updateData); + } + } + } + ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $category->categoryID); return $category->categoryID; -- 2.20.1