Language - Fix original_name value in sub-language edition, improve creating of sub-language file and fix visibility action - refs BT#20922

pull/5058/head
christian 11 months ago
parent e1f1cb5afc
commit e29e770252
  1. 101
      public/main/admin/languages.php
  2. 3
      public/main/admin/sub_language_add.php
  3. 41
      public/main/inc/lib/sub_language.class.php

@ -81,70 +81,30 @@ $htmlHeadXtra[] = '<script>
return false;
});
//$(window).load(function () {
$(".make_visible_and_invisible").attr("href","javascript:void(0)");
//});
$("td .make_visible_and_invisible").click(function () {
make_visible="visible.png";
make_invisible="invisible.png";
id_link_tool=$(this).attr("id");
id_img_link_tool="img"+id_link_tool;
path_name_of_imglinktool=$("#"+id_img_link_tool).attr("src");
link_info_id=id_link_tool.split("linktool_");
link_id=link_info_id[1];
link_tool_info=path_name_of_imglinktool.split("/");
my_image_tool=link_tool_info[link_tool_info.length-1];
if (my_image_tool=="visible.png") {
path_name_of_imglinktool=path_name_of_imglinktool.replace(make_visible,make_invisible);
my_visibility=0;
} else {
path_name_of_imglinktool=path_name_of_imglinktool.replace(make_invisible,make_visible);
my_visibility=1;
}
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(myObject) {
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.get_lang('Loading').'</div>");
},
type: "POST",
url: "../admin/languages.php",
data: "id="+link_id+"&visibility="+my_visibility+"&sent_http_request=1",
success: function(datos) {
if (datos=="set_visible" || datos=="set_hidden") {
$("#"+id_img_link_tool).attr("src",path_name_of_imglinktool);
if (my_image_tool=="visible.png") {
$("#"+id_img_link_tool).attr("alt","'.get_lang('Make available').'");
$("#"+id_img_link_tool).attr("title","'.get_lang('Make available').'");
} else {
$("#"+id_img_link_tool).attr("alt","'.get_lang('Make unavailable').'");
$("#"+id_img_link_tool).attr("title","'.get_lang('Make unavailable').'");
}
if (datos=="set_visible") {
$("#id_content_message").html("<div class=\"confirmation-message alert alert-success\">'.get_lang('LanguageIsNowVisible').'</div>");
}
if (datos=="set_hidden") {
$("#id_content_message").html("<div class=\"confirmation-message alert alert-success\">'.get_lang('The language has been hidden. It will not be possible to use it until it becomes visible again.').'</div>");
}
$(".make_visible_and_invisible").click(function(e) {
e.preventDefault();
var id_link_tool = $(this).attr("id");
var link_id = id_link_tool.split("linktool_")[1];
var currentIcon = $("#imglinktool_" + link_id);
$.ajax({
type: "POST",
url: "../admin/languages.php",
data: { id: link_id, visibility: currentIcon.hasClass("mdi-toggle-switch") ? 0 : 1, sent_http_request: 1 },
beforeSend: function() {
$("#id_content_message").html("<div class=\'warning-message alert alert-warning\'><em class=\'fa fa-refresh fa-spin\'></em>'.get_lang('Loading'). '...</div>");
},
success: function(response) {
if (response === "set_visible" || response === "set_hidden") {
var newIconClass = (response === "set_visible") ? "mdi-toggle-switch" : "mdi-toggle-switch-off";
var oldIconClass = (response === "set_visible") ? "mdi-toggle-switch-off" : "mdi-toggle-switch";
currentIcon.removeClass(oldIconClass).addClass(newIconClass);
}
var action = datos.split(":")[0];
if (action && action == "confirm") {
var id = datos.split(":")[1];
var sure = "<div class=\"warning-message alert alert-warning\">'.get_lang('There are users using this language. Do you want to disable this language and set all this users with the default portal language?').'<br /><br /><a href=\"languages.php?action=make_unavailable_confirmed&id="+id+"\" class=\"btn btn--plain\"><em class=\"fa fa-eye\"></em> '.get_lang('Make unavailable').'</a></div>";
$("#id_content_message").html(sure);
$("html, body").animate({ scrollTop: 0 }, 200);
}
} });
});
}
});
});
});
</script>';
@ -343,13 +303,14 @@ while ($row = Database::fetch_array($result_select)) {
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'))."</a>
&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
} else {
if (1 == $row['available']) {
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeunavailable&id=".$row['id']."'>".
Display::getMdiIcon(StateIcon::ACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Make unavailable'), ['id' => 'imglinktool_'.$row['id']])."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
} else {
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=makeavailable&id=".$row['id']."'>".
Display::getMdiIcon(StateIcon::INACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Make available'), ['id' => 'imglinktool_'.$row['id']])."</a> <a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'))."</a>&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
}
$action = ($row['available'] == 1) ? 'makeunavailable' : 'makeavailable';
$icon = ($row['available'] == 1) ? StateIcon::ACTIVE : StateIcon::INACTIVE;
$tooltip = ($row['available'] == 1) ? get_lang('Make unavailable') : get_lang('Make available');
$row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_".$row['id']."\" href='".api_get_self()."?action=$action&id=".$row['id']."'>".
Display::getMdiIcon($icon, 'ch-tool-icon', null, ICON_SIZE_SMALL, $tooltip, ['id' => 'imglinktool_'.$row['id']])."</a>
<a href='".api_get_self()."?action=edit&id=".$row['id']."#value'>".Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit'))."</a>
&nbsp;".$setplatformlanguage.$allow_use_sub_language.$allow_add_term_sub_language.$allow_delete_sub_language;
}
$language_data[] = $row_td;
}

