添加readme
This commit is contained in:
parent
acd78aad95
commit
f4a8b6c46c
Binary file not shown.
|
@ -0,0 +1,77 @@
|
|||
import xml.etree.ElementTree as et
|
||||
import re
|
||||
import os
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def read_resx_to_dict(path):
|
||||
tree = et.parse(path)
|
||||
root = tree.getroot()
|
||||
res_dict_x = {}
|
||||
for data in root.findall('data'):
|
||||
name = data.attrib['name']
|
||||
value = data.find('value').text
|
||||
res_dict_x[value] = name
|
||||
return res_dict_x
|
||||
|
||||
|
||||
def replace_text(content, old_text, new_text):
|
||||
# 替换在标签之间的文本
|
||||
# content = re.sub(r'>(.*?)' + re.escape(old_text) + r'(.*?)<',
|
||||
# f'>\\1<asp:Literal runat="server" Text="<%$ Resources:Lan,{new_text}%>"/>\\2<',
|
||||
# content)
|
||||
|
||||
content = re.sub(r'>' + re.escape(old_text) + r'<',
|
||||
f'><asp:Literal runat="server" Text="<%$ Resources:Lan,{new_text}%>"/><',
|
||||
content)
|
||||
|
||||
# # 替换在标签之间的文本2
|
||||
# content = content.replace(old_text+"<",'<asp:Literal runat="server" Text="<%$ Resources:Lan,'+new_text+'%>"/><')
|
||||
|
||||
# 替换在属性值中的文本
|
||||
content = re.sub(r'"([^"]*)"',
|
||||
lambda m: f'\"<%$ Resources:Lan,{new_text}%>\"' if m.group(1) == old_text else m.group(0),
|
||||
content)
|
||||
return content
|
||||
|
||||
def replace_text_in_aspx(aspx_file, res_dict):
|
||||
with open(aspx_file, 'r', encoding='utf-8', newline='') as file:
|
||||
aspx_content = file.read()
|
||||
|
||||
for old_text, new_text in res_dict.items():
|
||||
if new_text != "":
|
||||
aspx_content = replace_text(aspx_content, old_text, new_text)
|
||||
|
||||
with open(aspx_file, 'w', encoding='utf-8', newline='') as file:
|
||||
file.write(aspx_content)
|
||||
print(f"{aspx_file} ...替换完成")
|
||||
|
||||
|
||||
def get_aspx_files(directory):
|
||||
aspx_files = []
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for file in files:
|
||||
if file.endswith('.aspx'):
|
||||
aspx_files.append(os.path.join(root, file))
|
||||
return aspx_files
|
||||
|
||||
|
||||
#示例调用
|
||||
resx_path = "E:\\work_zhj\\Chinese2English\\ZHGL.resx"
|
||||
directory_path = 'E:\work\project\成达\sggl_cd\SGGL\FineUIPro.Web\ZHGL'
|
||||
|
||||
res_dict = read_resx_to_dict(resx_path)
|
||||
print("资源文件分析完成")
|
||||
print("开始替换")
|
||||
|
||||
aspx_files = get_aspx_files(directory_path)
|
||||
for file in aspx_files:
|
||||
replace_text_in_aspx(file, res_dict)
|
||||
|
||||
# 替换 单个aspx 文件中的文本
|
||||
# resx_path = "E:\\work_zhj\\Chinese2English\\rest.resx"
|
||||
#
|
||||
# res_dict = read_resx_to_dict(resx_path)
|
||||
#
|
||||
# directory_path = "E:\work\project\成达\sggl_cd\SGGL\FineUIPro.Web\index.aspx"
|
||||
#
|
||||
# replace_text_in_aspx(directory_path, res_dict)
|
Binary file not shown.
After Width: | Height: | Size: 550 KiB |
Binary file not shown.
After Width: | Height: | Size: 272 KiB |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.5 MiB |
|
@ -0,0 +1,79 @@
|
|||
## 对.net项目进行整体的国际化
|
||||
|
||||
### 整体思路
|
||||
- 手动处理的方式,面对整体项目文件较多时效率有限,
|
||||
- 举例来说,总数为20000+需要替换的地方
|
||||
- 其中大部分为重复的替换操作。
|
||||
|
||||
- 生成的资源文件[Chinese2English.rar](code/Chinese2English.rar)
|
||||
- 替换资源时的参考代码[replase3.py](code/replase3.py)
|
||||
- 生成资源方式参考
|
||||
### 目前欠缺
|
||||
- ASPX.cs 文件内未修改,资源确认, Menu未国际化。
|
||||
- 一部分主页未替换
|
||||
- 建议每个页面都打开确认,有时候可能漏了个别页面。
|
||||

