Editor : add Tinymce translate html plugin , setting translate_html from Database, global js translatehtml.js and improve pre-loader content translated - Feature task #18893

pull/3924/head
Christian 4 years ago
parent b0574a0235
commit d412f71207
  1. 1
      assets/js/vendor.js
  2. 4
      public/main/exercise/exercise_result.php
  3. 4
      public/main/exercise/exercise_show.php
  4. 4
      public/main/exercise/exercise_submit.php
  5. 4
      public/main/exercise/overview.php
  6. 55
      public/main/inc/lib/api.lib.php
  7. 2
      public/main/inc/lib/display.lib.php
  8. 2
      public/main/inc/lib/text.lib.php
  9. 2
      public/main/survey/fillsurvey.php
  10. 2
      public/main/survey/preview.php
  11. 2
      public/main/survey/question.php
  12. 2
      public/main/survey/survey.php
  13. 2
      public/main/survey/survey_list.php
  14. 2
      public/main/template/default/forum/list.html.twig
  15. 29
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/Basic.php
  16. 6
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/Documents.php
  17. 6
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/IntroductionSection.php
  18. 4
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/Survey.php
  19. 4
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/SurveyQuestion.php
  20. 6
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/TestQuestionDescription.php
  21. 2
      src/CoreBundle/Settings/EditorSettingsSchema.php
  22. 1
      src/CoreBundle/Settings/SettingsManager.php

@ -22,3 +22,4 @@ global.textcomplete = textcomplete;
require('chart.js'); require('chart.js');
require('./annotation.js'); require('./annotation.js');
require('./translatehtml.js');

