asp.net开发国际化的程序十个例子
by Max Poliashenko and Chip Andrews
例子1
(a)
<INPUT type=text value= <%=GetString(unTranslatedString ) %>>
(b)
Response.Write("<SELECT>")
For Each row In myRecordset
Reponse.Write("<OPTION")
If myRecordset!ID.value = oldSelection Then
Response.Write(" SELECTED>")
Else
Response.Write(">")
End If
Response.Write(GetLocalizedString(myRecordset!MyField.value)&
"</OPTION>")
Next
Response.Write("</SELECT>")
例子2
(a)
public class GlobalizedLabel : System.Web.UI.WebControls.Label
{
protected override void Render(HtmlTextWriter output)
{
output.Write(Translator.GetLocalizedString(Text));
}
}
(b)
Translator.GetLocalizedString("The amount of ")) + price.ToString(
) +
Translator.GetLocalizedString(" will be charged to your account.&quo
t;));
(c)
(new StringBuilder()).AppendFormat("The amount of {0:C} will be
charged to your account.", price);
(d)
<%@ Page language="c#" %>
<%@ Register TagPrefix="glb" NameSpace="GlobalControls&quo
t;
Assembly="GlobalComponents&quo
t;%>
<HTML>
<BODY>
<glb:GlobalizedLabel id=lblGlobal runat=server>Test Label
</glb:GlobalizedLabel>
</BODY>
</HTML>
例子3
/// <summary>
/// Validation messages are translated
/// </summary>
public class GlobalizedRequiredFieldValidator : RequiredFieldValidator
{
protected override void Render(HtmlTextWriter output)
{
Text = Translator.GetLocalizedString(Text);
ErrorMessage = Translator.GetLocalizedString(ErrorMessage);
base.Render(output);
}
}
... etc.
public class GlobalizedValidationSummary : ValidationSummary
{
/// <summary>
/// This header will be translated
/// </summary>
public new string HeaderText
{
get{return base.HeaderText;}
set{base.HeaderText = Translator.GetLocalizedString(value);}
}
}
例子4
<%@ Page language="c#" %>
<%@ Register TagPrefix="glb" NameSpace="AspNetDemo.Compone
nts"
Assembly="Components"
;%>
<HTML>
<HEAD>
<meta content="Microsoft Visual Studio 7.0" name="GENE
RATOR">
<meta content="C#" name="CODE_LANGUAGE">
</HEAD>
<body bgColor="#e4e4e0">
<h3 align="center">User Information</h3>
<form id="Form2" method="post" runat="server&q
uot;>
<glb:GlobalizedValidationSummary id="vSummary" runat="
server"
headertext="The following validation errors occurred:" />
<hr>
<table cellSpacing="0" cellPadding="0" width=&quo
t;100%" border="0">
<tr>
<td width="30%">Name</td>
<td>
<asp:textbox id="txName" runat="server">
</asp:textbox>
<glb:GlobalizedRequiredFieldValidator id="rfValidator1&quo
t;
runat="server" display=&
quot;dynamic"
controltovalidate="txName" ErrorMessage="Name is re
quired."
Text="required
" />
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:textbox id="txPassword" TextMode="Password&
quot;
runat="server"></asp:textbox>
<glb:GlobalizedRequiredFieldValidator id="rfValidator2&quo
t;
controltovalidate="txPassword" runat=&
quot;server"