--- /dev/null
+<?php
+
+namespace App\Fields;
+
+use App\Models\FluidbookTranslate;
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Util\Str;
+
+class FluidbookTranslatedString extends SelectFromArray
+{
+ protected static $__options = null;
+
+ /**
+ * @throws \JsonException
+ */
+ public function getOptions()
+ {
+ if (null === self::$__options) {
+ self::$__options = $this->_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;
+ }
+}
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;
$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' => '<i class="la la-language"></i>']);
- $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' => '<i class="la la-language"></i>']);
+ $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'));
--- /dev/null
+<?php
+
+namespace App\SubForms;
+
+use App\Fields\FluidbookTranslatedString;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\SubForm;
+
+class FluidbookTranslationOverwrite extends SubForm
+{
+ /**
+ * @var string
+ */
+ protected $_locale = 'en';
+
+ /**
+ * @return string
+ */
+ public function getLocale(): string
+ {
+ return $this->_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'));
+ }
+}