asp.net开发国际化的程序十个例子

Globalized Web Applications & 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"

ErrorMessage="Password is required."

Text="minimum 5 characters" display=&q
uot;dynamic" />

</td>

</tr>

<tr>

<td>Confirm password</td>

<td>

<asp:textbox id="txPasswordConf"

TextMode="Password" runat="
server" />

<glb:GlobalizedCompareValidator id="cmpValidator1"

runat="server" display="Dyn
amic"

controltovalidate="txPasswordConf"

ErrorMessage="Passwords don't match. Please, re-
enter."

ControlToCompare="txPassword" operator="Equal"

type="String" Text="doesn't match"
; />

</td>

</tr>

<tr>

<td>Email</td>

<td>

<asp:textbox id="txEmail" runat="server">
;</asp:textbox>

<glb:GlobalizedRequiredFieldValidator id="rfValidator3&quo
t;

runat="server" display="d
ynamic"

controltovalidate="txEmail" ErrorMessage="Email is
required."

Text="required" />

<glb:GlobalizedRegularExpressionValidator id="EmailRegVali
dator"

validationexpression="/w+@/w+/./w+" runat="server&q
uot;

ErrorMessage="Email format is invalid.

" controltovalidate="txEmail" di
splay="static">

user@domain.ext</glb:GlobalizedRegularExpressionValidator>

</td>

</tr>

<tr>

<td>Age</td>

<td>

<asp:textbox id="txAge" runat="server">&
lt;/asp:textbox>

<glb:GlobalizedRangeValidator id="rngValidator1"

runat="server" controltovalidate
="txAge"

MinimumValue="1" MaximumValue="199" Type="
;Integer"

ErrorMessage="Age is invalid."

display="static" Text="0 < age < 200" /&
gt;

</td>

</tr>

<tr><td>&nbsp;</td></tr>

<tr>

<td align="middle" colSpan="2">

<glb:GlobalizedLinkButton id="btUpdate"

runat="server" Text="Update
" />

&nbsp;

<glb:GlobalizedLinkButton id="btCancel"

runat="server" Text="Cancel
">

Cancel</glb:GlobalizedLinkButton>

</td>

</tr>

</table>

</form>

</body>

</HTML>






例子5

/// <summary>

/// Button that pops client-side dialog to confirm the action. It exposes

/// ConfirmMessage property to set its dialog message with "Are you sur
e?"

/// being a default. It relies on GlobalizedButton class to translate

/// its Text and ToolTip properties.

/// </summary>

public class GlobalizedConfirmButton : Button

{

private string m_ConfirmMsg = "Are you sure?";

/// <summary>

/// Message will be translated and displayed in confirmation dialog box.

/// </summary>

public string ConfirmMessage

{

set{m_ConfirmMsg = value;}

}

/// <summary>

/// Renders HTML and client javascript for confirmation box

/// </summary>

/// <param name="output"></param>

protected override void Render(HtmlTextWriter output)

{

if (Page.Request.Browser.JavaScript == true)

{

output.WriteLine(@"<script id='clientConfirmation'

language='javascript'><!--

function RUSure()

{if (confirm('" + Translator.GetLocalizedString(m_ConfirmMsg)

+ @"')) return true;else return false;}

//--></script>");

Attributes.Add("onclick","return RUSure();");

}

Text = Translator.GetLocalizedString(Text);

base.Render(output);

}

}






例子6

decimal d = 1234.556M;

d.ToString("C",new System.Globalization.CultureInfo("nl-NL&qu
ot;));





例子7

<configuration>

<system.web>

<globalization

responseEncoding="utf-8"

requestEncoding="utf-8"

fileEncoding="utf-8"

culture="en-CA"

uiCulture="de-DE"

/>



</system.web>

</configuration>






例子8

<%@ Page language="c#" Culture="ru-RU" ResponseEncodi
ng="utf-8" %>






例子9

/// <summary>

/// Page sets its Culture according to the user profile

/// to affect all the formatting on this page

/// </summary>

public class LocalizedPage: Page

{

public LocalizedPage()

{

this.Culture = Utility.GetUserContextCulture();

}

}



例子10

System.Threading.Thread.CurrentThread.CurrentUICulture =

new System.Globalization.CultureInfo("de-DE");

  • 1
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

zitjubiz

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值