|
|
@@ -1,6 +1,15 @@
|
|
|
+'''
|
|
|
+Author: deng.yinping deng.yinping@muchinfo.cn
|
|
|
+Date: 2025-03-07 16:27:53
|
|
|
+LastEditors: deng.yinping deng.yinping@muchinfo.cn
|
|
|
+LastEditTime: 2025-03-11 13:56:49
|
|
|
+FilePath: \MTP20_i18n_Tool\src\service_tools.py
|
|
|
+Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
+'''
|
|
|
|
|
|
from src.common import CommonUti
|
|
|
import os
|
|
|
+import re
|
|
|
|
|
|
class Service_Tools:
|
|
|
|
|
|
@@ -59,7 +68,9 @@ class Service_Tools:
|
|
|
continue # 无效行跳过
|
|
|
key, value = key_value[0].strip(), key_value[1].strip()
|
|
|
# 处理转义字符(例如 \n 或 \t)
|
|
|
- value = value.encode('utf-8').decode('unicode_escape')
|
|
|
+ # 判断是否java unicode 转义格式
|
|
|
+ if (Service_Tools.is_unicode_escape(value)):
|
|
|
+ value = value.encode('utf-8').decode('unicode_escape')
|
|
|
properties_dict[key] = value
|
|
|
|
|
|
return properties_dict
|
|
|
@@ -85,10 +96,19 @@ class Service_Tools:
|
|
|
if os.path.exists(oem_output): # 检查文件是否存在[4,10](@ref)
|
|
|
os.remove(oem_output) # 存在则删除[9,10](@ref)
|
|
|
|
|
|
+ # with open(oem_output, 'w', encoding='ISO-8859-1') as f:
|
|
|
with open(oem_output, 'w', encoding='utf-8') as f:
|
|
|
for key, value in excel_dic.items():
|
|
|
# 处理转义字符(如 \n → \\n,等号 → \=)
|
|
|
escaped_value = value.replace('\n', '\\n').replace('=', '\\=')
|
|
|
+ # 转义为unicode
|
|
|
+ # escaped_value = escaped_value.encode('unicode_escape').decode('utf-8')
|
|
|
+
|
|
|
f.write(f"{key}={escaped_value}\n")
|
|
|
|
|
|
- print("%s JSON文件已成功输出到 %s" % (lang, oem_output))
|
|
|
+ print("%s JSON文件已成功输出到 %s" % (lang, oem_output))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def is_unicode_escape(value):
|
|
|
+ # 判断是否java unicode 转义格式
|
|
|
+ return bool(re.search(r'\\u[0-9A-Fa-f]{4}', value))
|