From: Cyperghost Date: Wed, 20 Nov 2024 10:47:05 +0000 (+0100) Subject: Implement `TI18nDatabaseObjectAction::getLanguageItem()` to generate dynamic language... X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=19c1689fe9b16e62009ef3cfd96a7ee6b723c904;p=GitHub%2FWoltLab%2FWCF.git Implement `TI18nDatabaseObjectAction::getLanguageItem()` to generate dynamic language item names --- diff --git a/wcfsetup/install/files/lib/data/TI18nDatabaseObjectAction.class.php b/wcfsetup/install/files/lib/data/TI18nDatabaseObjectAction.class.php index 68fa37ed79..b2d59d133c 100644 --- a/wcfsetup/install/files/lib/data/TI18nDatabaseObjectAction.class.php +++ b/wcfsetup/install/files/lib/data/TI18nDatabaseObjectAction.class.php @@ -28,7 +28,7 @@ trait TI18nDatabaseObjectAction $langaugeItems = []; foreach ($this->getObjects() as $object) { foreach ($this->getI18nSaveTypes() as $name => $regex) { - if ($object->$name === \str_replace('\d+', $object->getObjectID(), $regex)) { + if ($object->$name === $this->getLanguageItem($object, $regex)) { $langaugeItems[] = $object->$name; } } @@ -100,7 +100,7 @@ trait TI18nDatabaseObjectAction $updateData = $deleteData = []; foreach ($this->getI18nSaveTypes() as $name => $regex) { - $languageName = \str_replace('\d+', $object->getObjectID(), $regex); + $languageName = $this->getLanguageItem($object, $regex); if (isset($this->parameters[$name . '_i18n'])) { I18nHandler::getInstance()->save( $this->parameters[$name . '_i18n'], @@ -121,4 +121,12 @@ trait TI18nDatabaseObjectAction $editor->update($updateData); } } + + /** + * Formats the language item. + */ + protected function getLanguageItem(DatabaseObject $object, string $regex): string + { + return \str_replace('\d+', $object->getObjectID(), $regex); + } } diff --git a/wcfsetup/install/files/lib/data/menu/MenuAction.class.php b/wcfsetup/install/files/lib/data/menu/MenuAction.class.php index fc426a5117..a0c73611b5 100644 --- a/wcfsetup/install/files/lib/data/menu/MenuAction.class.php +++ b/wcfsetup/install/files/lib/data/menu/MenuAction.class.php @@ -5,6 +5,7 @@ namespace wcf\data\menu; use wcf\data\AbstractDatabaseObjectAction; use wcf\data\box\BoxAction; use wcf\data\box\BoxEditor; +use wcf\data\DatabaseObject; use wcf\data\TI18nDatabaseObjectAction; use wcf\system\exception\PermissionDeniedException; @@ -111,7 +112,7 @@ class MenuAction extends AbstractDatabaseObjectAction public function getI18nSaveTypes(): array { return [ - 'title' => 'wcf.menu.com.woltlab.wcf.genericMenu\d+' + 'title' => 'wcf.menu.\w+' ]; } @@ -126,4 +127,15 @@ class MenuAction extends AbstractDatabaseObjectAction { return PACKAGE_ID; } + + protected function getLanguageItem(DatabaseObject $object, string $regex): string + { + \assert($object instanceof Menu); + + return \str_replace( + '\w+', + $object->identifier ?: 'com.woltlab.wcf.genericMenu' . $object->menuID, + $regex + ); + } }