diff --git a/config/areas/languages/dialogs.php b/config/areas/languages/dialogs.php index e208ac973f..3156e2a8ad 100644 --- a/config/areas/languages/dialogs.php +++ b/config/areas/languages/dialogs.php @@ -239,25 +239,56 @@ } $fields = $translationDialogFields; - $fields['key']['disabled'] = true; - $fields['value']['autofocus'] = true; + $fields['key']['disabled'] = true; + + $value = ['key' => $variable->key()]; + + // if language variable is array, + // set text fields as per array size + // otherwise it will show only one textarea + if (is_array($variable->value()) === true) { + unset($fields['value']); + + foreach ($variable->value() as $index => $val) { + $fields['value_' . $index] = [ + 'autofocus' => $index === 0, + 'counter' => false, + 'label' => I18n::translate('language.variable.value') . ' ' . ($index + 1), + 'type' => 'text', + ]; + $value['value_' . $index] = $val; + } + } else { + $fields['value']['autofocus'] = true; + $value['value'] = $variable->value(); + } return [ 'component' => 'k-form-dialog', 'props' => [ 'fields' => $fields, 'size' => 'large', - 'value' => [ - 'key' => $variable->key(), - 'value' => $variable->value() - ] + 'value' => $value ], ]; }, 'submit' => function (string $languageCode, string $translationKey) { - Find::language($languageCode)->variable($translationKey, true)->update( - App::instance()->request()->get('value', '') - ); + $kirby = App::instance(); + $variable = Find::language($languageCode)->variable($translationKey, true); + + // if the language variable is array + // it reads the text field values as many as the number of arrays + if (is_array($variable->value()) === true) { + $value = array_map( + fn ($val, $index) => $kirby->request()->get('value_' . $index, ''), + $variable->value(), + array_keys($variable->value()) + ); + } else { + $value = $kirby->request()->get('value', ''); + } + + $variable->update($value); return true; } diff --git a/src/Cms/LanguageVariable.php b/src/Cms/LanguageVariable.php index 7ca846bf87..f09653fd95 100644 --- a/src/Cms/LanguageVariable.php +++ b/src/Cms/LanguageVariable.php @@ -102,7 +102,7 @@ public function key(): string /** * Sets a new value for the language variable */ - public function update(string|null $value = null): static + public function update(string|array|null $value = null): static { $translations = $this->language->translations(); $translations[$this->key] = $value ?? ''; @@ -115,7 +115,7 @@ public function update(string|null $value = null): static /** * Returns the value if the variable has been translated. */ - public function value(): string|null + public function value(): string|array|null { return $this->language->translations()[$this->key] ?? null; }