Skip to content

feat: 添加 Django 国际化翻译文件自动化脚本#6323

Open
wangliang181230 wants to merge 3 commits into
1Panel-dev:v2from
wangliang181230:PR/62-feat-i18n_automation
Open

feat: 添加 Django 国际化翻译文件自动化脚本#6323
wangliang181230 wants to merge 3 commits into
1Panel-dev:v2from
wangliang181230:PR/62-feat-i18n_automation

Conversation

@wangliang181230

@wangliang181230 wangliang181230 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Django 国际化翻译文件自动化脚本

功能执行过程:

  1. 缓存已翻译的内容
  2. 扫描所有Python文件中的国际化代码
  3. 合并已有翻译和新发现的内容
  4. 生成排序后的翻译文件(根据 msgid 进行排序)
  5. 扫描所有Python文件中未使用国际化功能的代码,并写入 not_internationalized.txt 文件中

使用说明:

  1. 手动执行命令:
python apps/locales/i18n_automation.py
  1. 可修改脚本中的 KEEP_NO_SOURCEFalse,自动将源码中已经不存在的项从翻译文件中删除。(但会保留已翻译的项)

脚本对源码的检索率自查:

  1. 先说结论:源码检索率达到了 100%
  2. 手动校验截图:
    1. 源码中存在 4197 处: - 检索词:正则 \b(?:_|gettext_lazy|gettext)\(\s*(?:'[^']|"[^"]|'''|""")
      检索到 4212 处,减掉当前脚本内的 15 处,即 4197 处。
      图片
    2. 翻译文件中也存在 4197 处,和源码中的一致: - 检索词:#: apps/
      图片

后续优化方向建议:

添加 自动翻译 功能,就可以做成自动化程序了。
请对 翻译功能 比较熟的朋友,后续添加该功能,谢谢!!!

此次执行日志:

使用项目根目录: E:\Workspace_Java\3rd-party\1Panel-dev\MaxKB
开始 Django 国际化翻译文件自动化处理
项目根目录: E:\Workspace_Java\3rd-party\1Panel-dev\MaxKB

============================================================
步骤1: 缓存已有的翻译内容
============================================================
从 django.po 解析到 65 条翻译(en_US)
从 django.po 解析到 1762 条翻译(zh_CN)
从 django.po 解析到 1761 条翻译(zh_Hant)
共缓存 1762 条已有翻译

============================================================
步骤2: 扫描 Python 文件中的国际化代码
============================================================
找到 1044 个 Python 文件
扫描了 326 个文件
提取到 1500 条国际化字符串

============================================================
步骤3: 合并已有翻译
============================================================
合并完成,共 2104 条翻译项
其中有翻译内容的: 1762

============================================================
步骤4: 生成翻译文件
============================================================
en_US:   共 2104 条,已翻译 65 条
zh_CN:   共 2104 条,已翻译 1762 条
zh_Hant: 共 2104 条,已翻译 1761 条

所有翻译文件已生成完成!!!

============================================================
步骤5: 扫描未国际化的字符串
============================================================
找到 1044 个 Python 文件
扫描了 44 个文件
发现 86 条未国际化的字符串

============================================================
步骤6: 写入 not_internationalized.txt 文件
============================================================
已写入 76 条未国际化字符串到: E:\Workspace_Java\3rd-party\1Panel-dev\MaxKB\apps\locales\not_internationalized.txt


============================================================
翻译统计报告
============================================================

总翻译条目数: 2104
英文已翻译: 65 (3.09%)
简体中文已翻译: 1762 (83.75%)
繁体中文已翻译: 1761 (83.70%)
有代码来源: 1500
无代码来源(遗留): 604 (可将脚本中的 `KEEP_NO_SOURCE = False` 来自动清除这些项)


============================================================
前10个未翻译简体中文的项目:
============================================================
- Chat record id
- Agent 【{name}】 access token authentication is not supported for agent tool
- Agent Key is required for agent tool 【{name}】
- Model id type
- MCP Server
- MCP Tool ID
- MCP Tool IDs
- MCP Source
- Tool IDs
- App IDs

============================================================
不一致翻译项(简体已翻译但繁体未翻译,或繁体已翻译但简体未翻译):
============================================================
简体已翻译但繁体未翻译 (1 项):
  1. 原文: User
     简体: 用户

============================================================
处理完成!
============================================================

@wangliang181230 wangliang181230 force-pushed the PR/62-feat-i18n_automation branch 28 times, most recently from 64de0a9 to 2ae6bd4 Compare July 3, 2026 03:53
@wangliang181230 wangliang181230 force-pushed the PR/62-feat-i18n_automation branch from 2ae6bd4 to 2e50980 Compare July 3, 2026 06:09
@wangliang181230 wangliang181230 force-pushed the PR/62-feat-i18n_automation branch from 2e50980 to 74723e1 Compare July 3, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant