1
0
mirror of https://github.com/jumpserver/lina.git synced 2025-05-11 01:27:13 +00:00

perf: 优化 i18n-util 工具, apply 后删除 diff 文件; ()

* 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:
fit2bot 2023-02-06 16:04:29 +08:00 committed by GitHub
parent 71ac63b0c5
commit 2f79fa2d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

3
.gitignore vendored
View File

@ -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
View 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 = {}