Translate Chinese comments to English in File Manager components

- Complete translation of FileWindow.tsx comments and hardcoded text
- Complete translation of DraggableWindow.tsx hardcoded text
- Complete translation of FileManagerSidebar.tsx comments
- Complete translation of FileManagerGrid.tsx comments and UI text
- Complete translation of DiffViewer.tsx hardcoded text with proper i18n
- Partial translation of FileManagerModern.tsx comments (major sections done)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ZacharyZcR
2025-09-22 02:07:08 +08:00
parent 03e876dae9
commit d693dc5a14
10 changed files with 363 additions and 353 deletions

View File

@@ -43,7 +43,7 @@ interface FileWindowProps {
sshHost: SSHHost;
initialX?: number;
initialY?: number;
// readOnly参数已移除由FileViewer内部根据文件类型决定
// readOnly parameter removed, determined internally by FileViewer based on file type
}
export function FileWindow({
@@ -71,17 +71,17 @@ export function FileWindow({
const currentWindow = windows.find((w) => w.id === windowId);
// 确保SSH连接有效
// Ensure SSH connection is valid
const ensureSSHConnection = async () => {
try {
// 首先检查SSH连接状态
// First check SSH connection status
const status = await getSSHStatus(sshSessionId);
console.log("SSH connection status:", status);
if (!status.connected) {
console.log("SSH not connected, attempting to reconnect...");
// 重新建立连接
// Re-establish connection
await connectSSH(sshSessionId, {
hostId: sshHost.id,
ip: sshHost.ip,
@@ -99,12 +99,12 @@ export function FileWindow({
}
} catch (error) {
console.log("SSH connection check/reconnect failed:", error);
// 即使连接失败也尝试继续让具体的API调用报错
// Even if connection fails, try to continue and let specific API calls handle errors
throw error;
}
};
// 加载文件内容
// Load file content
useEffect(() => {
const loadFileContent = async () => {
if (file.type !== "file") return;
@@ -112,23 +112,23 @@ export function FileWindow({
try {
setIsLoading(true);
// 确保SSH连接有效
// Ensure SSH connection is valid
await ensureSSHConnection();
const response = await readSSHFile(sshSessionId, file.path);
const fileContent = response.content || "";
setContent(fileContent);
setPendingContent(fileContent); // 初始化待保存内容
setPendingContent(fileContent); // Initialize pending content
// 如果文件大小未知,根据内容计算大小
// If file size is unknown, calculate size based on content
if (!file.size) {
const contentSize = new Blob([fileContent]).size;
file.size = contentSize;
}
// 根据文件类型决定是否可编辑:除了媒体文件,其他都可编辑
// Determine if editable based on file type: all except media files are editable
const mediaExtensions = [
// 图片文件
// Image files
"jpg",
"jpeg",
"png",
@@ -138,7 +138,7 @@ export function FileWindow({
"webp",
"tiff",
"ico",
// 音频文件
// Audio files
"mp3",
"wav",
"ogg",
@@ -146,7 +146,7 @@ export function FileWindow({
"flac",
"m4a",
"wma",
// 视频文件
// Video files
"mp4",
"avi",
"mov",
@@ -155,7 +155,7 @@ export function FileWindow({
"mkv",
"webm",
"m4v",
// 压缩文件
// Archive files
"zip",
"rar",
"7z",
@@ -163,7 +163,7 @@ export function FileWindow({
"gz",
"bz2",
"xz",
// 二进制文件
// Binary files
"exe",
"dll",
"so",
@@ -173,12 +173,12 @@ export function FileWindow({
];
const extension = file.name.split(".").pop()?.toLowerCase();
// 只有媒体文件和二进制文件不可编辑,其他所有文件都可编辑
// Only media files and binary files are not editable, all other files are editable
setIsEditable(!mediaExtensions.includes(extension || ""));
} catch (error: any) {
console.error("Failed to load file:", error);
// 检查是否是大文件错误
// Check if it's a large file error
const errorData = error?.response?.data;
if (errorData?.tooLarge) {
toast.error(`File too large: ${errorData.error}`, {
@@ -188,7 +188,7 @@ export function FileWindow({
error.message?.includes("connection") ||
error.message?.includes("established")
) {
// 如果是连接错误,提供更明确的错误信息
// If connection error, provide more specific error message
toast.error(
`SSH connection failed. Please check your connection to ${sshHost.name} (${sshHost.ip}:${sshHost.port})`,
);
@@ -205,19 +205,19 @@ export function FileWindow({
loadFileContent();
}, [file, sshSessionId, sshHost]);
// 保存文件
// Save file
const handleSave = async (newContent: string) => {
try {
setIsLoading(true);
// 确保SSH连接有效
// Ensure SSH connection is valid
await ensureSSHConnection();
await writeSSHFile(sshSessionId, file.path, newContent);
setContent(newContent);
setPendingContent(""); // 清除待保存内容
setPendingContent(""); // Clear pending content
// 清除自动保存定时器
// Clear auto-save timer
if (autoSaveTimerRef.current) {
clearTimeout(autoSaveTimerRef.current);
autoSaveTimerRef.current = null;
@@ -227,7 +227,7 @@ export function FileWindow({
} catch (error: any) {
console.error("Failed to save file:", error);
// 如果是连接错误,提供更明确的错误信息
// If it's a connection error, provide more specific error message
if (
error.message?.includes("connection") ||
error.message?.includes("established")
@@ -243,16 +243,16 @@ export function FileWindow({
}
};
// 处理内容变更 - 设置1分钟自动保存
// Handle content changes - set 1-minute auto-save
const handleContentChange = (newContent: string) => {
setPendingContent(newContent);
// 清除之前的定时器
// Clear previous timer
if (autoSaveTimerRef.current) {
clearTimeout(autoSaveTimerRef.current);
}
// 设置新的1分钟自动保存定时器
// Set new 1-minute auto-save timer
autoSaveTimerRef.current = setTimeout(async () => {
try {
console.log("Auto-saving file...");
@@ -262,10 +262,10 @@ export function FileWindow({
console.error("Auto-save failed:", error);
toast.error(t("fileManager.autoSaveFailed"));
}
}, 60000); // 1分钟 = 60000毫秒
}, 60000); // 1 minute = 60000 milliseconds
};
// 清理定时器
// Cleanup timer
useEffect(() => {
return () => {
if (autoSaveTimerRef.current) {
@@ -274,10 +274,10 @@ export function FileWindow({
};
}, []);
// 下载文件
// Download file
const handleDownload = async () => {
try {
// 确保SSH连接有效
// Ensure SSH connection is valid
await ensureSSHConnection();
const response = await downloadSSHFile(sshSessionId, file.path);
@@ -308,7 +308,7 @@ export function FileWindow({
} catch (error: any) {
console.error("Failed to download file:", error);
// 如果是连接错误,提供更明确的错误信息
// If it's a connection error, provide more specific error message
if (
error.message?.includes("connection") ||
error.message?.includes("established")
@@ -324,7 +324,7 @@ export function FileWindow({
}
};
// 窗口操作处理
// Window operation handling
const handleClose = () => {
closeWindow(windowId);
};
@@ -366,7 +366,7 @@ export function FileWindow({
content={pendingContent || content}
savedContent={content}
isLoading={isLoading}
isEditable={isEditable} // 移除强制只读模式,由FileViewer内部控制
isEditable={isEditable} // Remove forced read-only mode, controlled internally by FileViewer
onContentChange={handleContentChange}
onSave={(newContent) => handleSave(newContent)}
onDownload={handleDownload}