多语言开发环境程序

Borland   C++   Builder   5.0软件开发的国际化   
在Borland   C++   Builder   5.0中提供了为应用程序定制不同语言版本的的功能,下面通过具体的例子来说明其实现过程。 
1:建立一英文般的窗口,窗口上有两按钮。(Caption= "My   Button ",Caption= "OK ")     
2:编译,链接程序。 
3:关闭程序,通过主菜单Project   |   Language   |   Add…打开Add   Languages对话框,然后按照提示信息进行,中间有一个步骤需要选择语言,如(图二)请选择你需要的语言,例如 
选中国(在中国前打标志)。选完之后,按next向下进行,中间经过编译等过程,直到出现Translation   Manager窗口。 
(图二) 

4:在Translation   Manager窗口中,展开左边的的树型控件,然后定位到Forms|Unit1上 
如图三,接着就可以在右面的窗口中修改字符的内容了。将15号(Caption= "OK "),改成“确定”;将20号(Caption= "My   Button "),改成“我的按钮”保存并关闭Translation   Manager窗口。 
图三 
6:在BCB集成环境中,保存所有修改的结果,同时将.BPG文件保存到目录中。然后编译、链接新工程。哈哈,多国语言版本完成。 





------------------------------------------------------------------------------------

eg:


利用XML文件作的多语言DEMO程序

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''

''

'' 多語系設置類

''

'' Create: Bunny_Young 2010-03-12

'' email:yangmeiwen@163.com

''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'' Modification history:

''

''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Imports System.Xml

Imports System.Data

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.IO

Public Class MutiLanguage

Const _LANGUAGE_NAME = "language"

Const _PAGE_NAME = "pageName"

Const _CONTROL_NAME = "controlName"

Const _CONTROL_TYPE = "controlType"

Const _CONTROL_VALUE = "controlValue"

Private _PageName As String ''resource讀取路徑

Private _languageType As String ''

Private _xmlDoc As XmlDocument

Private _savePath As String

Private ds As DataSet

Sub New(ByVal strLanguage As String, ByVal aspxPage As String)

'savePath = "~/Resource/" + strLanguage

_PageName = "~/Resource/" + strLanguage + "/" + aspxPage + ".xml"

_savePath = "~/Resource/" + strLanguage

_savePath = HttpContext.Current.Server.MapPath(_savePath)

_PageName = HttpContext.Current.Server.MapPath(_PageName)

_languageType = strLanguage

End Sub

Public Sub GetDataSet()

ds = New DataSet()

ds.ReadXml(_PageName, XmlReadMode.Auto)

End Sub

Public Function UpdateLanguage(ByVal _controlName As String, ByVal _controlType As String, ByVal _controlValue As String) As Boolean

GetDataSet()

For Each dr As DataRow In ds.Tables(0).Rows

If dr("controlName") = _controlName And dr("controlType") = _controlType Then

dr("controlValue") = _controlValue

End If

Next

ds.WriteXml(_PageName, XmlWriteMode.IgnoreSchema)

ds.ReadXml(_PageName)

End Function

Public Function GetControlsList() As List(Of UIControl)

GetDataSet()

Dim dt As DataTable = ds.Tables(0)

Dim ResultList As New List(Of UIControl)

For Each dr As DataRow In dt.Rows

Dim MyControl As New UIControl

MyControl.ControlName = dr("controlName")

MyControl.ControlType = dr("controlType")

MyControl.ControlValue = dr("controlValue")

ResultList.Add(MyControl)

Next

Return ResultList

End Function

''' <summary>

''' 主動生成資源文件

''' </summary>

''' <param name="strLanguage">語言類別</param>

''' <param name="Page">WEB PAGE</param>

''' <remarks></remarks>

Public Sub WriteResourceFile(ByVal Page As UI.Page)

Try

If Not Directory.Exists(_savePath) Then

Directory.CreateDirectory(_savePath)

End If

Dim writer As New XmlTextWriter(_PageName, Nothing)

writer.Formatting = Formatting.Indented

''語言類別

writer.WriteStartElement(_LANGUAGE_NAME, _languageType)

LoopAllControls(Page, writer)

''語言類別結束

writer.WriteEndElement()

writer.Close()

Catch ex As Exception

End Try

End Sub

Private Sub LoopAllControls(ByVal oCtrl As Control, ByVal writer As XmlWriter)

For Each _Ctrl As Control In oCtrl.Controls

Dim _strName As String = _Ctrl.GetType.Name.ToUpper

If _strName = "LABEL" Or _strName = "BUTTON" Then

Dim strValue As String

Dim strComment As String

If _strName = "LABEL" Then

strValue = CType(_Ctrl, Label).Text

strComment = "label control"

Else

strValue = CType(_Ctrl, Button).Text

strComment = "button control"

End If

writer.WriteComment(strComment)

writer.WriteStartElement("Control")

writer.WriteAttributeString(_CONTROL_VALUE, strValue)

writer.WriteAttributeString(_CONTROL_NAME, _Ctrl.ID)

writer.WriteAttributeString(_CONTROL_TYPE, _Ctrl.GetType.Name)

writer.WriteEndElement()

End If

If _Ctrl.GetType.Name.ToUpper() = "GRIDVIEW" Then

Continue For

End If

If _Ctrl.HasControls Then

LoopAllControls(_Ctrl, writer)

End If

Next

End Sub

Public Sub ApplylanguageResource(ByVal _aspxPage As System.Web.UI.Page)

GetDataSet()

LoopApply(_aspxPage)

End Sub

Private Sub LoopApply(ByVal _control As Control)

For Each ct As Control In _control.Controls

Dim controlName As String = ct.ID

Dim dr() As System.Data.DataRow = ds.Tables(0).Select("controlName='" + controlName + "'", "controlName DESC")

If dr.Count > 0 Then

If ct.GetType.Name.ToUpper = "LABEL" Then

CType(ct, Label).Text = dr(0)("controlValue")

End If

If ct.GetType.Name.ToUpper = "BUTTON" Then

CType(ct, Button).Text = dr(0)("controlValue")

End If

End If

If ct.HasControls Then

LoopApply(ct)

End If

Next

End Sub

End Class


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值