@ -46,8 +46,8 @@ if (empty($objExercise)) {
api_not_allowed(true); api_not_allowed(true);
} }
$js = '<script>'.api_get_language_translate_html().'</script>'; //$js = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = $js; //$htmlHeadXtra[] = $js;
if (api_is_in_gradebook()) { if (api_is_in_gradebook()) {
$interbreadcrumb[] = [ $interbreadcrumb[] = [

@ -138,8 +138,8 @@ if (!$is_allowedToEdit) {
$allowRecordAudio = 'true' === api_get_setting('enable_record_audio'); $allowRecordAudio = 'true' === api_get_setting('enable_record_audio');
$allowTeacherCommentAudio = true === api_get_configuration_value('allow_teacher_comment_audio'); $allowTeacherCommentAudio = true === api_get_configuration_value('allow_teacher_comment_audio');
$js = '<script>'.api_get_language_translate_html().'</script>'; //$js = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = $js; //$htmlHeadXtra[] = $js;
if (api_is_in_gradebook()) { if (api_is_in_gradebook()) {
$interbreadcrumb[] = [ $interbreadcrumb[] = [

@ -55,8 +55,8 @@ if ($showGlossary) {
$htmlHeadXtra[] = api_get_js('jquery.highlight.js'); $htmlHeadXtra[] = api_get_js('jquery.highlight.js');
} }
$js = '<script>'.api_get_language_translate_html().'</script>'; //$js = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = $js; //$htmlHeadXtra[] = $js;
//$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js'); //$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
//$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js'); //$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');

@ -12,8 +12,8 @@ $current_course_tool = TOOL_QUIZ;
Exercise::cleanSessionVariables(); Exercise::cleanSessionVariables();
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$js = '<script>'.api_get_language_translate_html().'</script>'; //$js = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = $js; //$htmlHeadXtra[] = $js;
// Notice for unauthorized people. // Notice for unauthorized people.
api_protect_course_script(true); api_protect_course_script(true);

@ -7408,73 +7408,38 @@ function api_create_zip(string $name): ZipStream
*/ */
function api_get_language_translate_html() function api_get_language_translate_html()
{ {
$translate = api_get_configuration_value('translate_html'); $translate = (api_get_setting('editor.translate_html') === 'true');
if (!$translate) { if (!$translate) {
return ''; return '';
} }
$languageList = api_get_languages(); /*$languageList = api_get_languages();
$hideAll = ''; $hideAll = '';
foreach ($languageList['all'] as $language) { foreach ($languageList as $isocode => $name) {
$hideAll .= ' $hideAll .= '
$("span:lang('.$language['isocode'].')").filter( $(".mce-translatehtml").hide();
$("span:lang('.$isocode.')").filter(
function(e, val) { function(e, val) {
// Only find the spans if they have set the lang // Only find the spans if they have set the lang
if ($(this).attr("lang") == null) { if ($(this).attr("lang") == null) {
return false; return false;
} }
// Ignore ckeditor classes // Ignore ckeditor classes
return !this.className.match(/cke(.*)/); return !this.className.match(/cke(.*)/);
}).hide();'."\n"; }).hide();'."\n";
} }*/
$userInfo = api_get_user_info(); $userInfo = api_get_user_info();
$languageId = api_get_language_id($userInfo['language']); if (!empty($userInfo['language'])) {
$languageInfo = api_get_language_info($languageId); $isoCode = $userInfo['language'];
$isoCode = 'en';
if (!empty($languageInfo)) {
$isoCode = $languageInfo['isocode'];
} }
return ' return '
$(function() { $(function() {
'.$hideAll.' $(".mce-translatehtml").hide();
var defaultLanguageFromUser = "'.$isoCode.'"; var defaultLanguageFromUser = "'.$isoCode.'";
$("span:lang('.$isoCode.')").show();
$("span:lang('.$isoCode.')").filter(
function() {
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).show();
var defaultLanguage = "";
var langFromUserFound = false;
$(this).find("span").filter(
function() {
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).each(function() {
defaultLanguage = $(this).attr("lang");
if (defaultLanguage) {
$(this).before().next("br").remove();
if (defaultLanguageFromUser == defaultLanguage) {
langFromUserFound = true;
}
}
});
// Show default language
if (langFromUserFound == false && defaultLanguage) {
$("span:lang("+defaultLanguage+")").filter(
function() {
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).show();
}
}); });
'; ';
} }

@ -2642,7 +2642,7 @@ HTML;
} }
$translateHtml = ''; $translateHtml = '';
$translate = api_get_configuration_value('translate_html'); $translate = (api_get_setting('editor.translate_html') === 'true');
if ($translate) { if ($translate) {
$translateHtml = '{type:"script", src:"'.api_get_path(WEB_AJAX_PATH).'lang.ajax.php?a=translate_html&'.api_get_cidreq().'"},'; $translateHtml = '{type:"script", src:"'.api_get_path(WEB_AJAX_PATH).'lang.ajax.php?a=translate_html&'.api_get_cidreq().'"},';
} }

@ -856,7 +856,7 @@ function api_get_short_text_from_html($text, $number)
*/ */
function api_get_filtered_multilingual_HTML_string($htmlString, $language = null) function api_get_filtered_multilingual_HTML_string($htmlString, $language = null)
{ {
if (true != api_get_configuration_value('translate_html')) { if ('false' === api_get_setting('editor.translate_html')) {
return $htmlString; return $htmlString;
} }
$userInfo = api_get_user_info(); $userInfo = api_get_user_info();

@ -543,7 +543,7 @@ if ('' != $survey->getFormFields() &&
$form->setDefaults($user_data); $form->setDefaults($user_data);
} }
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>'; //$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = ch_selectivedisplay::getJs(); $htmlHeadXtra[] = ch_selectivedisplay::getJs();
$htmlHeadXtra[] = survey_question::getJs(); $htmlHeadXtra[] = survey_question::getJs();

@ -48,7 +48,7 @@ $interbreadcrumb[] = [
'name' => strip_tags($survey->getTitle(), '<span>'), 'name' => strip_tags($survey->getTitle(), '<span>'),
]; ];
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>'; //$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = ch_selectivedisplay::getJs(); $htmlHeadXtra[] = ch_selectivedisplay::getJs();
$htmlHeadXtra[] = survey_question::getJs(); $htmlHeadXtra[] = survey_question::getJs();
$show = 0; $show = 0;

@ -11,7 +11,7 @@ use Chamilo\CoreBundle\Framework\Container;
*/ */
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>'; //$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/ /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit(false, true)) { if (!api_is_allowed_to_edit(false, true)) {

@ -132,7 +132,7 @@ if (!empty($action)) {
api_location(api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq()); api_location(api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq());
} }
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>'; //$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
Display::display_header($tool_name, 'Survey'); Display::display_header($tool_name, 'Survey');

@ -47,7 +47,7 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
$courseInfo $courseInfo
); );
$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>'; //$htmlHeadXtra[] = '<script>'.api_get_language_translate_html().'</script>';
if ($isDrhOfCourse) { if ($isDrhOfCourse) {
Display::display_header(get_lang('Survey list')); Display::display_header(get_lang('Survey list'));

@ -3,7 +3,7 @@
{% block content %} {% block content %}
{% autoescape false %} {% autoescape false %}
{% if 'translate_html'|api_get_configuration_value %} {% if 'editor.translate_html'|api_get_setting == 'true' %}
<script> <script>
$(function () { $(function () {
// default // default

@ -66,6 +66,7 @@ class Basic extends Toolbar
* Plugins this toolbar. * Plugins this toolbar.
*/ */
public array $plugins = []; public array $plugins = [];
private string $toolbarSet;
public function __construct( public function __construct(
$router, $router,
@ -136,6 +137,7 @@ class Basic extends Toolbar
$plugins[] = 'blockimagepaste'; $plugins[] = 'blockimagepaste';
} }
$this->defaultPlugins = array_unique(array_merge($this->defaultPlugins, $plugins)); $this->defaultPlugins = array_unique(array_merge($this->defaultPlugins, $plugins));
$this->toolbarSet = $toolbar;
parent::__construct($router, $toolbar, $config, $prefix); parent::__construct($router, $toolbar, $config, $prefix);
} }
@ -194,10 +196,27 @@ class Basic extends Toolbar
]; ];
$config['startupOutlineBlocks'] = true === api_get_configuration_value('ckeditor_startup_outline_blocks');*/ $config['startupOutlineBlocks'] = true === api_get_configuration_value('ckeditor_startup_outline_blocks');*/
$customPlugins = '';
$customPluginsPath = [];
if (api_get_setting('editor.translate_html') === 'true') {
$customPlugins .= ' translatehtml';
$customPluginsPath['translatehtml'] = api_get_path(WEB_PUBLIC_PATH).'libs/editor/tinymce_plugins/translatehtml/plugin.js';
$languageList = api_get_languages();
$rtlIsocodes = ['ps', 'ar', 'he', 'fa'];
$list = [];
foreach ($languageList as $isocode => $name) {
// Example format language list : ['ar:Arabic:rtl', 'fr:French', 'es:Spanish'];
$rtl = (in_array($isocode, $rtlIsocodes)?':rtl':'');
$list[] = $isocode.':'.$name.$rtl;
}
$config['translatehtml_lenguage_list'] = $list;
}
$plugins = [ $plugins = [
'advlist autolink lists link image charmap print preview anchor', 'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen', 'searchreplace visualblocks code fullscreen',
'insertdatetime media table paste wordcount ', 'insertdatetime media table paste wordcount'.$customPlugins,
]; ];
/*plugins: [ /*plugins: [
@ -211,7 +230,11 @@ class Basic extends Toolbar
} }
$config['plugins'] = implode(' ', $plugins); $config['plugins'] = implode(' ', $plugins);
$config['toolbar'] = 'undo redo | bold italic underline strikethrough | insertfile image media template link | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen preview save print | code codesample | ltr rtl'; $config['toolbar'] = 'undo redo directionality | bold italic underline strikethrough | insertfile image media template link | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen preview save print | code codesample | ltr rtl'.$customPlugins;
if (!empty($customPluginsPath)) {
$config['external_plugins'] = $customPluginsPath;
}
//$config['skin'] = 'oxide'; //$config['skin'] = 'oxide';
$config['skin_url'] = '/build/libs/tinymce/skins/ui/oxide'; $config['skin_url'] = '/build/libs/tinymce/skins/ui/oxide';
@ -233,6 +256,8 @@ class Basic extends Toolbar
$config['language_url'] = "$url/libs/editor/langs/$iso.js"; $config['language_url'] = "$url/libs/editor/langs/$iso.js";
} }
/*if (isset($this->config)) { /*if (isset($this->config)) {
$this->config = array_merge($config, $this->config); $this->config = array_merge($config, $this->config);
} else { } else {

@ -79,7 +79,7 @@ class Documents extends Basic
'NumberedList', 'NumberedList',
'BulletedList', 'BulletedList',
'-', '-',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
'true' === api_get_setting('allow_spellcheck') ? 'Scayt' : '', 'true' === api_get_setting('allow_spellcheck') ? 'Scayt' : '',
], ],
'/', '/',
@ -131,7 +131,7 @@ class Documents extends Basic
'-', '-',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''], ['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''],
['Styles', 'Format', 'Font', 'FontSize'], ['Styles', 'Format', 'Font', 'FontSize'],
@ -175,7 +175,7 @@ class Documents extends Basic
'BGColor', 'BGColor',
], ],
[ [
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
'ShowBlocks', 'ShowBlocks',
], ],
'true' === api_get_setting('enabled_wiris') ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''], 'true' === api_get_setting('enabled_wiris') ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],

@ -80,7 +80,7 @@ class IntroductionSection extends Basic
'NumberedList', 'NumberedList',
'BulletedList', 'BulletedList',
'-', '-',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
'true' === api_get_setting('allow_spellcheck') ? 'Scayt' : '', 'true' === api_get_setting('allow_spellcheck') ? 'Scayt' : '',
], ],
'/', '/',
@ -125,7 +125,7 @@ class IntroductionSection extends Basic
'Underline', 'Underline',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true'? 'translatehtml' : '',
], ],
[ [
'ShowBlocks', 'ShowBlocks',
@ -174,7 +174,7 @@ class IntroductionSection extends Basic
'-', '-',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''], ['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''],
['Styles', 'Format', 'Font', 'FontSize'], ['Styles', 'Format', 'Font', 'FontSize'],

@ -69,7 +69,7 @@ class Survey extends Basic
'-', '-',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''], ['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''],
['Styles', 'Format', 'Font', 'FontSize'], ['Styles', 'Format', 'Font', 'FontSize'],
@ -118,7 +118,7 @@ class Survey extends Basic
'Underline', 'Underline',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
'Source', 'Source',
], ],
['Toolbarswitch'], ['Toolbarswitch'],

@ -66,7 +66,7 @@ class SurveyQuestion extends Basic
'-', '-',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''], ['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''],
['Styles', 'Format', 'Font', 'FontSize'], ['Styles', 'Format', 'Font', 'FontSize'],
@ -99,7 +99,7 @@ class SurveyQuestion extends Basic
'Underline', 'Underline',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
'true' === api_get_setting('enabled_wiris') ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''], 'true' === api_get_setting('enabled_wiris') ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
['Toolbarswitch', 'Source'], ['Toolbarswitch', 'Source'],

@ -130,7 +130,7 @@ class TestQuestionDescription extends Basic
'-', '-',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''], ['true' === api_get_setting('allow_spellcheck') ? 'Scayt' : ''],
['Styles', 'Format', 'Font', 'FontSize'], ['Styles', 'Format', 'Font', 'FontSize'],
@ -161,7 +161,7 @@ class TestQuestionDescription extends Basic
'TextColor', 'TextColor',
'BGColor', 'BGColor',
'-', '-',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
'/', '/',
['Styles', 'Format', 'Font', 'FontSize'], ['Styles', 'Format', 'Font', 'FontSize'],
@ -194,7 +194,7 @@ class TestQuestionDescription extends Basic
'Underline', 'Underline',
'TextColor', 'TextColor',
'BGColor', 'BGColor',
api_get_configuration_value('translate_html') ? 'Language' : '', api_get_setting('editor.translate_html') === 'true' ? 'translatehtml' : '',
], ],
['Toolbarswitch', 'Source'], ['Toolbarswitch', 'Source'],
]; ];

@ -36,6 +36,7 @@ class EditorSettingsSchema extends AbstractSettingsSchema
'htmlpurifier_wiki' => '', 'htmlpurifier_wiki' => '',
'enable_iframe_inclusion' => '', 'enable_iframe_inclusion' => '',
'enabled_mathjax' => '', 'enabled_mathjax' => '',
'translate_html' => 'false',
] ]
) )
/*->setAllowedTypes( /*->setAllowedTypes(
@ -67,6 +68,7 @@ class EditorSettingsSchema extends AbstractSettingsSchema
->add('htmlpurifier_wiki', YesNoType::class) ->add('htmlpurifier_wiki', YesNoType::class)
->add('enable_iframe_inclusion', YesNoType::class) ->add('enable_iframe_inclusion', YesNoType::class)
->add('enabled_mathjax', YesNoType::class) ->add('enabled_mathjax', YesNoType::class)
->add('translate_html', YesNoType::class)
; ;
} }
} }

@ -861,6 +861,7 @@ class SettingsManager implements SettingsManagerInterface
'donotlistcampus' => 'platform', 'donotlistcampus' => 'platform',
'gradebook_show_percentage_in_reports' => 'gradebook', 'gradebook_show_percentage_in_reports' => 'gradebook',
'course_creation_splash_screen' => 'Course', 'course_creation_splash_screen' => 'Course',
'translate_html' => 'Editor',
]; ];
} }

Loading…
Cancel
Save