From 23c7e404a0a19497bf6992fe7f727387417f69a9 Mon Sep 17 00:00:00 2001 From: maghuro <1546139+maghuro@users.noreply.github.com> Date: Wed, 1 Jul 2026 12:54:03 +0100 Subject: [PATCH] i18n: localize remaining hard-coded UI strings --- tinyfilemanager.php | 189 +++++++++++++++++++++++++++----------------- 1 file changed, 118 insertions(+), 71 deletions(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index 756b4a0f..586dcfd1 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -486,7 +486,7 @@ function getClientIP() if ((isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']]) || !FM_USE_AUTH) && isset($_POST['ajax'], $_POST['token'])) { if (!verifyToken($_POST['token'])) { header('HTTP/1.0 401 Unauthorized'); - die("Invalid Token."); + die(lng('Invalid Token.')); } //search : get list of files from the current folder @@ -529,7 +529,7 @@ function getClientIP() fclose($fd); if ($write_results === false) { header("HTTP/1.1 500 Internal Server Error"); - die("Could Not Write File! - Check Permissions / Ownership"); + die(lng('Could not write file. Check permissions and ownership.')); } die(true); } @@ -547,12 +547,12 @@ function getClientIP() $fullyQualifiedFileName = $fullPath . $fileName; try { if (!file_exists($fullyQualifiedFileName)) { - throw new Exception("File {$fileName} not found"); + throw new Exception(sprintf(lng('File %s not found'), fm_enc($fileName))); } if (copy($fullyQualifiedFileName, $fullPath . $newFileName)) { - echo "Backup {$newFileName} created"; + echo sprintf(lng('Backup %s created'), fm_enc($newFileName)); } else { - throw new Exception("Could not copy file {$fileName}"); + throw new Exception(sprintf(lng('Could not copy file %s'), fm_enc($fileName))); } } catch (Exception $e) { echo $e->getMessage(); @@ -634,7 +634,7 @@ function get_file_path() $knownPorts = [22, 23, 25, 3306]; if (preg_match("/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/i", $domain) || in_array($port, $knownPorts)) { - $err = array("message" => "URL is not allowed"); + $err = array('message' => lng('URL is not allowed')); event_callback(array("fail" => $err)); exit(); } @@ -651,7 +651,7 @@ function get_file_path() $err = false; if (!$isFileAllowed) { - $err = array("message" => "File extension is not allowed"); + $err = array('message' => lng('File extension is not allowed')); event_callback(array("fail" => $err)); exit(); } @@ -690,7 +690,7 @@ function get_file_path() } else { unlink($temp_file); if (!$err) { - $err = array("message" => "Invalid url parameter"); + $err = array('message' => lng('Invalid URL parameter')); } event_callback(array("fail" => $err)); } @@ -708,11 +708,11 @@ function get_file_path() } $is_dir = is_dir($path . '/' . $del); if (fm_rdelete($path . '/' . $del)) { - $msg = $is_dir ? lng('Folder') . ' %s ' . lng('Deleted') : lng('File') . ' %s ' . lng('Deleted'); - fm_set_msg(sprintf($msg, fm_enc($del))); + $msg = $is_dir ? lng('Folder deleted') : lng('File deleted'); + fm_set_msg(sprintf($msg, '' . fm_enc($del) . '')); } else { - $msg = $is_dir ? lng('Folder') . ' %s ' . lng('not deleted') : lng('File') . ' %s ' . lng('not deleted'); - fm_set_msg(sprintf($msg, fm_enc($del)), 'error'); + $msg = $is_dir ? lng('Folder not deleted') : lng('File not deleted'); + fm_set_msg(sprintf($msg, '' . fm_enc($del) . ''), 'error'); } } else { fm_set_msg(lng('Invalid file or folder name'), 'error'); @@ -733,21 +733,21 @@ function get_file_path() if ($type == "file") { if (!file_exists($path . '/' . $new)) { if (fm_is_valid_ext($new)) { - @fopen($path . '/' . $new, 'w') or die('Cannot open file: ' . $new); - fm_set_msg(sprintf(lng('File') . ' %s ' . lng('Created'), fm_enc($new))); + @fopen($path . '/' . $new, 'w') or die(sprintf(lng('Cannot open file: %s'), fm_enc($new))); + fm_set_msg(sprintf(lng('File created'), '' . fm_enc($new) . '')); } else { fm_set_msg(lng('File extension is not allowed'), 'error'); } } else { - fm_set_msg(sprintf(lng('File') . ' %s ' . lng('already exists'), fm_enc($new)), 'alert'); + fm_set_msg(sprintf(lng('File already exists'), '' . fm_enc($new) . ''), 'alert'); } } else { if (fm_mkdir($path . '/' . $new, false) === true) { - fm_set_msg(sprintf(lng('Folder') . ' %s ' . lng('Created'), $new)); + fm_set_msg(sprintf(lng('Folder created'), '' . fm_enc($new) . '')); } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) { - fm_set_msg(sprintf(lng('Folder') . ' %s ' . lng('already exists'), fm_enc($new)), 'alert'); + fm_set_msg(sprintf(lng('Folder already exists'), '' . fm_enc($new) . ''), 'alert'); } else { - fm_set_msg(sprintf(lng('Folder') . ' %s ' . lng('not created'), fm_enc($new)), 'error'); + fm_set_msg(sprintf(lng('Folder not created'), '' . fm_enc($new) . ''), 'error'); } } } else { @@ -817,9 +817,9 @@ function get_file_path() $loop_count++; } if (fm_rcopy($from, $fn_duplicate, False)) { - fm_set_msg(sprintf('Copied from %s to %s', fm_enc($copy), fm_enc($fn_duplicate))); + fm_set_msg(sprintf(lng('Copied from') . ' %s ' . lng('to') . ' %s', fm_enc($copy), fm_enc($fn_duplicate))); } else { - fm_set_msg(sprintf('Error while copying from %s to %s', fm_enc($copy), fm_enc($fn_duplicate)), 'error'); + fm_set_msg(sprintf(lng('Error while copying from') . ' %s ' . lng('to') . ' %s', fm_enc($copy), fm_enc($fn_duplicate)), 'error'); } } else { fm_set_msg(lng('Paths must be not equal'), 'alert'); @@ -834,7 +834,7 @@ function get_file_path() if (!verifyToken($_POST['token'])) { fm_set_msg(lng('Invalid Token.'), 'error'); - die("Invalid Token."); + die(lng('Invalid Token.')); } // from @@ -904,7 +904,7 @@ function get_file_path() if (isset($_POST['rename_from'], $_POST['rename_to'], $_POST['token']) && !FM_READONLY) { if (!verifyToken($_POST['token'])) { fm_set_msg(lng("Invalid Token."), 'error'); - die("Invalid Token."); + die(lng('Invalid Token.')); } // old name $old = urldecode($_POST['rename_from']); @@ -979,7 +979,7 @@ function get_file_path() exit(); } } else { - $response = array('status' => 'error', 'info' => "Token Missing."); + $response = array('status' => 'error', 'info' => lng('Token Missing.')); echo json_encode($response); exit(); } @@ -1000,7 +1000,7 @@ function get_file_path() $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false; $response = array( 'status' => 'error', - 'info' => 'Oops! Try again' + 'info' => lng('Oops! Try again') ); $filename = $f['file']['name']; @@ -1011,7 +1011,7 @@ function get_file_path() if (!fm_isvalid_filename($filename) && !fm_isvalid_filename($fullPathInput)) { $response = array( 'status' => 'error', - 'info' => "Invalid File name!", + 'info' => lng('Invalid File name!'), ); echo json_encode($response); exit(); @@ -1050,12 +1050,12 @@ function get_file_path() } $response = array( 'status' => 'success', - 'info' => "file upload successful" + 'info' => lng('File upload successful') ); } else { $response = array( 'status' => 'error', - 'info' => "failed to open output stream", + 'info' => lng('Failed to open output stream'), 'errorDetails' => error_get_last() ); } @@ -1065,12 +1065,12 @@ function get_file_path() $response = array( 'status' => 'success', - 'info' => "file upload successful" + 'info' => lng('File upload successful') ); } else { $response = array( 'status' => 'error', - 'info' => "failed to open output stream" + 'info' => lng('Failed to open output stream') ); } @@ -1088,25 +1088,25 @@ function get_file_path() if (file_exists($fullPath)) { $response = array( 'status' => 'success', - 'info' => "file upload successful" + 'info' => lng('File upload successful') ); } else { $response = array( 'status' => 'error', - 'info' => 'Couldn\'t upload the requested file.' + 'info' => lng("Couldn't upload the requested file.") ); } } else { $response = array( 'status' => 'error', - 'info' => "Error while uploading files. Uploaded files $uploads", + 'info' => sprintf(lng('Error while uploading files. Uploaded files: %s'), $uploads), ); } } } else { $response = array( 'status' => 'error', - 'info' => 'The specified folder for upload isn\'t writeable.' + 'info' => lng("The specified folder for upload isn't writable.") ); } // Return the response @@ -1119,7 +1119,7 @@ function get_file_path() if (!verifyToken($_POST['token'])) { fm_set_msg(lng("Invalid Token."), 'error'); - die("Invalid Token."); + die(lng('Invalid Token.')); } $path = FM_ROOT_PATH; @@ -1156,7 +1156,7 @@ function get_file_path() if (!verifyToken($_POST['token'])) { fm_set_msg(lng("Invalid Token."), 'error'); - die("Invalid Token."); + die(lng('Invalid Token.')); } $path = FM_ROOT_PATH; @@ -1204,7 +1204,7 @@ function get_file_path() } if ($res) { - fm_set_msg(sprintf(lng('Archive') . ' %s ' . lng('Created'), fm_enc($zipname))); + fm_set_msg(sprintf(lng('Archive created'), '' . fm_enc($zipname) . '')); } else { fm_set_msg(lng('Archive not created'), 'error'); } @@ -1221,7 +1221,7 @@ function get_file_path() if (!verifyToken($_POST['token'])) { fm_set_msg(lng("Invalid Token."), 'error'); - die("Invalid Token."); + die(lng('Invalid Token.')); } $unzip = urldecode($_POST['unzip']); @@ -1292,7 +1292,7 @@ function get_file_path() if (!verifyToken($_POST['token'])) { fm_set_msg(lng("Invalid Token."), 'error'); - die("Invalid Token."); + die(lng('Invalid Token.')); } $path = FM_ROOT_PATH; @@ -1473,7 +1473,7 @@ function getUploadExt() let _path = (file.fullPath) ? file.fullPath : file.name; document.getElementById("fullpath").value = _path; xhr.ontimeout = (function() { - toast('Error: Server Timeout'); + toast(); }); }).on("success", function(res) { try { @@ -1483,7 +1483,7 @@ function getUploadExt() toast(_response.info); } } catch (e) { - toast("Error: Invalid JSON response"); + toast(); } }).on("error", function(file, response) { toast(response); @@ -1558,15 +1558,15 @@ function getUploadExt() fm_show_nav_path(FM_PATH); // current path ?>
-

Copying

+

- Source path:
- Destination folder: + :
+ :

- Copy   - Move   - Cancel +   +   +

- "> + "> - + - + - + ' . fm_get_filesize($all_files_size) . '' ?> - ' . $num_files . '' ?> - ' . $num_folders . '' ?> + ' . $num_files . '' ?> + ' . $num_folders . '' ?> @@ -2357,13 +2357,13 @@ class="edit-file"> - + - + @@ -3707,12 +3707,12 @@ function __construct() if (strlen($CONFIG)) { $data = fm_object_to_array(json_decode($CONFIG)); } else { - $msg = lng("AppName").'
Error: Cannot load configuration'; + $msg = lng('AppName') . '
' . lng('Error: Cannot load configuration'); if (substr($fm_url, -1) == '/') { $fm_url = rtrim($fm_url, '/'); $msg .= '
'; - $msg .= '
Seems like you have a trailing slash on the URL.'; - $msg .= '
Try this link: ' . $fm_url . ''; + $msg .= '
' . lng('The URL appears to end with a slash.'); + $msg .= '
' . lng('Try this link:') . ' ' . $fm_url . ''; } die($msg); } @@ -3753,7 +3753,7 @@ function fm_show_nav_path($path) ?>