mirror of
https://github.com/jumpserver/lina.git
synced 2025-05-11 01:27:13 +00:00
perf: 优化 i18n-util 工具, apply 后删除 diff 文件; (#2533)
* perf: 添加 npm run diff-i18n | npm run apply-i18n 脚本执行 * perf: 优化 i18n-util 工具, apply 后删除 diff 文件; --------- Co-authored-by: Bai <baijiangjie@gmail.com> Co-authored-by: Jiangjie.Bai <bugatti_it@163.com>
This commit is contained in:
parent
71ac63b0c5
commit
2f79fa2d50
3
.gitignore
vendored
3
.gitignore
vendored
@ -16,6 +16,3 @@ tests/**/coverage/
|
||||
*.njsproj
|
||||
*.sln
|
||||
.env.development
|
||||
|
||||
src/i18n/langs/diff-zh-en.json
|
||||
src/i18n/langs/diff-zh-ja.json
|
||||
|
12
src/i18n/langs/i18n-util.py
Executable file → Normal file
12
src/i18n/langs/i18n-util.py
Executable file → Normal file
@ -16,6 +16,7 @@
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import data_tree
|
||||
@ -47,7 +48,9 @@ class I18NFileUtil(object):
|
||||
diff_paths = set(zh_paths) - set(lang_paths)
|
||||
|
||||
data = {}
|
||||
diff_filepath = f'{self.dir_path}/diff-zh-{lang}.json'
|
||||
|
||||
diff_filepath = f'{self.dir_path}/.diff-zh-{lang}.json'
|
||||
|
||||
with open(diff_filepath, 'w', encoding='utf-8') as f:
|
||||
for path in diff_paths:
|
||||
value = zh_tree.get(path)
|
||||
@ -63,7 +66,8 @@ class I18NFileUtil(object):
|
||||
print(msg)
|
||||
|
||||
def apply(self, lang):
|
||||
diff_data = self.load_json(f'{self.dir_path}/diff-zh-{lang}.json')
|
||||
diff_filepath = f'{self.dir_path}/.diff-zh-{lang}.json'
|
||||
diff_data = self.load_json(diff_filepath)
|
||||
lang_data = self.load_json(f'{self.dir_path}/{lang}.json')
|
||||
|
||||
lang_pdict = PathDict(lang_data, create_if_not_exists=True)
|
||||
@ -74,8 +78,10 @@ class I18NFileUtil(object):
|
||||
data = self.pathdict_to_dict(lang_pdict)
|
||||
data = json.dumps(data, ensure_ascii=False, indent=2)
|
||||
f.write(data)
|
||||
|
||||
print(f'\n翻译文件 {self.dir_path}/{lang}.json 已更新, 总共写入新的翻译 {len(diff_data)} 条.\n')
|
||||
|
||||
# 删除 diff 文件
|
||||
os.remove(diff_filepath)
|
||||
|
||||
def pathdict_to_dict(self, data):
|
||||
d = {}
|
||||
|
Loading…
Reference in New Issue
Block a user