$tsDir = "d:\aoyiduo\woterm\woterm\private\languages\ts"

$zhCNTranslations = @{}
$zhCNTranslations["MoDBRestoreSetup||SQLiteDB selection"] = "SQLite数据库选择"
$zhCNTranslations["MoLanguageView||After modifying the language, you need to restart the application to take effect."] = "修改语言后，需要重启应用才能生效。"
$zhCNTranslations["QKxCombineKeyActionDialog||+Alt"] = "+Alt"
$zhCNTranslations["QKxCombineKeyActionDialog||-Alt"] = "-Alt"
$zhCNTranslations["QKxCombineKeyActionDialog||+Ansi"] = "+Ansi"
$zhCNTranslations["QKxCombineKeyActionDialog||-Ansi"] = "-Ansi"
$zhCNTranslations["QKxCombineKeyActionDialog||+AppCuKeys"] = "+应用光标键"
$zhCNTranslations["QKxCombineKeyActionDialog||-AppCuKeys"] = "-应用光标键"
$zhCNTranslations["QKxCombineKeyActionDialog||+AppKeyPad"] = "+应用小键盘"
$zhCNTranslations["QKxCombineKeyActionDialog||-AppKeyPad"] = "-应用小键盘"
$zhCNTranslations["QKxCombineKeyActionDialog||+AppScreen"] = "+应用屏幕"
$zhCNTranslations["QKxCombineKeyActionDialog||-AppScreen"] = "-应用屏幕"
$zhCNTranslations["QKxCombineKeyActionDialog||+Ctrl"] = "+Ctrl"
$zhCNTranslations["QKxCombineKeyActionDialog||-Ctrl"] = "-Ctrl"
$zhCNTranslations["QKxCombineKeyActionDialog||+Meta"] = "+Meta"
$zhCNTranslations["QKxCombineKeyActionDialog||-Meta"] = "-Meta"
$zhCNTranslations["QKxCombineKeyActionDialog||+NewLine"] = "+新行"
$zhCNTranslations["QKxCombineKeyActionDialog||-NewLine"] = "-新行"
$zhCNTranslations["QKxCombineKeyActionDialog||None"] = "无"
$zhCNTranslations["QKxCombineKeyActionDialog||+Shift"] = "+Shift"
$zhCNTranslations["QKxCombineKeyActionDialog||-Shift"] = "-Shift"
$zhCNTranslations["QKxDockGuider||Drop here"] = "拖放到此处"
$zhCNTranslations["QKxDockGuider||Form"] = "表单"
$zhCNTranslations["QKxFtpFilterInput||Form"] = "表单"
$zhCNTranslations["QKxInputHistoryDialog||Current input message is empty."] = "当前输入消息为空。"
$zhCNTranslations["QKxInputHistoryDialog||Dialog"] = "对话框"
$zhCNTranslations["QKxInputHistoryDialog||Remove"] = "移除"
$zhCNTranslations["QKxItemFilterDialog||Dialog"] = "对话框"
$zhCNTranslations["QKxLoadingAnimation||Form"] = "表单"
$zhCNTranslations["QKxSearch||Border"] = "边框"
$zhCNTranslations["QKxSessionPanel||Search sessions…"] = "搜索会话…"
$zhCNTranslations["QKxSessionTreeView||Delete `"%1`" and all its contents?"] = "删除 `"%1`" 及其所有内容？"
$zhCNTranslations["QKxSessionTreeView||Delete Folder"] = "删除文件夹"
$zhCNTranslations["QKxSessionTreeView||Sessions"] = "会话"
$zhCNTranslations["QKxTermCompleter||Form"] = "表单"
$zhCNTranslations["QKxTermScriptReplayer||Form"] = "表单"
$zhCNTranslations["QWoAboutDialog||OfficeWeb"] = "官网"
$zhCNTranslations["QWoBaseToolForm||Form"] = "表单"
$zhCNTranslations["QWoBindPortPermissionDialog||sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0"] = "sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0"
$zhCNTranslations["QWoDbBackupDialog||backup success."] = "备份成功。"
$zhCNTranslations["QWoDbBackupDialog||Input a file path to backup."] = "请输入备份文件路径。"
$zhCNTranslations["QWoDbPowerBackupDialog||sftp server"] = "sftp服务器"
$zhCNTranslations["QWoDBServerMergeModel||path"] = "路径"
$zhCNTranslations["QWoDBSftpDownListDialog||Backup file list"] = "备份文件列表"
$zhCNTranslations["QWoEditorWindow||Ctrl+E"] = "Ctrl+E"
$zhCNTranslations["QWoEditorWindow||Ctrl+S"] = "Ctrl+S"
$zhCNTranslations["QWoFtpAuthorizeInput||Explicit SSL/TLS"] = "显式SSL/TLS"
$zhCNTranslations["QWoFtpAuthorizeInput||Form"] = "表单"
$zhCNTranslations["QWoFtpAuthorizeInput||Implicit SSL/TLS"] = "隐式SSL/TLS"
$zhCNTranslations["QWoFtpAuthorizeInput||No SSL/TLS"] = "无SSL/TLS"
$zhCNTranslations["QWoFtpTransferWidget||Breakpoint resume is an exclusive feature of the professional version"] = "断点续传是专业版专属功能"
$zhCNTranslations["QWoFtpWidget||Failed to open file:"] = "无法打开文件："
$zhCNTranslations["QWoFtpWidget||Form"] = "表单"
$zhCNTranslations["QWoFtpWidget||FTP"] = "FTP"
$zhCNTranslations["QWoHistoryWidget||Form"] = "表单"
$zhCNTranslations["QWoHostSimpleList||Dialog"] = "对话框"
$zhCNTranslations["QWoHostSimpleList||Ok"] = "确定"
$zhCNTranslations["QWoIdentifyDialog||ssh-agent"] = "ssh-agent"
$zhCNTranslations["QWoInternetAccessDetectionDialog||Dialog"] = "对话框"
$zhCNTranslations["QWoInternetAccessDetectionDialog||Ok"] = "确定"
$zhCNTranslations["QWoLockWidget||Form"] = "表单"
$zhCNTranslations["QWoMainWindow||Alt+L"] = "Alt+L"
$zhCNTranslations["QWoMainWindow||Alt+O"] = "Alt+O"
$zhCNTranslations["QWoMainWindow||d"] = "d"
$zhCNTranslations["QWoMainWindow||Plugin"] = "插件"
$zhCNTranslations["QWoMenuButton||PushButton"] = "按钮"
$zhCNTranslations["QWoPluginManageDialog||Are you sure to remove plugin '%1'?"] = "确定要移除插件 '%1' 吗？"
$zhCNTranslations["QWoPluginManageDialog||Author"] = "作者"
$zhCNTranslations["QWoPluginManageDialog||Confirm Remove"] = "确认移除"
$zhCNTranslations["QWoPluginManageDialog||Copy Plugin"] = "复制插件"
$zhCNTranslations["QWoPluginManageDialog||Description"] = "描述"
$zhCNTranslations["QWoPluginManageDialog||Dialog"] = "对话框"
$zhCNTranslations["QWoPluginManageDialog||Disable"] = "禁用"
$zhCNTranslations["QWoPluginManageDialog||Disabled"] = "已禁用"
$zhCNTranslations["QWoPluginManageDialog||Edit"] = "编辑"
$zhCNTranslations["QWoPluginManageDialog||Enable"] = "启用"
$zhCNTranslations["QWoPluginManageDialog||Enabled"] = "已启用"
$zhCNTranslations["QWoPluginManageDialog||Enter new plugin name:"] = "输入新插件名称："
$zhCNTranslations["QWoPluginManageDialog||Enter plugin name:"] = "输入插件名称："
$zhCNTranslations["QWoPluginManageDialog||Import Plugin"] = "导入插件"
$zhCNTranslations["QWoPluginManageDialog||Name"] = "名称"
$zhCNTranslations["QWoPluginManageDialog||Plugin files (*.dll)"] = "插件文件 (*.dll)"
$zhCNTranslations["QWoPluginManageDialog||Plugin Manager"] = "插件管理器"
$zhCNTranslations["QWoPluginManageDialog||Plugin Name"] = "插件名称"
$zhCNTranslations["QWoPluginManageDialog||Remove"] = "移除"
$zhCNTranslations["QWoPluginManageDialog||Version"] = "版本"
$zhCNTranslations["QWoPluginSessionAdapter||failed to upate information"] = "更新信息失败"
$zhCNTranslations["QWoSerialInput||Form"] = "表单"
$zhCNTranslations["QWoSessionFileAssociationAddDialog||.tar.gz, .ini, .sh, .log, .conf, .db, *"] = ".tar.gz, .ini, .sh, .log, .conf, .db, *"
$zhCNTranslations["QWoSessionFileAssociationAddDialog||{file}"] = "{file}"
$zhCNTranslations["QWoSessionFileAssociationAddDialog||Example: c:\Windows\notepad.exe {file}"] = "示例：c:\Windows\notepad.exe {file}"
$zhCNTranslations["QWoSessionFTPProperty|| (EPSV)"] = " (EPSV)"
$zhCNTranslations["QWoSessionInternalTreeView||Add folder"] = "添加文件夹"
$zhCNTranslations["QWoSessionInternalTreeView||Add session"] = "添加会话"
$zhCNTranslations["QWoSessionInternalTreeView||Continue to delete the selected items?"] = "是否继续删除选中的项目？"
$zhCNTranslations["QWoSessionInternalTreeView||Deletion confirmation"] = "删除确认"
$zhCNTranslations["QWoSessionInternalTreeView||Folder name:"] = "文件夹名称："
$zhCNTranslations["QWoSessionInternalTreeView||Memo"] = "备忘"
$zhCNTranslations["QWoSessionInternalTreeView||Name"] = "名称"
$zhCNTranslations["QWoSessionInternalTreeView||New folder"] = "新建文件夹"
$zhCNTranslations["QWoSessionInternalWidget||Enter keyword to search"] = "输入关键字搜索"
$zhCNTranslations["QWoSessionInternalWidget||Form"] = "表单"
$zhCNTranslations["QWoSessionInternalWidget||login name"] = "登录名"
$zhCNTranslations["QWoSessionInternalWidget||memo"] = "备忘"
$zhCNTranslations["QWoSessionManage||Confirmation"] = "确认"
$zhCNTranslations["QWoSessionManage||New folder"] = "新建文件夹"
$zhCNTranslations["QWoSessionManage||New session"] = "新建会话"
$zhCNTranslations["QWoSessionManage||No selected items to open"] = "没有选中的项目可打开"
$zhCNTranslations["QWoSessionPluginTreeView||Continue to delete the selected items?"] = "是否继续删除选中的项目？"
$zhCNTranslations["QWoSessionPluginTreeView||Deletion confirmation"] = "删除确认"
$zhCNTranslations["QWoSessionPluginTreeView||Folder name:"] = "文件夹名称："
$zhCNTranslations["QWoSessionPluginTreeView||Memo"] = "备忘"
$zhCNTranslations["QWoSessionPluginTreeView||Name"] = "名称"
$zhCNTranslations["QWoSessionPluginTreeView||New folder"] = "新建文件夹"
$zhCNTranslations["QWoSessionPluginWidget||Enter keyword to search"] = "输入关键字搜索"
$zhCNTranslations["QWoSessionPluginWidget||Form"] = "表单"
$zhCNTranslations["QWoSessionPluginWidget||login name"] = "登录名"
$zhCNTranslations["QWoSessionPluginWidget||memo"] = "备忘"
$zhCNTranslations["QWoSessionProperty||Explicit SSL/TLS"] = "显式SSL/TLS"
$zhCNTranslations["QWoSessionProperty||Implicit SSL/TLS"] = "隐式SSL/TLS"
$zhCNTranslations["QWoSessionProperty||No SSL/TLS"] = "无SSL/TLS"
$zhCNTranslations["QWoSessionProperty||The name can't contain characters like (/)"] = "名称不能包含 (/) 等字符"
$zhCNTranslations["QWoSessionRDPProperty||FreeRdp"] = "FreeRdp"
$zhCNTranslations["QWoSessionRDPProperty||Mstsc"] = "Mstsc"
$zhCNTranslations["QWoSessionToolConfigureDialog||`"{file}`""] = "`"{file}`""
$zhCNTranslations["QWoSessionToolConfigureDialog||Example: c:\Windows\notepad.exe `"{file}`""] = "示例：c:\Windows\notepad.exe `"{file}`""
$zhCNTranslations["QWoSessionToolConfigureDialog||Tab 2"] = "标签 2"
$zhCNTranslations["QWoSessionTTYProperty||[DISPLAY=:0]"] = "[DISPLAY=:0]"
$zhCNTranslations["QWoSessionTTYProperty||localhost:0.0"] = "localhost:0.0"
$zhCNTranslations["QWoSftpTaskRunner||Form"] = "表单"
$zhCNTranslations["QWoSftpTaskRunner||Mb/s"] = "兆字节/秒"
$zhCNTranslations["QWoSftpWidget||Chmod"] = "权限"
$zhCNTranslations["QWoSSHAuthorizeInput||Form"] = "表单"
$zhCNTranslations["QWoSSHAuthorizeInput||tr"] = "tr"
$zhCNTranslations["QWoSSHChartWidget||CPU"] = "CPU"
$zhCNTranslations["QWoSSHChartWidget||Form"] = "表单"
$zhCNTranslations["QWoSshMonitorWidget||Form"] = "表单"
$zhCNTranslations["QWoSSHProcessModel||CPU"] = "CPU"
$zhCNTranslations["QWoSshTermWidget||Choose a way to accept the file."] = "选择一种接受文件的方式。"
$zhCNTranslations["QWoSshTermWidget||Paste text"] = "粘贴文本"
$zhCNTranslations["QWoSystemOptionDialog||Ctrl+Shift+Tab"] = "Ctrl+Shift+Tab"
$zhCNTranslations["QWoSystemOptionDialog||Ctrl+Tab"] = "Ctrl+Tab"
$zhCNTranslations["QWoTelnetTermWidgetImpl||%1:%2"] = "%1:%2"
$zhCNTranslations["QWoTermMask||Form"] = "表单"
$zhCNTranslations["QWoTermWidget||Failed to create file."] = "创建文件失败。"
$zhCNTranslations["QWoTermWidget||log (*.log)"] = "日志 (*.log)"
$zhCNTranslations["QWoTermWidget||Save history to file"] = "保存历史到文件"
$zhCNTranslations["QWoTunnelAddDialog||HTTP/SOCKS4/SOCKS5 over SSH"] = "通过SSH的HTTP/SOCKS4/SOCKS5"
$zhCNTranslations["QWoTunnelAddDialog||Plain HTTP/SOCKS4/SOCKS5"] = "普通HTTP/SOCKS4/SOCKS5"
$zhCNTranslations["QWoTunnelAddDialog||Port Forward over SSH"] = "SSH端口转发"
$zhCNTranslations["QWoTunnelDialog||["] = "["
$zhCNTranslations["QWoTunnelDialog||]"] = "]"
$zhCNTranslations["QWoTunnelDialog||No system proxy"] = "无系统代理"
$zhCNTranslations["QWoTunnelHelpDialog||Dialog"] = "对话框"
$zhCNTranslations["QWoTunnelHelpDialog||OK"] = "确定"
$zhCNTranslations["QWoUserLoginDialog||Email:"] = "邮箱："
$zhCNTranslations["QWoUserLoginDialog||PushButton"] = "按钮"
$zhCNTranslations["QWoVncPlayWidget||Form"] = "表单"
$zhCNTranslations["QWoVncToolForm||Form"] = "表单"
$zhCNTranslations["WtPluginParamsDialog||Edit Plugin: %1"] = "编辑插件：%1"
$zhCNTranslations["WtPluginParamsDialog||Failed to get parameter template"] = "获取参数模板失败"
$zhCNTranslations["WtPluginParamsDialog||Failed to load plugin library:`n%1"] = "加载插件库失败：`n%1"
$zhCNTranslations["WtPluginParamsDialog||Internal plugin path cannot be modified"] = "内部插件路径不可修改"
$zhCNTranslations["WtPluginParamsDialog||Invalid JSON format: %1"] = "无效的JSON格式：%1"
$zhCNTranslations["WtPluginParamsDialog||Invalid template JSON format: %1"] = "无效的模板JSON格式：%1"
$zhCNTranslations["WtPluginParamsDialog||Load Template"] = "加载模板"
$zhCNTranslations["WtPluginParamsDialog||Loading template will overwrite current parameters. Continue?"] = "加载模板将覆盖当前参数，是否继续？"
$zhCNTranslations["WtPluginParamsDialog||Name:"] = "名称："
$zhCNTranslations["WtPluginParamsDialog||Parameters (JSON):"] = "参数 (JSON)："
$zhCNTranslations["WtPluginParamsDialog||Parameters must be a JSON object"] = "参数必须是JSON对象"
$zhCNTranslations["WtPluginParamsDialog||Path:"] = "路径："
$zhCNTranslations["WtPluginParamsDialog||Plugin does not support parameter template"] = "插件不支持参数模板"
$zhCNTranslations["WtPluginParamsDialog||Plugin name cannot be empty"] = "插件名称不能为空"

Write-Host "Processing zh_CN..." -ForegroundColor Yellow

$filePath = Join-Path $tsDir "woterm_zh_CN.ts.xml"
$xml = New-Object System.Xml.XmlDocument
$xml.Load($filePath)
$updated = 0

foreach ($ctx in $xml.TS.context) {
    $ctxName = $ctx.name
    foreach ($msg in $ctx.message) {
        $src = $msg.source
        $key = "$ctxName||$src"
        
        $transNode = $msg.translation
        $hasTranslation = $false
        if ($transNode -and $transNode.InnerText -and $transNode.InnerText -ne "") {
            $hasTranslation = $true
        }
        
        if (-not $hasTranslation -and $zhCNTranslations.ContainsKey($key)) {
            $newValue = $zhCNTranslations[$key]
            $transNode.InnerText = $newValue
            if ($transNode.type -eq "unfinished") {
                $transNode.RemoveAttribute("type")
            }
            $updated++
        }
    }
}

if ($updated -gt 0) {
    $xml.Save($filePath)
    Write-Host "Updated $updated translations for zh_CN" -ForegroundColor Green
} else {
    Write-Host "No updates needed for zh_CN" -ForegroundColor Gray
}

Write-Host "Done!" -ForegroundColor Cyan
