class FluidbookTranslatedString extends SelectFromArray
{
protected static $__options = null;
+ protected $_ajax = false;
+ protected $_allowsHTML = true;
/**
* @throws \JsonException
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'];
- }
+ $res[$translation['str']] = $translation['str'];
}
return $res;
}
--- /dev/null
+<?php
+
+namespace App\Fields;
+
+use Cubist\Backpack\Magic\Fields\Field;
+use Cubist\Backpack\Magic\Fields\KeyValueBunchOfFieldsMultiple;
+
+class FluidbookTranslationOverwrite extends KeyValueBunchOfFieldsMultiple
+{
+ protected $_adminType = 'fluidbook_translation_overwrite';
+ protected $_viewNamespace='fields';
+
+ public function getDefaultAttributes()
+ {
+ return array_merge(parent::getDefaultAttributes(), ['bunch' => \App\SubForms\FluidbookTranslationOverwrite::class, "add_label" => __('Nouvelle traduction')]);
+ }
+}
$this->addField('section_locale', FormBigSection::class, __('Langue'));
$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->addFieldOnFill('translations', KeyValueBunchOfFieldsMultiple::class, __('Traductions personnalisées'), ['bunch' => FluidbookTranslationOverwrite::class, 'add_label' => __('Nouvelle traduction'),]);
+ $this->addField('translations', \App\Fields\FluidbookTranslationOverwrite::class, __('Traductions personnalisées'));
$this->addField('section_chapters', FormBigSection::class, __('Sommaire'));
$this->addField('chapters', Textarea::class, __('Sommaire'));
class FluidbookTranslationOverwrite extends SubForm
{
-
- /**
- * @param $model CubistMagicAbstractModel
- * @return void
- */
- public function setModelInstance($model)
- {
- $this->addField('key', FluidbookTranslatedString::class, __('Texte original'), ['locale' => $model->locale]);
- $this->addField('value', Text::class, __('Nouvelle traduction'));
- }
-
public function init()
{
parent::init();
-
+ $this->addField('key', FluidbookTranslatedString::class, __('Texte original'));
+ $this->addField('value', Text::class, __('Nouvelle traduction'));
}
}
--- /dev/null
+@if (!isset($seenTranslationOverwrite))
+ @php $seenTranslationOverwrite=true;@endphp
+ @push('crud_fields_scripts')
+ <script>
+ var allTranslations =@json(\App\Models\FluidbookTranslate::getAllFluidbookTranslations());
+ var locale = $('select[name="locale"]').val();
+ $(document).on('change', 'select[name="locale"]', function () {
+ console.log(locale);
+ locale = $('select[name="locale"]').val()
+ updateTranslationOverwrite();
+ });
+
+ $(document).on('change', '[data-bunch-name="translations"] select', function () {
+ var text = $(this).closest('.bunchfields').find('input');
+ var selectVal = $(this).val();
+ if ($(text).val() === '') {
+ var k = allTranslations['locale'];
+ $.each(allTranslations[locale], function (k, t) {
+ if (k === 'k') {
+ return;
+ }
+ var str = window.atob(k.substring(2));
+ if (selectVal === str) {
+ $(text).val(t.translation);
+ return true;
+ }
+ });
+ }
+ });
+
+ setTimeout(function () {
+ updateTranslationOverwrite();
+ }, 1000);
+
+ function updateTranslationOverwrite() {
+ function escapeStr(str) {
+ if (str) {
+ return str.replace(/([ #;?%&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1');
+ }
+ return str;
+ }
+
+
+ $('[data-bunch-name="translations"]').each(function () {
+ $(this).find('.item').each(function () {
+ var s = $(this).find('select');
+ $.each(allTranslations[locale], function (k, t) {
+ if (k === 'k') {
+ return;
+ }
+ var str = window.atob(k.substring(2));
+ if (k === 'nsis') {
+ return;
+ }
+ var d = t.translation;
+ if (t.translation !== str) {
+ d += '<i style="font-size: 75%;display: block;margin-top: -5px;">' + str + '</i>';
+ }
+ $(s).find('option[value="' + escapeStr(str) + '"]').text(d);
+ });
+ $(s).removeClass('select2-hidden-accessible');
+ $(this).find('.select2').remove();
+ });
+ });
+ initUntriggeredSelectFromArray($);
+ }
+ </script>
+ @endpush
+
+ @push('crud_fields_styles')
+ <style>
+ [data-bunch-name="translations"] .select2-selection__rendered {
+ margin-top: -5px;
+ }
+ </style>
+ @endpush
+@endif
+@include('cubist_back::fields.bunch_keyvalue_multiple')
+