Implement `LanguageContentCopying` event
authormutec <mysterycode@mysterycode.de>
Tue, 31 Jan 2023 19:55:26 +0000 (20:55 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 26 Apr 2023 09:02:49 +0000 (11:02 +0200)
This event is meant to give 3rd-party developers the possibility to copy i18n
contents in every case contents should be copied to another language.

[Tim: Renamed the event to match the event naming scheme]

see #5252

wcfsetup/install/files/lib/data/language/LanguageEditor.class.php
wcfsetup/install/files/lib/system/language/event/LanguageContentCopying.class.php [new file with mode: 0644]

index a2e37741199c65638d5a0509c421d8b15df1574e..b58a1df575d6458e352e7a9278a97465c7e90f06 100644 (file)
@@ -11,8 +11,10 @@ use wcf\data\language\item\LanguageItemList;
 use wcf\data\page\PageEditor;
 use wcf\system\cache\builder\LanguageCacheBuilder;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\io\AtomicWriter;
+use wcf\system\language\event\LanguageContentCopying;
 use wcf\system\language\LanguageFactory;
 use wcf\system\Regex;
 use wcf\system\WCF;
@@ -1041,5 +1043,10 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje
         }
 
         PageEditor::resetCache();
+
+        EventHandler::getInstance()->fire(new LanguageContentCopying(
+            new Language($sourceLanguageID),
+            new Language($destinationLanguageID)
+        ));
     }
 }
diff --git a/wcfsetup/install/files/lib/system/language/event/LanguageContentCopying.class.php b/wcfsetup/install/files/lib/system/language/event/LanguageContentCopying.class.php
new file mode 100644 (file)
index 0000000..bada7fb
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+namespace wcf\system\language\event;
+
+use wcf\data\language\Language;
+use wcf\system\event\IEvent;
+
+/**
+ * Indicates that the contents of a language should be copied to another one.
+ *
+ * @author Florian Gail
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+final class LanguageContentCopying implements IEvent
+{
+    public function __construct(
+        public readonly Language $sourceLanguage,
+        public readonly Language $targetLanguage,
+    ) {
+    }
+}