From 86792012e23f2f9270f689b4873a435d5dd29841 Mon Sep 17 00:00:00 2001 From: LHY0125 <3364451258@qq.com> Date: Thu, 26 Mar 2026 22:06:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n):=20=E4=B8=BAUI=E6=B7=BB=E5=8A=A0gett?= =?UTF-8?q?ext=E5=9B=BD=E9=99=85=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将配置中的中文文本改为英文原文,作为翻译源字符串 - 在C代码中为所有UI字符串添加_()包装以启用gettext翻译 - 更新对话框、主窗口和配置文件的文本处理方式 --- lua/config.lua | 66 +++++++++++++++++++++---------------------- src/ui/dialogs.c | 4 +-- src/ui/main_window.c | 67 ++++++++++++++++++++++++-------------------- 3 files changed, 72 insertions(+), 65 deletions(-) diff --git a/lua/config.lua b/lua/config.lua index 220b149..41c4d3f 100644 --- a/lua/config.lua +++ b/lua/config.lua @@ -5,14 +5,14 @@ local config = { -- 应用程序信息 app = { name = "PathEditor", - name_readonly = "PathEditor (只读模式)" + name_readonly = "PathEditor (Read-only)" }, -- 对话框设置 dialog = { size = "800x800", minsize = "800x800", - select_dir = "选择目录" + select_dir = "Select Directory" }, -- 列表控件设置 @@ -21,31 +21,31 @@ local config = { backcolor = "255 255 255" }, - -- 按钮设置 + -- 按钮设置(使用英文原文,供 gettext 翻译) button = { rastersize = "100x32", - new = "新建(N)", - edit = "编辑(E)", - browse = "浏览(B)...", - del = "删除(D)", - up = "上移(U)", - down = "下移(O)", - clean = "一键清理", - import = "导入(I)", - export = "导出(E)", - ok = "确定", - cancel = "取消", - help = "帮助(?)" + new = "New", + edit = "Edit", + browse = "Browse", + del = "Delete", + up = "Move Up", + down = "Move Down", + clean = "Clean Invalid", + import = "Import", + export = "Export", + ok = "OK", + cancel = "Cancel", + help = "Help" }, - -- 标签文本 + -- 标签文本(使用英文原文,供 gettext 翻译) label = { - title = "环境变量编辑器:", - search_placeholder = "输入关键词搜索...", - tab_sys = "系统变量 (System)", - tab_user = "用户变量 (User)", - export_title = "导出 PATH", - import_title = "导入 PATH" + title = "Environment Variable Editor:", + search_placeholder = "Search...", + tab_sys = "System Variables", + tab_user = "User Variables", + export_title = "Export PATH", + import_title = "Import PATH" }, -- 布局设置 @@ -59,24 +59,24 @@ local config = { hbox_alignment = "ACENTER" }, - -- 状态栏 + -- 状态栏(使用英文原文,供 gettext 翻译) status = { - normal = "状态: 就绪", - readonly = "状态: ⚠️ 只读模式 (无管理员权限)", - saving = "状态: 保存中...", - saved = "状态: ✓ 保存成功", - error = "状态: ✗ 保存失败", - deleted = "状态: 已删除选中项", - loaded = "状态: 已加载系统和用户变量", - drag_folder_only = "提示: 只能拖拽文件夹添加到 PATH", - admin_warning = "未检测到管理员权限,只能查看和导出 PATH,无法保存更改。" + normal = "Status: Ready", + readonly = "Status: Read-only (No admin)", + saving = "Status: Saving...", + saved = "Status: Saved", + error = "Status: Error", + deleted = "Status: Deleted", + loaded = "Status: Loaded", + drag_folder_only = "Tip: Only folders can be added to PATH", + admin_warning = "No admin rights. You can only view and export PATH." }, -- 语言选择对话框 language = { dialog_title = "Language", label = "Language", - option_cn = "中文 (简体中文)", + option_cn = "Chinese (Simplified)", option_en = "English", dialog_size = "250x150", list_size = "200x", diff --git a/src/ui/dialogs.c b/src/ui/dialogs.c index 7fb8aa2..cca2d3c 100644 --- a/src/ui/dialogs.c +++ b/src/ui/dialogs.c @@ -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, "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); 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); IupSetAttribute(btn_cancel, "RASTERSIZE", lua_config_get_string("button", "rastersize")); diff --git a/src/ui/main_window.c b/src/ui/main_window.c index aec6a43..bc3dfb8 100644 --- a/src/ui/main_window.c +++ b/src/ui/main_window.c @@ -43,29 +43,36 @@ Ihandle *create_main_window(void) IupVbox(list_user, NULL), NULL); IupSetAttribute(tabs_main, "NAME", "TABS_MAIN"); - 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, "TABTITLE0", _(lua_config_get_string("label", "tab_sys"))); + IupSetAttribute(tabs_main, "TABTITLE1", _(lua_config_get_string("label", "tab_user"))); 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"); - 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"); - 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"); - 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"); - 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"); - 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"); - 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"); - 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"); - 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"); // 创建语言切换按钮 @@ -120,11 +127,11 @@ Ihandle *create_main_window(void) 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"); - 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"); - 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"); // 设置底部按钮回调 @@ -155,7 +162,7 @@ Ihandle *create_main_window(void) // 创建主窗口对话框 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, "MINSIZE", lua_config_get_string("dialog", "minsize")); IupSetAttribute(dlg, "MINBOX", "NO"); @@ -169,46 +176,46 @@ void refresh_main_window_ui(Ihandle *main_dlg) if (!main_dlg) 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, "TABTITLE1", lua_config_get_string("label", "tab_user")); + IupSetAttribute(main_dlg, "TABTITLE0", _(lua_config_get_string("label", "tab_sys"))); + IupSetAttribute(main_dlg, "TABTITLE1", _(lua_config_get_string("label", "tab_user"))); Ihandle *btn = IupGetDialogChild(main_dlg, "BTN_NEW"); 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"); 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"); 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"); 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"); 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"); 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"); 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"); 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"); 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"); if (btn) @@ -216,13 +223,13 @@ void refresh_main_window_ui(Ihandle *main_dlg) btn = IupGetDialogChild(main_dlg, "BTN_OK"); 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"); 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"); if (btn) - IupSetAttribute(btn, "TITLE", lua_config_get_string("button", "help")); + IupSetAttribute(btn, "TITLE", _(lua_config_get_string("button", "help"))); } \ No newline at end of file