ASP.NET Tutorial/I18N/Request — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:30, 26 мая 2010
Displaying a browser"s language settings.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
void Page_Load()
{
bltAcceptLanguages.DataSource = Request.UserLanguages;
bltAcceptLanguages.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show Accept Languages</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:BulletedList
id="bltAcceptLanguages"
Runat="server" />
</div>
</form>
</body>
</html>
Get language resource file based on user language
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import namespace="System.Resources" %>
<%@ Import namespace="System.Threading" %>
<script runat="server">
sub Page_Load(Sender as Object, e as EventArgs)
dim objRM as ResourceManager
dim strLanguage as string = Request.UserLanguages(0).ToString
dim objCulture as new CultureInfo(strLanguage)
Thread.CurrentThread.CurrentCulture = new CultureInfo(strLanguage)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLanguage)
objRM = ResourceManager.CreateFileBasedResourceManager("data",Server.MapPath("."), Nothing)
lblGreeting.Text = objRM.GetString("Greeting")
objRM.ReleaseAllResources
end sub
</script>
<html><body>
<b><asp:Label id="lblGreeting" runat="server"/></b>
</body></html>
File: data.en-us.txt
Greeting=Welcome!
File: data.fr-fr.txt
Greeting=Bonjour!
Request.UserLanguages
<%@Page Language="VB" %>
<%@Import Namespace="System.Globalization" %>
<script runat="server">
sub Page_Load(Sender as Object,e as EventArgs)
lblMessage.Text = Request.UserLanguages(0).ToString
end sub
</script>
<html><body>
Your primary language is:
<asp:Label id="lblMessage" runat="server"/>
</body></html>