@ -7,6 +7,9 @@
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
ini_set('memory_limit', '512M');
ini_set('max_execution_time', 300);
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();

@ -182,8 +182,9 @@ class SubLanguageManager
// Check if the translations directory is writable
if (!is_writable($translationsDir)) {
// Attempt to set writable permissions
if (!@chmod($translationsDir, 0775)) { // You might adjust the permission level as needed
return false; // Failed to set writable permissions
if (!@chmod($translationsDir, 0775)) {
error_log("Failed to set writable permissions for $translationsDir");
return false;
}
}
@ -191,7 +192,8 @@ class SubLanguageManager
if (!file_exists($poFilePath)) {
$initialContent = "# Translation file for $subLanguageIsoCode\nmsgid \"\"\nmsgstr \"\"\n";
if (false === file_put_contents($poFilePath, $initialContent)) {
return false; // Failed to write the file
error_log("Failed to write the initial content to $poFilePath");
return false;
}
}
@ -603,23 +605,38 @@ class SubLanguageManager
*/
private static function getTranslationForVariable(string $variable, string $filename, $checkSubLanguagePath = false): string
{
$poFilePath = self::getPoFilePath($filename, $checkSubLanguagePath);
if (!file_exists($poFilePath)) {
$shortLanguageCode = self::getShortLanguageCode($filename);
$poFilePath = self::getPoFilePath($shortLanguageCode . '.po', $checkSubLanguagePath);
$poFilePath = api_get_path(SYS_PATH) . self::LANGUAGE_TRANS_PATH . $filename;
if ($checkSubLanguagePath) {
$poFilePath = api_get_path(SYS_PATH) . self::SUBLANGUAGE_TRANS_PATH . $filename;
if (!file_exists($poFilePath)) {
return '';
}
}
if (file_exists($poFilePath)) {
$content = file_get_contents($poFilePath);
$pattern = '/msgid "' . preg_quote($variable, '/') . '"\nmsgstr "(.*?)"/';
if (preg_match($pattern, $content, $match)) {
return $match[1];
}
$content = file_get_contents($poFilePath);
$pattern = '/msgid "' . preg_quote($variable, '/') . '"\nmsgstr "(.*?)"/';
if (preg_match($pattern, $content, $match)) {
return $match[1];
}
return '';
}
private static function getPoFilePath(string $filename, bool $checkSubLanguagePath): string
{
$path = $checkSubLanguagePath ? self::SUBLANGUAGE_TRANS_PATH : self::LANGUAGE_TRANS_PATH;
return api_get_path(SYS_PATH) . $path . $filename;
}
private static function getShortLanguageCode(string $filename): string
{
$parts = explode('.', $filename);
$languageCodeParts = explode('_', $parts[1]);
return $parts[0].'.'.$languageCodeParts[0];
}
/**
* Updates or adds a msgid in the specified .po file.
*

Loading…
Cancel
Save