Add package selection to LanguageImportForm
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 26 Feb 2021 14:12:04 +0000 (15:12 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 26 Feb 2021 14:15:14 +0000 (15:15 +0100)
Resolves #3976

wcfsetup/install/files/acp/templates/languageImport.tpl
wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 0d7df015f45bbe84af151a7fdf894ba4cc359a31..3f5fe280e86aafb3fe922e1787d507320466bf67 100644 (file)
                                <small>{lang}wcf.acp.language.add.source.description{/lang}</small>
                        </dd>
                </dl>
+
+               <dl{if $errorField == 'packageID'} class="formError"{/if}>
+                       <dt><label for="packageID">{lang}wcf.acp.language.add.package{/lang}</label></dt>
+                       <dd>
+                               <select id="packageID" name="packageID">
+                                       <option value="0"></option>
+                                       {foreach from=$packages item=package}
+                                               <option value="{$package->packageID}"{if $package->packageID == $packageID} selected{/if}>{$package->getName()} ({$package->package})</option>
+                                       {/foreach}
+                               </select>
+                               {if $errorField == 'packageID'}
+                                       <small class="innerError">
+                                               {if $errorType == 'empty'}
+                                                       {lang}wcf.global.form.error.empty{/lang}
+                                               {else}
+                                                       {lang}wcf.acp.language.add.package.error.{@$errorType}{/lang}
+                                               {/if}
+                                       </small>
+                               {/if}
+                               <small>{lang}wcf.acp.language.add.package.description{/lang}</small>
+                       </dd>
+               </dl>
                
                {event name='fields'}
        </div>
index a1908cce9d5010a3d86fb3a2ef370898f02d2def..ad067f909aa9186afe95872915faca0c9ebf235b 100644 (file)
@@ -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,
         ]);
     }
 
index 920b7bc5e39d1a00ea4badef7e1555443dacbcf1..1e6484205327d62655c207a3f72506f080aa1812 100644 (file)
@@ -1051,6 +1051,8 @@ ACHTUNG: Die oben genannten Meldungen sind stark gekürzt. Sie können Details z
                <item name="wcf.acp.language.item.languageCategory.error.notUnique"><![CDATA[Der angegebene Bezeichner wird bereits für eine vorhandene Sprachvariablen-Kategorie verwendet.]]></item>
                <item name="wcf.acp.language.item.languageCategory.error.tooFewSegments"><![CDATA[Die angegebene Kategorie enthält {#$segmentCount} Abschnitt{if $segmentCount > 1}e{/if}.]]></item>
                <item name="wcf.acp.language.item.languageCategoryID.mode.new"><![CDATA[Neue Sprachvariablen-Kategorie]]></item>
+               <item name="wcf.acp.language.add.package"><![CDATA[Paket]]></item>
+               <item name="wcf.acp.language.add.package.description"><![CDATA[Die importierten Texte werden dem ausgewählten Paket zugeordnet.]]></item>
        </category>
        <category name="wcf.acp.masterPassword">
                <item name="wcf.acp.masterPassword"><![CDATA[Hauptkennwort]]></item>
index 1b348cdf2ddacd78f2b251c2597b538460207f5b..c6e7dfcf324106f5a9304752b459bc3190438a31 100644 (file)
@@ -1028,6 +1028,8 @@ ATTENTION: The messages listed above are greatly shortened. You can view details
                <item name="wcf.acp.language.item.languageCategory.description"><![CDATA[The entered language category identifier is used to group phrases.]]></item>
                <item name="wcf.acp.language.item.languageCategory.error.notUnique"><![CDATA[The entered identifier is already used by an existing language category.]]></item>
                <item name="wcf.acp.language.item.languageCategory.error.tooFewSegments"><![CDATA[The entered category contains {#$segmentCount} segment{if $segmentCount > 1}s{/if}.]]></item>
+               <item name="wcf.acp.language.add.package"><![CDATA[Package]]></item>
+               <item name="wcf.acp.language.add.package.description"><![CDATA[The imported phrases will be assigned to the selected package.]]></item>
        </category>
        <category name="wcf.acp.masterPassword">
                <item name="wcf.acp.masterPassword"><![CDATA[Master Password]]></item>