From 6ae5eaef6485095d6a41da0f089c681076cac8b6 Mon Sep 17 00:00:00 2001 From: Hongyu Shi Date: Fri, 17 Oct 2025 18:00:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(i18n):=20=E6=B7=BB=E5=8A=A0=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=E7=BF=BB=E8=AF=91=E6=96=87=E4=BB=B6=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=92=8C=E6=89=93=E5=8C=85=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hongyu Shi --- distribution/linux/euler-copilot-shell.spec | 3 +++ ...00\345\217\221\346\214\207\345\215\227.md" | 25 +++++++++++++++++++ oi-cli.spec | 3 +++ 3 files changed, 31 insertions(+) diff --git a/distribution/linux/euler-copilot-shell.spec b/distribution/linux/euler-copilot-shell.spec index d65f525..49801d5 100644 --- a/distribution/linux/euler-copilot-shell.spec +++ b/distribution/linux/euler-copilot-shell.spec @@ -59,6 +59,9 @@ uv pip install . # 安装 PyInstaller(通过 uv 保证环境一致) uv pip install pyinstaller +# 编译国际化翻译文件 +./scripts/tools/i18n-manager.sh compile + # 使用虚拟环境中的 PyInstaller 创建单一可执行文件 pyinstaller --noconfirm \ --distpath dist \ diff --git "a/docs/development/\345\233\275\351\231\205\345\214\226\345\274\200\345\217\221\346\214\207\345\215\227.md" "b/docs/development/\345\233\275\351\231\205\345\214\226\345\274\200\345\217\221\346\214\207\345\215\227.md" index c2ca8b5..6c545f2 100644 --- "a/docs/development/\345\233\275\351\231\205\345\214\226\345\274\200\345\217\221\346\214\207\345\215\227.md" +++ "b/docs/development/\345\233\275\351\231\205\345\214\226\345\274\200\345\217\221\346\214\207\345\215\227.md" @@ -143,6 +143,31 @@ msgstr[0] "找到 {n} 个文件" 这会依次执行提取、更新和编译操作。 +### PyInstaller 打包支持 + +项目使用 PyInstaller 构建单文件可执行程序时,国际化翻译文件会自动打包。 + +**配置文件**: `oi-cli.spec` + +```python +# 数据文件 +added_files = [ + (str(src_dir / "app" / "css" / "styles.tcss"), "app/css"), + # 国际化翻译文件 + (str(src_dir / "i18n" / "locales" / "en_US" / "LC_MESSAGES" / "messages.mo"), "i18n/locales/en_US/LC_MESSAGES"), + (str(src_dir / "i18n" / "locales" / "zh_CN" / "LC_MESSAGES" / "messages.mo"), "i18n/locales/zh_CN/LC_MESSAGES"), +] +``` + +**构建流程**: + +1. 编译翻译文件: `./scripts/tools/i18n-manager.sh compile` +2. 打包应用: `pyinstaller oi-cli.spec` + +打包后的可执行文件会包含所有翻译,无需额外配置即可使用国际化功能。 + +**添加新语言时**: 记得在 `oi-cli.spec` 中添加对应的 `.mo` 文件路径。 + ### 添加新语言 要添加对新语言的支持: diff --git a/oi-cli.spec b/oi-cli.spec index 955e7c8..b1ad230 100644 --- a/oi-cli.spec +++ b/oi-cli.spec @@ -37,6 +37,9 @@ hidden_imports = [ # 数据文件 added_files = [ (str(src_dir / "app" / "css" / "styles.tcss"), "app/css"), + # 国际化翻译文件 + (str(src_dir / "i18n" / "locales" / "en_US" / "LC_MESSAGES" / "messages.mo"), "i18n/locales/en_US/LC_MESSAGES"), + (str(src_dir / "i18n" / "locales" / "zh_CN" / "LC_MESSAGES" / "messages.mo"), "i18n/locales/zh_CN/LC_MESSAGES"), ] a = Analysis( -- Gitee From 79bca35e78cdcd6df98d2845c0db50b62557941c Mon Sep 17 00:00:00 2001 From: Hongyu Shi Date: Fri, 17 Oct 2025 18:05:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore(i18n):=20=E6=B7=BB=E5=8A=A0=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E5=92=8C=E7=AE=80=E4=BD=93=E4=B8=AD=E6=96=87=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hongyu Shi --- .../locales/en_US/LC_MESSAGES/messages.po | 172 ++++++++++++++++++ src/i18n/locales/messages.pot | 163 +++++++++++++++++ .../locales/zh_CN/LC_MESSAGES/messages.po | 170 +++++++++++++++++ 3 files changed, 505 insertions(+) create mode 100644 src/i18n/locales/en_US/LC_MESSAGES/messages.po create mode 100644 src/i18n/locales/messages.pot create mode 100644 src/i18n/locales/zh_CN/LC_MESSAGES/messages.po diff --git a/src/i18n/locales/en_US/LC_MESSAGES/messages.po b/src/i18n/locales/en_US/LC_MESSAGES/messages.po new file mode 100644 index 0000000..991491c --- /dev/null +++ b/src/i18n/locales/en_US/LC_MESSAGES/messages.po @@ -0,0 +1,172 @@ +# English translations for smart-shell package. +# Copyright (C) 2025 openEuler Intelligence Project +# This file is distributed under the same license as the smart-shell package. +# +msgid "" +msgstr "" +"Project-Id-Version: smart-shell\n" +"Report-Msgid-Bugs-To: contact@openeuler.org\n" +"POT-Creation-Date: 2025-10-17 17:39+0800\n" +"PO-Revision-Date: 2025-01-17 00:00+0000\n" +"Last-Translator: openEuler Intelligence Team\n" +"Language-Team: English\n" +"Language: en_US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: src/main.py:28 +msgid "openEuler Intelligence - Intelligent command-line tool" +msgstr "openEuler Intelligence - Intelligent command-line tool" + +#: src/main.py:29 +msgid "" +"\n" +"For more information and documentation, please visit:\n" +" https://gitee.com/openeuler/euler-copilot-shell/tree/master/docs\n" +" " +msgstr "" +"\n" +"For more information and documentation, please visit:\n" +" https://gitee.com/openeuler/euler-copilot-shell/tree/master/docs\n" +" " + +#: src/main.py:39 +msgid "General Options" +msgstr "General Options" + +#: src/main.py:40 +msgid "Show help and version information" +msgstr "Show help and version information" + +#: src/main.py:46 +msgid "Show this help message and exit" +msgstr "Show this help message and exit" + +#: src/main.py:53 +msgid "Show program version number and exit" +msgstr "Show program version number and exit" + +#: src/main.py:58 +msgid "Backend Configuration Options" +msgstr "Backend Configuration Options" + +#: src/main.py:59 +msgid "" +"For initializing and configuring openEuler Intelligence backend services" +msgstr "" +"For initializing and configuring openEuler Intelligence backend services" + +#: src/main.py:65 +msgid "" +"Initialize openEuler Intelligence backend\n" +" * Initialization requires administrator privileges and network connection" +msgstr "" +"Initialize openEuler Intelligence backend\n" +" * Initialization requires administrator privileges and network connection" + +#: src/main.py:73 +msgid "" +"Change openEuler Intelligence LLM settings (requires valid local backend " +"service)\n" +" * Configuration editing requires administrator privileges" +msgstr "" +"Change openEuler Intelligence LLM settings (requires valid local backend " +"service)\n" +" * Configuration editing requires administrator privileges" + +#: src/main.py:80 +msgid "Application Configuration Options" +msgstr "Application Configuration Options" + +#: src/main.py:81 +msgid "For configuring application frontend behavior and preferences" +msgstr "For configuring application frontend behavior and preferences" + +#: src/main.py:86 +msgid "Select default agent" +msgstr "Select default agent" + +#: src/main.py:91 +msgid "Language Settings" +msgstr "Language Settings" + +#: src/main.py:92 +msgid "For configuring application display language" +msgstr "For configuring application display language" + +#: src/main.py:100 +#, python-brace-format +msgid "Set display language (available: {locales})" +msgstr "Set display language (available: {locales})" + +#: src/main.py:105 +msgid "Log Management Options" +msgstr "Log Management Options" + +#: src/main.py:106 +msgid "For viewing and configuring log output" +msgstr "For viewing and configuring log output" + +#: src/main.py:111 +msgid "Show latest log content (up to 1000 lines)" +msgstr "Show latest log content (up to 1000 lines)" + +#: src/main.py:117 +msgid "Set log level (available: DEBUG, INFO, WARNING, ERROR)" +msgstr "Set log level (available: DEBUG, INFO, WARNING, ERROR)" + +#: src/main.py:140 +#, python-brace-format +msgid "Failed to retrieve logs: {error}\n" +msgstr "Failed to retrieve logs: {error}\n" + +#: src/main.py:147 +#, python-brace-format +msgid "Invalid log level: {level}\n" +msgstr "Invalid log level: {level}\n" + +#: src/main.py:156 +#, python-format +msgid "Log level has been set to: %s" +msgstr "Log level has been set to: %s" + +#: src/main.py:157 +msgid "This is a DEBUG level test message" +msgstr "This is a DEBUG level test message" + +#: src/main.py:158 +msgid "This is an INFO level test message" +msgstr "This is an INFO level test message" + +#: src/main.py:159 +msgid "This is a WARNING level test message" +msgstr "This is a WARNING level test message" + +#: src/main.py:160 +msgid "This is an ERROR level test message" +msgstr "This is an ERROR level test message" + +#: src/main.py:162 +#, python-brace-format +msgid "✓ Log level successfully set to: {level}\n" +msgstr "✓ Log level successfully set to: {level}\n" + +#: src/main.py:163 +msgid "✓ Logging system initialized\n" +msgstr "✓ Logging system initialized\n" + +#: src/main.py:181 +#, python-brace-format +msgid "✓ Language set to: {locale}\n" +msgstr "✓ Language set to: {locale}\n" + +#: src/main.py:183 +#, python-brace-format +msgid "✗ Unsupported language: {locale}\n" +msgstr "✗ Unsupported language: {locale}\n" + +#: src/main.py:218 +msgid "Fatal error in Intelligent Shell application" +msgstr "Fatal error in Intelligent Shell application" diff --git a/src/i18n/locales/messages.pot b/src/i18n/locales/messages.pot new file mode 100644 index 0000000..3545d8e --- /dev/null +++ b/src/i18n/locales/messages.pot @@ -0,0 +1,163 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR openEuler Intelligence Project +# This file is distributed under the same license as the smart-shell package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: smart-shell 0.10.2\n" +"Report-Msgid-Bugs-To: contact@openeuler.org\n" +"POT-Creation-Date: 2025-10-17 17:39+0800\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/main.py:28 +msgid "openEuler Intelligence - Intelligent command-line tool" +msgstr "" + +#: src/main.py:29 +msgid "" +"\n" +"For more information and documentation, please visit:\n" +" https://gitee.com/openeuler/euler-copilot-shell/tree/master/docs\n" +" " +msgstr "" + +#: src/main.py:39 +msgid "General Options" +msgstr "" + +#: src/main.py:40 +msgid "Show help and version information" +msgstr "" + +#: src/main.py:46 +msgid "Show this help message and exit" +msgstr "" + +#: src/main.py:53 +msgid "Show program version number and exit" +msgstr "" + +#: src/main.py:58 +msgid "Backend Configuration Options" +msgstr "" + +#: src/main.py:59 +msgid "" +"For initializing and configuring openEuler Intelligence backend services" +msgstr "" + +#: src/main.py:65 +msgid "" +"Initialize openEuler Intelligence backend\n" +" * Initialization requires administrator privileges and network connection" +msgstr "" + +#: src/main.py:73 +msgid "" +"Change openEuler Intelligence LLM settings (requires valid local backend " +"service)\n" +" * Configuration editing requires administrator privileges" +msgstr "" + +#: src/main.py:80 +msgid "Application Configuration Options" +msgstr "" + +#: src/main.py:81 +msgid "For configuring application frontend behavior and preferences" +msgstr "" + +#: src/main.py:86 +msgid "Select default agent" +msgstr "" + +#: src/main.py:91 +msgid "Language Settings" +msgstr "" + +#: src/main.py:92 +msgid "For configuring application display language" +msgstr "" + +#: src/main.py:100 +#, python-brace-format +msgid "Set display language (available: {locales})" +msgstr "" + +#: src/main.py:105 +msgid "Log Management Options" +msgstr "" + +#: src/main.py:106 +msgid "For viewing and configuring log output" +msgstr "" + +#: src/main.py:111 +msgid "Show latest log content (up to 1000 lines)" +msgstr "" + +#: src/main.py:117 +msgid "Set log level (available: DEBUG, INFO, WARNING, ERROR)" +msgstr "" + +#: src/main.py:140 +#, python-brace-format +msgid "Failed to retrieve logs: {error}\n" +msgstr "" + +#: src/main.py:147 +#, python-brace-format +msgid "Invalid log level: {level}\n" +msgstr "" + +#: src/main.py:156 +#, python-format +msgid "Log level has been set to: %s" +msgstr "" + +#: src/main.py:157 +msgid "This is a DEBUG level test message" +msgstr "" + +#: src/main.py:158 +msgid "This is an INFO level test message" +msgstr "" + +#: src/main.py:159 +msgid "This is a WARNING level test message" +msgstr "" + +#: src/main.py:160 +msgid "This is an ERROR level test message" +msgstr "" + +#: src/main.py:162 +#, python-brace-format +msgid "✓ Log level successfully set to: {level}\n" +msgstr "" + +#: src/main.py:163 +msgid "✓ Logging system initialized\n" +msgstr "" + +#: src/main.py:181 +#, python-brace-format +msgid "✓ Language set to: {locale}\n" +msgstr "" + +#: src/main.py:183 +#, python-brace-format +msgid "✗ Unsupported language: {locale}\n" +msgstr "" + +#: src/main.py:218 +msgid "Fatal error in Intelligent Shell application" +msgstr "" diff --git a/src/i18n/locales/zh_CN/LC_MESSAGES/messages.po b/src/i18n/locales/zh_CN/LC_MESSAGES/messages.po new file mode 100644 index 0000000..a52bf85 --- /dev/null +++ b/src/i18n/locales/zh_CN/LC_MESSAGES/messages.po @@ -0,0 +1,170 @@ +# Simplified Chinese translations for smart-shell package. +# Copyright (C) 2025 openEuler Intelligence Project +# This file is distributed under the same license as the smart-shell package. +# +msgid "" +msgstr "" +"Project-Id-Version: smart-shell\n" +"Report-Msgid-Bugs-To: contact@openeuler.org\n" +"POT-Creation-Date: 2025-10-17 17:39+0800\n" +"PO-Revision-Date: 2025-01-17 00:00+0000\n" +"Last-Translator: openEuler Intelligence Team\n" +"Language-Team: Chinese (Simplified)\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: src/main.py:28 +msgid "openEuler Intelligence - Intelligent command-line tool" +msgstr "openEuler Intelligence - 智能命令行工具" + +#: src/main.py:29 +msgid "" +"\n" +"For more information and documentation, please visit:\n" +" https://gitee.com/openeuler/euler-copilot-shell/tree/master/docs\n" +" " +msgstr "" +"\n" +"更多信息和使用文档请访问:\n" +" https://gitee.com/openeuler/euler-copilot-shell/tree/master/docs\n" +" " + +#: src/main.py:39 +msgid "General Options" +msgstr "通用选项" + +#: src/main.py:40 +msgid "Show help and version information" +msgstr "显示帮助信息和版本信息" + +#: src/main.py:46 +msgid "Show this help message and exit" +msgstr "显示此帮助信息并退出" + +#: src/main.py:53 +msgid "Show program version number and exit" +msgstr "显示程序版本号并退出" + +#: src/main.py:58 +msgid "Backend Configuration Options" +msgstr "后端配置选项" + +#: src/main.py:59 +msgid "" +"For initializing and configuring openEuler Intelligence backend services" +msgstr "用于初始化和配置 openEuler Intelligence 后端服务" + +#: src/main.py:65 +msgid "" +"Initialize openEuler Intelligence backend\n" +" * Initialization requires administrator privileges and network connection" +msgstr "" +"初始化 openEuler Intelligence 后端\n" +" * 初始化操作需要管理员权限和网络连接" + +#: src/main.py:73 +msgid "" +"Change openEuler Intelligence LLM settings (requires valid local backend " +"service)\n" +" * Configuration editing requires administrator privileges" +msgstr "" +"更改 openEuler Intelligence 大模型设置(需要有效的本地后端服务)\n" +" * 配置编辑操作需要管理员权限" + +#: src/main.py:80 +msgid "Application Configuration Options" +msgstr "应用配置选项" + +#: src/main.py:81 +msgid "For configuring application frontend behavior and preferences" +msgstr "用于配置应用前端行为和偏好设置" + +#: src/main.py:86 +msgid "Select default agent" +msgstr "选择默认智能体" + +#: src/main.py:91 +msgid "Language Settings" +msgstr "语言设置" + +#: src/main.py:92 +msgid "For configuring application display language" +msgstr "用于配置应用显示语言" + +#: src/main.py:100 +#, python-brace-format +msgid "Set display language (available: {locales})" +msgstr "设置显示语言 (可选: {locales})" + +#: src/main.py:105 +msgid "Log Management Options" +msgstr "日志管理选项" + +#: src/main.py:106 +msgid "For viewing and configuring log output" +msgstr "用于查看和配置日志输出" + +#: src/main.py:111 +msgid "Show latest log content (up to 1000 lines)" +msgstr "显示最新的日志内容(最多1000行)" + +#: src/main.py:117 +msgid "Set log level (available: DEBUG, INFO, WARNING, ERROR)" +msgstr "设置日志级别 (可选: DEBUG, INFO, WARNING, ERROR)" + +#: src/main.py:140 +#, python-brace-format +msgid "Failed to retrieve logs: {error}\n" +msgstr "获取日志失败: {error}\n" + +#: src/main.py:147 +#, python-brace-format +msgid "Invalid log level: {level}\n" +msgstr "无效的日志级别: {level}\n" + +#: src/main.py:156 +#, python-format +msgid "Log level has been set to: %s" +msgstr "日志级别已设置为: %s" + +#: src/main.py:157 +msgid "This is a DEBUG level test message" +msgstr "这是一条 DEBUG 级别的测试消息" + +#: src/main.py:158 +msgid "This is an INFO level test message" +msgstr "这是一条 INFO 级别的测试消息" + +#: src/main.py:159 +msgid "This is a WARNING level test message" +msgstr "这是一条 WARNING 级别的测试消息" + +#: src/main.py:160 +msgid "This is an ERROR level test message" +msgstr "这是一条 ERROR 级别的测试消息" + +#: src/main.py:162 +#, python-brace-format +msgid "✓ Log level successfully set to: {level}\n" +msgstr "✓ 日志级别已成功设置为: {level}\n" + +#: src/main.py:163 +msgid "✓ Logging system initialized\n" +msgstr "✓ 日志系统初始化完成\n" + +#: src/main.py:181 +#, python-brace-format +msgid "✓ Language set to: {locale}\n" +msgstr "✓ 语言已设置为: {locale}\n" + +#: src/main.py:183 +#, python-brace-format +msgid "✗ Unsupported language: {locale}\n" +msgstr "✗ 不支持的语言: {locale}\n" + +#: src/main.py:218 +msgid "Fatal error in Intelligent Shell application" +msgstr "智能 Shell 应用发生致命错误" -- Gitee