Translate HTML text based in the HTML "lang" attribute see BT#15166

$_configuration['translate_html'] = false;
pull/2858/head
Julio Montoya 7 years ago
parent 1e1d8c719b
commit 5c4c90b28c
  1. 2
      main/document/create_document.php
  2. 76
      main/inc/ajax/lang.ajax.php
  3. 7
      main/inc/lib/display.lib.php
  4. 8
      main/inc/lib/javascript/ckeditor/config_js.php
  5. 3
      main/install/configuration.dist.php
  6. 2
      main/template/default/javascript/editor/ckeditor/config_js.tpl
  7. 2
      src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/Documents.php

@ -171,7 +171,7 @@ if ($relative_url == '') {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$editorConfig = [
'ToolbarSet' => ($is_allowed_to_edit ? 'Documents' : 'DocumentsStudent'),
'ToolbarSet' => $is_allowed_to_edit ? 'Documents' : 'DocumentsStudent',
'Width' => '100%',
'Height' => '400',
'cols-size' => [2, 10, 0],

@ -0,0 +1,76 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls.
*/
require_once __DIR__.'/../global.inc.php';
api_protect_course_script(true);
$action = $_REQUEST['a'];
switch ($action) {
case 'translate_html':
$translate = api_get_configuration_value('translate_html');
if (!$translate) {
exit;
}
$languageList = api_get_languages();
$hideAll = '';
foreach ($languageList['all'] as $language) {
$hideAll .= '$("span:lang('.$language['isocode'].')").filter(
function() {
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).hide();';
}
$userInfo = api_get_user_info();
$languageId = api_get_language_id($userInfo['language']);
$languageInfo = api_get_language_info($languageId);
echo '
$(document).ready(function() {
'.$hideAll.'
var defaultLanguageFromUser = "'.$languageInfo['isocode'].'";
$("span:lang('.$languageInfo['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();
}
});
';
break;
default:
echo '';
}
exit;

@ -2815,6 +2815,12 @@ HTML;
}
}
$translateHtml = '';
$translate = api_get_configuration_value('translate_html');
if ($translate) {
$translateHtml = '{type:"script", id:"_fr4", src:"'.api_get_path(WEB_AJAX_PATH).'lang.ajax.php?a=translate_html&'.api_get_cidreq().'"},';
}
$defaultFeatures = implode("','", $defaultFeatures);
$frameReady = '
$.frameReady(function() {
@ -2841,6 +2847,7 @@ HTML;
{type: "stylesheet", id: "_media2", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/build/mediaelementplayer.min.css"},
{type: "stylesheet", id: "_media4", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/plugins/vrview/vrview.css"},
{type: "script", id: "_media4", src: "'.api_get_path(WEB_PUBLIC_PATH).'assets/mediaelement/plugins/vrview/vrview.js"},
'.$translateHtml.'
]
});';

@ -31,5 +31,13 @@ if (!empty($courseId)) {
}
$template->assign('course_condition', $courseCondition);
$languageList = api_get_languages();
$list = [];
foreach ($languageList['all'] as $language) {
$list[] = $language['isocode'].':'.$language['original_name'];
}
$template->assign('language_list', implode("','", $list));
header('Content-type: application/x-javascript');
$template->display($template->get_template('javascript/editor/ckeditor/config_js.tpl'));

@ -1131,6 +1131,9 @@ VALUES (2, 13, 'session_courses_read_only_mode', 'Lock Course In Session', 1, 1,
// Allow to show users in a map, users need to have a coordinates extra field BT#15176
//$_configuration['allow_social_map_fields'] = ['fields' => ['terms_villedustage', 'terms_ville']];
// Translate HTML based in the HTML "lang" attribute see BT#15166
//$_configuration['translate_html'] = false;
// ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email

@ -114,6 +114,8 @@ CKEDITOR.editorConfig = function (config) {
'{{ font_awesome_css }}',
'{{ css_editor }}',
];
config.language_list = ['{{ language_list }}'];
};
// Sets default target to "_blank" in link plugin

@ -78,6 +78,7 @@ class Documents extends Basic
'NumberedList',
'BulletedList',
'-',
api_get_configuration_value('translate_html') ? 'Language' : '',
api_get_setting('allow_spellcheck') === 'true' ? 'Scayt' : '',
],
'/',
@ -123,6 +124,7 @@ class Documents extends Basic
'BGColor',
],
[
api_get_configuration_value('translate_html') ? 'Language' : '',
'ShowBlocks',
'Source',
],

Loading…
Cancel
Save