在当今开放的年代里,国际化潮流越来越密切的时代里,发展为多种语言的趋势就越来越强了。当今在互联网的时代里,web应用程序的范围越来越广泛,但是要做成多语言功能的web应用需要付出很多的人力财力。
为此,制作一个多语言的工具的必要性就迫在眉睫;
我就在工作闲于写了个针对web应用的多语言生成工具。
制作背景:
我采用了我同事的一个多语言模块,我只是把这个模块的引用地址加入到了每个页面。
如下:
1
HB.Localization localization = new HB.Localization();
2
//传入当前文件的资源文件所在的位置,格式为:"项目名.Globalization.当前文件名"
3
localization.LocalResource = "HBWeb.Globalization.DossierBaseInfo";
4
//下面一句获取当前的程序集。
5
localization.ExcutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
生成原理:
2

3

4

5

根据前台和后台的代码来找中文单词,让后再用我的一个多语言处理类进行处理。如果是前台的就用
1
<%#var%>
后台的就可以生成相应的后台变量如下:
1
string strName = XM0;
2
…………
3
4
txtName.Text = XM0;
5
……
6
7
下面来列个例子:
2

3

4

5

6

7

1
<%
@ Page language="c#" Codebehind="HBweb.aspx.cs" AutoEventWireup="false" Inherits="HB.CreateSubCollection" %>
2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3
<HTML>
4
<HEAD>
5
<title>
6
我的标题
7
</title>
8
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
9
<meta name="CODE_LANGUAGE" Content="C#">
10
<meta name="vs_defaultClientScript" content="JavaScript">
11
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
12
<base target="_self">
13
</HEAD>
14
<body MS_POSITIONING="GridLayout" scroll="no">
15
<form id="Form1" method="post" runat="server">
16
<asp:lable id="lable1" >标题</asp:lable>
17
</form>
18
19
</body>
20
</HTML>
21



2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

前台生成后:
1
<%
@ Page language="c#" Codebehind="HBweb.aspx.cs" AutoEventWireup="false" Inherits="HB.CreateSubCollection" %>
2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3
<HTML>
4
<HEAD>
5
<title>
6
<%=WDBT0%>
7
</title>
8
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
9
<meta name="CODE_LANGUAGE" Content="C#">
10
<meta name="vs_defaultClientScript" content="JavaScript">
11
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
12
<base target="_self">
13
</HEAD>
14
<body MS_POSITIONING="GridLayout" scroll="no">
15
<form id="Form1" method="post" runat="server">
16
<asp:lable id="lable1" ></asp:lable>
17
</form>
19
</body>
20
</HTML>
21
后台生成了:


2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

19

20

21

1 public string WDBT0 = ""; //我的标题
2 public string BT1 = ""; //标题
3 #region 多语言设置
4 /// <summary>
5 /// 多语言参数设置
6 /// </summary>
7 private void InitText()
8 {
9 HB.Localization localization = new HB.Localization();
10 //传入当前文件的资源文件所在的位置,格式为:"项目名.Globalization.当前文件名"
11 localization.LocalResource = "HB.Globalization.HBweb";
12 //下面一句获取当前的程序集。
13 localization.ExcutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
14
15 WDBT0 = = localization.LocalResourceManager.GetString("WDBT0 "); //我的标题
16 BT1 = = localization.LocalResourceManager.GetString("BT1 "); //标题
17 label1.Text = BT1;
18
19 }
20 #endregion
然后在onload事件里就会自动增加一这么一行:2 public string BT1 = ""; //标题
3 #region 多语言设置
4 /// <summary>
5 /// 多语言参数设置
6 /// </summary>
7 private void InitText()
8 {
9 HB.Localization localization = new HB.Localization();
10 //传入当前文件的资源文件所在的位置,格式为:"项目名.Globalization.当前文件名"
11 localization.LocalResource = "HB.Globalization.HBweb";
12 //下面一句获取当前的程序集。
13 localization.ExcutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
14
15 WDBT0 = = localization.LocalResourceManager.GetString("WDBT0 "); //我的标题
16 BT1 = = localization.LocalResourceManager.GetString("BT1 "); //标题
17 label1.Text = BT1;
18
19 }
20 #endregion
1 private void Page_Load(object sender, System.EventArgs e)
2 {
3 // 在此处放置用户代码以初始化页面
4 InitText();
5 ……
6 }
后面有我的源代码,希望同志们多提意见,我们一起改进。2 {
3 // 在此处放置用户代码以初始化页面
4 InitText();
5 ……
6 }
多语言生成工具
源代码