From 316b48fe72e26b37f25e3b66710c1e0d0af52b5f Mon Sep 17 00:00:00 2001 From: EV-soft <21997911+EV-soft@users.noreply.github.com> Date: Fri, 13 Mar 2026 11:55:09 +0100 Subject: [PATCH 1/3] Implement language string extraction for translation Added functionality to extract and display language strings for translation. --- tinyfilemanager.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index 81da5483..8b97346c 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -5609,5 +5609,32 @@ function lng($txt) else if (isset($tr['en'][$txt])) return fm_enc($tr['en'][$txt]); else return "$txt"; } + +if ($lang != 'en') { # Check your language +// if (@$_GET['lng'] != 'lng') { # URL-trigger: tinyfilemanager.php?lng=lng + function extractLngStrings($input) { # Make a updated lng-keylist: + preg_match_all('/lng\([\'"]([^\'"]*)[\'"]\)/', $input, $matches); # Scann source-file for keywords in lng()-call + if (!isset($matches[1])) { return []; } # + $unique = array_unique($matches[1]); # Remove dublicates + sort($unique, SORT_NATURAL | SORT_FLAG_CASE); # Sort alphabetic + return $unique; # + } # Output result to screen: + echo '
Translate control:
'; + echo 'Updated list of current keywords for your language, to be used in translation.json:
'; # 'Vers:'. VERSION . + echo 'Use CTRL-A to mark all in the green frame. Copy/Paste it to your UTF8 editor and complete translation.'; + echo '
{
'; 
+    echo '"name": "'.$lang_list[$lang].'",
'; + echo '"code": "'.$lang.'",
'; + echo '"translation": {
'; + $array= extractLngStrings(file_get_contents(__FILE__)); + $last = count($array) - 1; $n=0; + foreach ($array as $ix => $key) { if ($key==lng($key)) $n++; + echo ' "'.$key.'": "'.($key==lng($key) ? ''. $n.': ' : '').lng($key).''.'"'; + echo ($ix < $last) ? ",
" : "
"; + } + echo '}
'; + echo 'Check the strings shown with italic & bold (KeyString != TranslateString)
'; + echo 'If you have a complete translate for the newest version of Filemanager, do share it on Github'; +} ?> From e0df11c0dc4f455ad0b7077a601606818dd128ef Mon Sep 17 00:00:00 2001 From: EV-soft <21997911+EV-soft@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:22:11 +0100 Subject: [PATCH 2/3] Add show_translation option to configuration Added show_translation configuration option to manage translation visibility in the Tiny File Manager. --- tinyfilemanager.php | 97 +++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index 8b97346c..70ffa5c9 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -1,7 +1,6 @@ data['lang']) ? $cfg->data['lang'] : 'en'; +// Show or hide translation control +$show_translation = isset($cfg->data['show_translation']) ? $cfg->data['show_translation'] : true; + // Show or hide files and folders that starts with a dot $show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true; @@ -537,13 +539,14 @@ function getClientIP() // Save Config if (isset($_POST['type']) && $_POST['type'] == "settings") { - global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $theme; + global $cfg, $lang, $show_translation, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $theme; $newLng = $_POST['js-language']; fm_get_translations([]); if (!array_key_exists($newLng, $lang_list)) { $newLng = 'en'; } - + + $trl = isset($_POST['js-show-translation']) && $_POST['js-show-translation'] == "true" ? true : false; $erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false; $shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false; $hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false; @@ -553,15 +556,15 @@ function getClientIP() $cfg->data['lang'] = $newLng; $lang = $newLng; } + if ($cfg->data['show_translation'] != $trl) { + $cfg->data['show_translation'] = $trl; + $show_translation = $trl; + } if ($cfg->data['error_reporting'] != $erp) { $cfg->data['error_reporting'] = $erp; $report_errors = $erp; } - if ($cfg->data['show_hidden'] != $shf) { - $cfg->data['show_hidden'] = $shf; - $show_hidden_files = $shf; - } - if ($cfg->data['show_hidden'] != $shf) { + if ($cfg->data['show_hidden'] != $shf) { $cfg->data['show_hidden'] = $shf; $show_hidden_files = $shf; } @@ -1599,7 +1602,17 @@ function getSelected($l) -
+ +
+ +
+
+ /> +
+
+
+ +
@@ -4892,7 +4905,8 @@ function backup(e, t) { // Toast message function toast(txt) { var x = document.getElementById("snackbar"); - x.innerHTML = txt; + var translated = (typeof i18n !== 'undefined' && i18n[txt]) ? i18n[txt] : txt; + x.innerHTML = translated; x.className = "show"; setTimeout(function() { x.className = x.className.replace("show", ""); @@ -5488,7 +5502,7 @@ function renderThemeMode() { */ function lng($txt) { - global $lang; + global $lang, $tr; // English Language $tr['en']['AppName'] = 'Tiny File Manager'; @@ -5610,31 +5624,62 @@ function lng($txt) else return "$txt"; } -if ($lang != 'en') { # Check your language -// if (@$_GET['lng'] != 'lng') { # URL-trigger: tinyfilemanager.php?lng=lng - function extractLngStrings($input) { # Make a updated lng-keylist: - preg_match_all('/lng\([\'"]([^\'"]*)[\'"]\)/', $input, $matches); # Scann source-file for keywords in lng()-call - if (!isset($matches[1])) { return []; } # +if ($show_translation == true) { + function extractTxt($input, $txt='lng') { # Make a updated lng-keylist: + preg_match_all('/'.$txt.'\([\'"]([^\'"]*)[\'"]\)/',$input,$matches);# Scann source-file for keywords in lng()-call + if (!isset($matches[1])) { return []; } $unique = array_unique($matches[1]); # Remove dublicates sort($unique, SORT_NATURAL | SORT_FLAG_CASE); # Sort alphabetic - return $unique; # - } # Output result to screen: - echo '
Translate control:
'; - echo 'Updated list of current keywords for your language, to be used in translation.json:
'; # 'Vers:'. VERSION . - echo 'Use CTRL-A to mark all in the green frame. Copy/Paste it to your UTF8 editor and complete translation.'; + return $unique; + } + function indentAfter($text, $totalWidth = 30) { + return str_repeat(' ', max(0, $totalWidth - strlen($text))); + } + function arrPretty($arrVar,$titl='',$attr='rows="10" cols="120"',$wdth='50%',$rtrn=false) { ## Pretty output of any variable + $result= " +
".$titl."
+
\n"; + if (!$rtrn) echo $result; else return $result; + } + + echo '
Translate control:
'; # Output result to screen: + echo 'Updated list of current keywords for your language, to be used in translation.json:
'; + echo 'Use CTRL-A to mark all in the green frame. Copy/Paste it to your UTF8 editor and complete translation or let AI do the work. (Plese profread!)'; echo '
{
'; 
     echo '"name": "'.$lang_list[$lang].'",
'; echo '"code": "'.$lang.'",
'; + echo '"vers": "'.APP_TITLE.' '.VERSION.'",
'; + echo '"note": "vers, note, date, author are new fields 2026",
'; + echo '"date": "'.date("Y-m-d").'",
'; + echo '"author": "----",
'; echo '"translation": {
'; - $array= extractLngStrings(file_get_contents(__FILE__)); - $last = count($array) - 1; $n=0; - foreach ($array as $ix => $key) { if ($key==lng($key)) $n++; + $array1= extractTxt(file_get_contents(__FILE__),'lng'); + $array2= extractTxt(file_get_contents(__FILE__),'toast'); + $array = array_merge(array_values($array1), array_values($array2)); + $last = count($array) - 1; $n=0; + foreach ($array as $ix => $key) { + if ($key == lng($key)) $n++; echo ' "'.$key.'": "'.($key==lng($key) ? ''. $n.': ' : '').lng($key).''.'"'; echo ($ix < $last) ? ",
" : "
"; } echo '}
'; echo 'Check the strings shown with italic & bold (KeyString != TranslateString)
'; echo 'If you have a complete translate for the newest version of Filemanager, do share it on Github'; -} + arrPretty($array1,'$Strings sendt to lng()'); + arrPretty($array2,'$Strings sendt to toast()'); + if (true) { + echo '

Suggestions for updating the english tr table:
'; + $s= []; + foreach ($array as $a) { # in function lng($txt) add $tr as global: "global $lang, $tr;" + $str = ' $tr[\'en\'][\''.$a.'\'] '; + echo $str.indentAfter($str,70).'= \''.($tr['en'][($a)] > '' ? $tr['en'][($a)] : $a).'\';
'; + $newArr[$a] = $a; + } + echo ' Total: '.count($array) . ' keys in list.'; + $ar= array_merge($newArr, array_diff($tr['en'])); + } +} ?> From f353bc294ddb51b1db6c46fd2ce5fe6c176e7d63 Mon Sep 17 00:00:00 2001 From: EV-soft <21997911+EV-soft@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:43:55 +0100 Subject: [PATCH 3/3] Update tinyfilemanager.php --- tinyfilemanager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index 70ffa5c9..16a92cf3 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -5681,5 +5681,5 @@ function arrPretty($arrVar,$titl='',$attr='rows="10" cols="120"',$wdth='50%',$rt $ar= array_merge($newArr, array_diff($tr['en'])); } } - + ?>