feat(i18n): 为UI添加gettext国际化支持

- 将配置中的中文文本改为英文原文,作为翻译源字符串
- 在C代码中为所有UI字符串添加_()包装以启用gettext翻译
- 更新对话框、主窗口和配置文件的文本处理方式
This commit is contained in:
2026-03-26 22:06:05 +08:00
parent 4fe7dc47e4
commit 86792012e2
3 changed files with 72 additions and 65 deletions
+33 -33
View File
@@ -5,14 +5,14 @@ local config = {
-- 应用程序信息 -- 应用程序信息
app = { app = {
name = "PathEditor", name = "PathEditor",
name_readonly = "PathEditor (只读模式)" name_readonly = "PathEditor (Read-only)"
}, },
-- 对话框设置 -- 对话框设置
dialog = { dialog = {
size = "800x800", size = "800x800",
minsize = "800x800", minsize = "800x800",
select_dir = "选择目录" select_dir = "Select Directory"
}, },
-- 列表控件设置 -- 列表控件设置
@@ -21,31 +21,31 @@ local config = {
backcolor = "255 255 255" backcolor = "255 255 255"
}, },
-- 按钮设置 -- 按钮设置(使用英文原文,供 gettext 翻译)
button = { button = {
rastersize = "100x32", rastersize = "100x32",
new = "新建(N)", new = "New",
edit = "编辑(E)", edit = "Edit",
browse = "浏览(B)...", browse = "Browse",
del = "删除(D)", del = "Delete",
up = "上移(U)", up = "Move Up",
down = "下移(O)", down = "Move Down",
clean = "一键清理", clean = "Clean Invalid",
import = "导入(I)", import = "Import",
export = "导出(E)", export = "Export",
ok = "确定", ok = "OK",
cancel = "取消", cancel = "Cancel",
help = "帮助(?)" help = "Help"
}, },
-- 标签文本 -- 标签文本(使用英文原文,供 gettext 翻译)
label = { label = {
title = "环境变量编辑器:", title = "Environment Variable Editor:",
search_placeholder = "输入关键词搜索...", search_placeholder = "Search...",
tab_sys = "系统变量 (System)", tab_sys = "System Variables",
tab_user = "用户变量 (User)", tab_user = "User Variables",
export_title = "导出 PATH", export_title = "Export PATH",
import_title = "导入 PATH" import_title = "Import PATH"
}, },
-- 布局设置 -- 布局设置
@@ -59,24 +59,24 @@ local config = {
hbox_alignment = "ACENTER" hbox_alignment = "ACENTER"
}, },
-- 状态栏 -- 状态栏(使用英文原文,供 gettext 翻译)
status = { status = {
normal = "状态: 就绪", normal = "Status: Ready",
readonly = "状态: ⚠️ 只读模式 (无管理员权限)", readonly = "Status: Read-only (No admin)",
saving = "状态: 保存中...", saving = "Status: Saving...",
saved = "状态: ✓ 保存成功", saved = "Status: Saved",
error = "状态: ✗ 保存失败", error = "Status: Error",
deleted = "状态: 已删除选中项", deleted = "Status: Deleted",
loaded = "状态: 已加载系统和用户变量", loaded = "Status: Loaded",
drag_folder_only = "提示: 只能拖拽文件夹添加到 PATH", drag_folder_only = "Tip: Only folders can be added to PATH",
admin_warning = "未检测到管理员权限,只能查看和导出 PATH,无法保存更改。" admin_warning = "No admin rights. You can only view and export PATH."
}, },
-- 语言选择对话框 -- 语言选择对话框
language = { language = {
dialog_title = "Language", dialog_title = "Language",
label = "Language", label = "Language",
option_cn = "中文 (简体中文)", option_cn = "Chinese (Simplified)",
option_en = "English", option_en = "English",
dialog_size = "250x150", dialog_size = "250x150",
list_size = "200x", list_size = "200x",
+2 -2
View File
@@ -30,11 +30,11 @@ int custom_input_dialog(const char *title, const char *label_text, char *buffer,
IupSetAttribute(text, "RASTERSIZE", lua_config_get_string("input_dialog", "text_size")); IupSetAttribute(text, "RASTERSIZE", lua_config_get_string("input_dialog", "text_size"));
IupSetAttribute(text, "NAME", "INPUT_TEXT"); IupSetAttribute(text, "NAME", "INPUT_TEXT");
Ihandle *btn_ok = IupButton(lua_config_get_string("button", "ok"), NULL); Ihandle *btn_ok = IupButton(_(lua_config_get_string("button", "ok")), NULL);
IupSetCallback(btn_ok, "ACTION", on_dialog_ok); IupSetCallback(btn_ok, "ACTION", on_dialog_ok);
IupSetAttribute(btn_ok, "RASTERSIZE", lua_config_get_string("button", "rastersize")); IupSetAttribute(btn_ok, "RASTERSIZE", lua_config_get_string("button", "rastersize"));
Ihandle *btn_cancel = IupButton(lua_config_get_string("button", "cancel"), NULL); Ihandle *btn_cancel = IupButton(_(lua_config_get_string("button", "cancel")), NULL);
IupSetCallback(btn_cancel, "ACTION", on_dialog_cancel); IupSetCallback(btn_cancel, "ACTION", on_dialog_cancel);
IupSetAttribute(btn_cancel, "RASTERSIZE", lua_config_get_string("button", "rastersize")); IupSetAttribute(btn_cancel, "RASTERSIZE", lua_config_get_string("button", "rastersize"));
+37 -30
View File
@@ -43,29 +43,36 @@ Ihandle *create_main_window(void)
IupVbox(list_user, NULL), IupVbox(list_user, NULL),
NULL); NULL);
IupSetAttribute(tabs_main, "NAME", "TABS_MAIN"); IupSetAttribute(tabs_main, "NAME", "TABS_MAIN");
IupSetAttribute(tabs_main, "TABTITLE0", lua_config_get_string("label", "tab_sys")); IupSetAttribute(tabs_main, "TABTITLE0", _(lua_config_get_string("label", "tab_sys")));
IupSetAttribute(tabs_main, "TABTITLE1", lua_config_get_string("label", "tab_user")); IupSetAttribute(tabs_main, "TABTITLE1", _(lua_config_get_string("label", "tab_user")));
IupSetAttribute(tabs_main, "TABTYPE", "TOP"); IupSetAttribute(tabs_main, "TABTYPE", "TOP");
// 创建操作按钮 // 创建操作按钮
Ihandle *btn_new = IupButton(lua_config_get_string("button", "new"), NULL); Ihandle *btn_new = IupButton(_(lua_config_get_string("button", "new")), NULL);
IupSetAttribute(btn_new, "NAME", "BTN_NEW"); IupSetAttribute(btn_new, "NAME", "BTN_NEW");
Ihandle *btn_edit = IupButton(lua_config_get_string("button", "edit"), NULL);
Ihandle *btn_edit = IupButton(_(lua_config_get_string("button", "edit")), NULL);
IupSetAttribute(btn_edit, "NAME", "BTN_EDIT"); IupSetAttribute(btn_edit, "NAME", "BTN_EDIT");
Ihandle *btn_browse = IupButton(lua_config_get_string("button", "browse"), NULL);
Ihandle *btn_browse = IupButton(_(lua_config_get_string("button", "browse")), NULL);
IupSetAttribute(btn_browse, "NAME", "BTN_BROWSE"); IupSetAttribute(btn_browse, "NAME", "BTN_BROWSE");
Ihandle *btn_del = IupButton(lua_config_get_string("button", "del"), NULL);
Ihandle *btn_del = IupButton(_(lua_config_get_string("button", "del")), NULL);
IupSetAttribute(btn_del, "NAME", "BTN_DEL"); IupSetAttribute(btn_del, "NAME", "BTN_DEL");
Ihandle *btn_up = IupButton(lua_config_get_string("button", "up"), NULL);
Ihandle *btn_up = IupButton(_(lua_config_get_string("button", "up")), NULL);
IupSetAttribute(btn_up, "NAME", "BTN_UP"); IupSetAttribute(btn_up, "NAME", "BTN_UP");
Ihandle *btn_down = IupButton(lua_config_get_string("button", "down"), NULL);
Ihandle *btn_down = IupButton(_(lua_config_get_string("button", "down")), NULL);
IupSetAttribute(btn_down, "NAME", "BTN_DOWN"); IupSetAttribute(btn_down, "NAME", "BTN_DOWN");
Ihandle *btn_clean = IupButton(lua_config_get_string("button", "clean"), NULL);
Ihandle *btn_clean = IupButton(_(lua_config_get_string("button", "clean")), NULL);
IupSetAttribute(btn_clean, "NAME", "BTN_CLEAN"); IupSetAttribute(btn_clean, "NAME", "BTN_CLEAN");
Ihandle *btn_import = IupButton(lua_config_get_string("button", "import"), NULL); Ihandle *btn_import = IupButton(_(lua_config_get_string("button", "import")), NULL);
IupSetAttribute(btn_import, "NAME", "BTN_IMPORT"); IupSetAttribute(btn_import, "NAME", "BTN_IMPORT");
Ihandle *btn_export = IupButton(lua_config_get_string("button", "export"), NULL);
Ihandle *btn_export = IupButton(_(lua_config_get_string("button", "export")), NULL);
IupSetAttribute(btn_export, "NAME", "BTN_EXPORT"); IupSetAttribute(btn_export, "NAME", "BTN_EXPORT");
// 创建语言切换按钮 // 创建语言切换按钮
@@ -120,11 +127,11 @@ Ihandle *create_main_window(void)
IupSetAttribute(lbl_status, "EXPAND", "HORIZONTAL"); IupSetAttribute(lbl_status, "EXPAND", "HORIZONTAL");
// 创建底部按钮 // 创建底部按钮
Ihandle *btn_ok = IupButton(lua_config_get_string("button", "ok"), NULL); Ihandle *btn_ok = IupButton(_(lua_config_get_string("button", "ok")), NULL);
IupSetAttribute(btn_ok, "NAME", "BTN_OK"); IupSetAttribute(btn_ok, "NAME", "BTN_OK");
Ihandle *btn_cancel = IupButton(lua_config_get_string("button", "cancel"), NULL); Ihandle *btn_cancel = IupButton(_(lua_config_get_string("button", "cancel")), NULL);
IupSetAttribute(btn_cancel, "NAME", "BTN_CANCEL"); IupSetAttribute(btn_cancel, "NAME", "BTN_CANCEL");
Ihandle *btn_help = IupButton(lua_config_get_string("button", "help"), NULL); Ihandle *btn_help = IupButton(_(lua_config_get_string("button", "help")), NULL);
IupSetAttribute(btn_help, "NAME", "BTN_HELP"); IupSetAttribute(btn_help, "NAME", "BTN_HELP");
// 设置底部按钮回调 // 设置底部按钮回调
@@ -155,7 +162,7 @@ Ihandle *create_main_window(void)
// 创建主窗口对话框 // 创建主窗口对话框
Ihandle *dlg = IupDialog(vbox_all); Ihandle *dlg = IupDialog(vbox_all);
IupSetAttribute(dlg, "TITLE", lua_config_get_string("app", "name")); IupSetAttribute(dlg, "TITLE", _(lua_config_get_string("app", "name")));
IupSetAttribute(dlg, "RASTERSIZE", lua_config_get_string("dialog", "size")); IupSetAttribute(dlg, "RASTERSIZE", lua_config_get_string("dialog", "size"));
IupSetAttribute(dlg, "MINSIZE", lua_config_get_string("dialog", "minsize")); IupSetAttribute(dlg, "MINSIZE", lua_config_get_string("dialog", "minsize"));
IupSetAttribute(dlg, "MINBOX", "NO"); IupSetAttribute(dlg, "MINBOX", "NO");
@@ -169,46 +176,46 @@ void refresh_main_window_ui(Ihandle *main_dlg)
if (!main_dlg) if (!main_dlg)
return; return;
IupSetAttribute(main_dlg, "TITLE", lua_config_get_string("app", "name")); IupSetAttribute(main_dlg, "TITLE", _(lua_config_get_string("app", "name")));
IupSetAttribute(main_dlg, "TABTITLE0", lua_config_get_string("label", "tab_sys")); IupSetAttribute(main_dlg, "TABTITLE0", _(lua_config_get_string("label", "tab_sys")));
IupSetAttribute(main_dlg, "TABTITLE1", lua_config_get_string("label", "tab_user")); IupSetAttribute(main_dlg, "TABTITLE1", _(lua_config_get_string("label", "tab_user")));
Ihandle *btn = IupGetDialogChild(main_dlg, "BTN_NEW"); Ihandle *btn = IupGetDialogChild(main_dlg, "BTN_NEW");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "new")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "new")));
btn = IupGetDialogChild(main_dlg, "BTN_EDIT"); btn = IupGetDialogChild(main_dlg, "BTN_EDIT");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "edit")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "edit")));
btn = IupGetDialogChild(main_dlg, "BTN_BROWSE"); btn = IupGetDialogChild(main_dlg, "BTN_BROWSE");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "browse")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "browse")));
btn = IupGetDialogChild(main_dlg, "BTN_DEL"); btn = IupGetDialogChild(main_dlg, "BTN_DEL");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "del")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "del")));
btn = IupGetDialogChild(main_dlg, "BTN_UP"); btn = IupGetDialogChild(main_dlg, "BTN_UP");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "up")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "up")));
btn = IupGetDialogChild(main_dlg, "BTN_DOWN"); btn = IupGetDialogChild(main_dlg, "BTN_DOWN");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "down")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "down")));
btn = IupGetDialogChild(main_dlg, "BTN_CLEAN"); btn = IupGetDialogChild(main_dlg, "BTN_CLEAN");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "clean")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "clean")));
btn = IupGetDialogChild(main_dlg, "BTN_IMPORT"); btn = IupGetDialogChild(main_dlg, "BTN_IMPORT");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "import")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "import")));
btn = IupGetDialogChild(main_dlg, "BTN_EXPORT"); btn = IupGetDialogChild(main_dlg, "BTN_EXPORT");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "export")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "export")));
btn = IupGetDialogChild(main_dlg, "BTN_LANG"); btn = IupGetDialogChild(main_dlg, "BTN_LANG");
if (btn) if (btn)
@@ -216,13 +223,13 @@ void refresh_main_window_ui(Ihandle *main_dlg)
btn = IupGetDialogChild(main_dlg, "BTN_OK"); btn = IupGetDialogChild(main_dlg, "BTN_OK");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "ok")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "ok")));
btn = IupGetDialogChild(main_dlg, "BTN_CANCEL"); btn = IupGetDialogChild(main_dlg, "BTN_CANCEL");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "cancel")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "cancel")));
btn = IupGetDialogChild(main_dlg, "BTN_HELP"); btn = IupGetDialogChild(main_dlg, "BTN_HELP");
if (btn) if (btn)
IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "help")); IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "help")));
} }