From 66aa26cc1128d9b755fff6b8f0c05389212e3991 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 26 Feb 2021 15:12:04 +0100 Subject: [PATCH] Add package selection to LanguageImportForm Resolves #3976 --- .../files/acp/templates/languageImport.tpl | 22 ++++++++++++++++++ .../lib/acp/form/LanguageImportForm.class.php | 23 ++++++++++++++++++- wcfsetup/install/lang/de.xml | 2 ++ wcfsetup/install/lang/en.xml | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/acp/templates/languageImport.tpl b/wcfsetup/install/files/acp/templates/languageImport.tpl index 0d7df015f4..3f5fe280e8 100644 --- a/wcfsetup/install/files/acp/templates/languageImport.tpl +++ b/wcfsetup/install/files/acp/templates/languageImport.tpl @@ -58,6 +58,28 @@ {lang}wcf.acp.language.add.source.description{/lang} + + +
+
+ + {if $errorField == 'packageID'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.language.add.package.error.{@$errorType}{/lang} + {/if} + + {/if} + {lang}wcf.acp.language.add.package.description{/lang} +
+ {event name='fields'} diff --git a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php index a1908cce9d..ad067f909a 100644 --- a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php @@ -4,6 +4,8 @@ namespace wcf\acp\form; use wcf\data\language\Language; use wcf\data\language\LanguageEditor; +use wcf\data\package\Package; +use wcf\data\package\PackageCache; use wcf\form\AbstractForm; use wcf\system\exception\SystemException; use wcf\system\exception\UserInputException; @@ -62,6 +64,11 @@ class LanguageImportForm extends AbstractForm */ public $sourceLanguageID = 0; + /** + * @var int + */ + public $packageID = 0; + /** * @inheritDoc */ @@ -85,6 +92,9 @@ class LanguageImportForm extends AbstractForm if (isset($_POST['sourceLanguageID'])) { $this->sourceLanguageID = \intval($_POST['sourceLanguageID']); } + if (isset($_POST['packageID'])) { + $this->packageID = \intval($_POST['packageID']); + } } /** @@ -109,6 +119,10 @@ class LanguageImportForm extends AbstractForm throw new UserInputException('sourceLanguageID'); } + if (!PackageCache::getInstance()->getPackage($this->packageID)) { + throw new UserInputException('packageID'); + } + // try to import try { // open xml document @@ -116,7 +130,7 @@ class LanguageImportForm extends AbstractForm $xml->load($this->filename); // import xml document - $this->language = LanguageEditor::importFromXML($xml, -1, $this->sourceLanguage); + $this->language = LanguageEditor::importFromXML($xml, $this->packageID, $this->sourceLanguage); // copy content if (!isset($this->languages[$this->language->languageID])) { @@ -151,9 +165,16 @@ class LanguageImportForm extends AbstractForm { parent::assignVariables(); + $packages = PackageCache::getInstance()->getPackages(); + \usort($packages, static function (Package $a, Package $b) { + return $a->getName() <=> $b->getName(); + }); + WCF::getTPL()->assign([ 'languages' => $this->languages, 'sourceLanguageID' => $this->sourceLanguageID, + 'packages' => $packages, + 'packageID' => $this->packageID, ]); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 920b7bc5e3..1e64842053 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1051,6 +1051,8 @@ ACHTUNG: Die oben genannten Meldungen sind stark gekürzt. Sie können Details z 1}e{/if}.]]> + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 1b348cdf2d..c6e7dfcf32 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1028,6 +1028,8 @@ ATTENTION: The messages listed above are greatly shortened. You can view details 1}s{/if}.]]> + + -- 2.20.1