--- /dev/null
+<?php
+
+namespace App\Fields;
+
+use App\Models\ElearningTranslate;
+use App\Models\FluidbookTranslate;
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Util\Str;
+
+class ElearningTranslatedString extends SelectFromArray
+{
+ protected static $__options = null;
+ protected $_ajax = false;
+ protected $_allowsHTML = true;
+
+ /**
+ * @throws \JsonException
+ */
+ public function getOptions()
+ {
+ if (null === self::$__options) {
+ self::$__options = $this->_getOptions();
+ }
+ return self::$__options;
+ }
+
+ protected function _getOptions()
+ {
+ $locale = 'en';
+
+ $translations = ElearningTranslate::getLocaleTranslations($locale);
+ $res = [];
+ foreach ($translations as $k => $translation) {
+ if ($k === 'k' || $k === 'nsis') {
+ continue;
+ }
+ $res[$translation['str']] = $translation['str'];
+ }
+ return $res;
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Fields;
+
+use Cubist\Backpack\Magic\Fields\KeyValueBunchOfFieldsMultiple;
+
+class ElearningTranslationOverwrite extends KeyValueBunchOfFieldsMultiple
+{
+ protected $_adminType = 'elearning_translation_overwrite';
+ protected $_viewNamespace = 'fields';
+
+ public function getDefaultAttributes()
+ {
+ return array_merge(parent::getDefaultAttributes(), ['bunch' => \App\SubForms\ElearningTranslationOverwrite::class, "add_label" => __('Nouvelle traduction')]);
+ }
+}
--- /dev/null
+<?php
+
+namespace App\SubForms;
+
+use App\Fields\ElearningTranslatedString;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\SubForm;
+// __('!! Paramètres des fluidbooks')
+class ElearningTranslationOverwrite extends SubForm
+{
+ public function init()
+ {
+ parent::init();
+ $this->addField('key', ElearningTranslatedString::class, __('Texte original'));
+ $this->addField('value', Text::class, __('Nouvelle traduction'));
+ }
+}
--- /dev/null
+{{-- __('!! Paramètres des fluidbooks') --}}
+@if (!isset($seenTranslationOverwrite))
+ @php $seenTranslationOverwrite=true;@endphp
+ @push('crud_fields_scripts')
+ <script>
+ var allTranslations =@json(\App\Models\FluidbookTranslate::getAllTranslations());
+ var locale = $('select[name="locale"]').val();
+ $(document).on('change', 'select[name="locale"]', function () {
+ 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')
+