From c1e7b00ff174deb7a00d5d38b9acbdce8824aca7 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 19 May 2022 15:11:31 +0200 Subject: [PATCH] wip #4285 @1 --- app/Fields/FluidbookTranslatedString.php | 44 +++++++++++++++++++ app/Models/FluidbookPublication.php | 8 +++- .../FluidbookTranslationOverwrite.php | 38 ++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 app/Fields/FluidbookTranslatedString.php create mode 100644 app/SubForms/FluidbookTranslationOverwrite.php diff --git a/app/Fields/FluidbookTranslatedString.php b/app/Fields/FluidbookTranslatedString.php new file mode 100644 index 000000000..1f9e5d26a --- /dev/null +++ b/app/Fields/FluidbookTranslatedString.php @@ -0,0 +1,44 @@ +_getOptions(); + } + return self::$__options; + } + + protected function _getOptions() + { + $locale = 'en'; + + $translations = FluidbookTranslate::getFluidbookTranslation($locale); + $res = []; + foreach ($translations as $k => $translation) { + if ($k === 'k' || $k === 'nsis') { + continue; + } + if (!$translation['translation']) { + $res[$translation['str']] = $translation['str']; + } else if (Str::lower($translation['translation']) == Str::lower($translation['str'])) { + $res[$translation['str']] = $translation['translation']; + } else { + $res[$translation['str']] = $translation['translation'] . ' // ' . $translation['str']; + } + } + return $res; + } +} diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index c33167ec2..60fa304e4 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -8,6 +8,8 @@ use App\Fields\FluidbookTitle; use App\Fields\User; use App\Models\Base\ToolboxModel; use App\Models\Traits\PublicationSettings; +use App\SubForms\FluidbookTranslationOverwrite; +use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple; use Cubist\Backpack\Magic\Fields\Code; use Cubist\Backpack\Magic\Fields\Datetime; use Cubist\Backpack\Magic\Fields\FormBigSection; @@ -60,8 +62,10 @@ class FluidbookPublication extends ToolboxModel $this->addField('theme', \App\Fields\FluidbookTheme::class); $this->addField('section_locale', FormBigSection::class, __('Langue')); - $this->addField('locale', FluidbookLocale::class, 'Langue', ['default' => 'fr', 'allows_null' => false, 'filter' => true, 'filter_label' => 'Langue', 'column' => true, 'column_label' => '']); - $this->addField('translations', Code::class, 'Traductions', ['language' => 'javascript']); + $this->addField('locale', FluidbookLocale::class, __('Langue principale'), ['default' => 'fr', 'allows_null' => false, 'filter' => true, 'filter_label' => 'Langue', 'column' => true, 'column_label' => '']); + $this->addField('translations', Code::class, __('Traductions')); + $this->addField('translations_1', KeyValueBunchOfFieldsMultiple::class, __('Traductions personnalisées'), ['bunch' => FluidbookTranslationOverwrite::class, 'add_label' => __('Nouvelle traduction'),]); + $this->addField('section_chapters', FormBigSection::class, __('Sommaire')); $this->addField('chapters', Textarea::class, __('Sommaire')); diff --git a/app/SubForms/FluidbookTranslationOverwrite.php b/app/SubForms/FluidbookTranslationOverwrite.php new file mode 100644 index 000000000..4a366f9f6 --- /dev/null +++ b/app/SubForms/FluidbookTranslationOverwrite.php @@ -0,0 +1,38 @@ +_locale; + } + + /** + * @param string $locale + */ + public function setLocale(string $locale): void + { + $this->_locale = $locale; + } + + public function init() + { + parent::init(); + $this->addField('key', FluidbookTranslatedString::class, __('Texte original'), ['locale' => $this->getLocale()]); + $this->addField('value', Text::class, __('Nouvelle traduction')); + } +} -- 2.39.5