|
||||
|
||||
### 半自动化处理流程一览
|
||||

|
||||
|
||||
### 具体操作步骤
|
||||
|
||||
* 判断页面总量,参考img/项目总览.png
|
||||
* 查看代码判断哪些部分需要进行处理
|
||||
- aspx文件
|
||||
- ` <view>标题</view> <asp:Literal runat="server" Text="<%$ Resources:Lan,{new_text}%/>`
|
||||
- `<text="标题"/> <%$ Resources:Lan,{new_text}%>`
|
||||
- aspx.cs 文件中的提示词
|
||||
- Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||||
- 下拉框的 "请选择"
|
||||
* 参考res.resx 文件的写法,使用工具生成对应文件的资源文件,拿通义灵码举例:指定代码后使用promote
|
||||
|
||||
为了实现 这个文件的国际化,我们需要为文件中的所有静态文本添加资源文件中的键值。
|
||||
以下是 Lan.zh-CN.resx 和 Lan.en.resx 文件中需要添加的资源项。
|
||||
输出参考:<!-- InstallationSave.aspx --> <data name="InstallationSave_txtInstallationCode_Label" xml:space="preserve"> <value>装置/单元编号</value> </data> <data name="InstallationSave_txtInstallationName_Label" xml:space="preserve"> <value>装置/单元名称</value> </data>
|
||||
不需要给出aspx文件,但是需要注意所有会被展示的中文文本都需要国际化,比如说单位。
|
||||
请使用注释标明文件名。不需要给出修改后的aspx文件。
|
||||
name的前缀为文件名,不允许使用中文,
|
||||
如果我输入1,代表之前的输出很满意,请继续按照之前的方式输出。
|
||||
|
||||
|
||||
|
||||
- 获得中英文资源类似
|
||||
|
||||
<data name="StartWorkReport_Title" xml:space="preserve"><value>开工报告</value></data>
|
||||
<data name="StartWorkReport_SearchPlaceholder" xml:space="preserve"><value>按名称查询</value></data>
|
||||
<data name="StartWorkReport_Search" xml:space="preserve"><value>查询</value></data>
|
||||
<data name="StartWorkReport_New" xml:space="preserve"><value>增加</value></data>
|
||||
<data name="StartWorkReport_Edit" xml:space="preserve"><value>修改</value></data>
|
||||
<data name="StartWorkReport_Delete" xml:space="preserve"><value>删除</value></data>
|
||||
<data name="StartWorkReport_DeleteConfirm" xml:space="preserve"><value>确定要删除数据吗?</value></data>
|
||||
<data name="StartWorkReport_SerialNumber" xml:space="preserve"><value>序号</value></data>
|
||||
<data name="StartWorkReport_FileCode" xml:space="preserve"><value>编号</value></data>
|
||||
<data name="StartWorkReport_FileName" xml:space="preserve"><value>名称</value></data>
|
||||
<data name="StartWorkReport_UploadManName" xml:space="preserve"><value>编制人</value></data>
|
||||
<data name="StartWorkReport_UploadDate" xml:space="preserve"><value>上传日期</value></data>
|
||||
<data name="StartWorkReport_Remark" xml:space="preserve"><value>备注</value></data>
|
||||
<data name="StartWorkReport_AttachmentView" xml:space="preserve"><value>附件查看</value></data>
|
||||
<data name="StartWorkReport_PageSize" xml:space="preserve"><value>每页记录数:</value></data>
|
||||
<data name="StartWorkReport_WindowTitle" xml:space="preserve"><value>页面编辑</value></data>
|
||||
注意:首次获得的返回资源非常重要一定要调整到正确,之后每次输入1即可。
|
||||
|
||||
- 使用资源文件对代码进行替换 参考代码见code文件夹 replace3.py
|
||||
- 将中英文两份资源文件复制到 lan.resx Lan.en-US.resx Lan.zh-CN.resx 等资源文件并确认能否正常显示
|
||||
- 如果存在资源名称重复可以使用rename.py ,注意name的大小写在resx文件中是不敏感的
|
||||
- 运行代码,然后查漏补缺!!!
|
||||
- aspx.cs文件中由于重复度相对比较高,建议使用python代码 进行批量替换操作然后再查漏补缺
|
||||
|
||||
### 操作流程
|
||||
1. 查看需要进行国际化的部分
|
||||
2. 生成资源文件,建议批量处理。
|
||||
3. 使用python代码通过资源文件,批量替换代码中的关键词
|
||||
4. 生成的资源文件整合进项目文件
|
||||
5. 运行并查漏补缺。
|
||||
|
||||
|
||||
|
||||
|
||||
### 项目总览(后来发现还有一页!外加几个菜单!)
|
||||

|
Loading…
Reference in New Issue