From 19c1689fe9b16e62009ef3cfd96a7ee6b723c904 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Wed, 20 Nov 2024 11:47:05 +0100 Subject: [PATCH] Implement `TI18nDatabaseObjectAction::getLanguageItem()` to generate dynamic language item names --- .../lib/data/TI18nDatabaseObjectAction.class.php | 12 ++++++++++-- .../files/lib/data/menu/MenuAction.class.php | 14 +++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) 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 + ); + } } -- 2.20.1