温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

.Net 全球化应用(Global):中英文翻译(附:谷歌在线翻译代码)

发布时间:2020-07-07 02:40:04 来源:网络 阅读:590 作者:行航杭航 栏目:编程语言

1.通过添加ASP.NET文件夹 来添加App.GlobalResources

.Net 全球化应用(Global):中英文翻译(附:谷歌在线翻译代码)


2.App.GlobalResources右键添加资源文件,Resource.en-US.resxResource.resx

分别在两个资源文件里,修改名称、值

.Net 全球化应用(Global):中英文翻译(附:谷歌在线翻译代码)


3.

1>.主要控件:一个Button,一个DropDownList

选择按钮,选择属性,点击(Expressions),选择 Text 属性,表达式类型选为Resources,把表达式属性填好。

.Net 全球化应用(Global):中英文翻译(附:谷歌在线翻译代码)


2>.选中DropDownList,首先点击编辑项...,添加成员,Text为显示的字符串,Value为类型(这里就列出两种格式:中文与英文),记住不要忘记选中启用AutoPostBack

.Net 全球化应用(Global):中英文翻译(附:谷歌在线翻译代码)


3>.Global.aspx代码如下

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Global.aspx.cs"Inherits="Global"UICulture="Auto"Culture="Auto"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title></title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ButtonID="Button1"runat="server"Text="<%$ Resources:Resource, buttontext %>"/>

<br/>

<br/>

语言:<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True">

<asp:ListItemValue="zh-cn">默认</asp:ListItem>

<asp:ListItemValue="en-us">Default</asp:ListItem>

</asp:DropDownList>

</div>

<%--以下为Google在线翻译代码--%>

<div id="google_translate_element"></div>

<script type="text/javascript">

function googleTranslateElementInit(){

new google.translate.TranslateElement({

pageLanguage: 'zh-CN',

autoDisplay: false,

layout: google.translate.TranslateElement.InlineLayout.SIMPLE

}, 'google_translate_element');

}

</script>

<scripttype="text/javascript"src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

</form>

<p>

今天有幸游了一回漓江,真的深有感触,漓江的水清水静水绿,漓江的山奇山秀山险。无不让人想看了再看。<br /><br />一上船,别的游客已站在甲板指指点点,兴味盎然,我还坐在船仓,以为船还没动呢,何必到外边吹风。那知,许多游客都涌向外边,我才往下一看,船已在向前开了。你说水静不静呢?<br /><br />早晨,太阳慢慢升起来了,我走上了甲板。风还有一点微冷。远处的山清晰可见。一座山如马如猴如骆驼,如笔如柱如姑娘。我看更像一道道魏然的墨绿屏障。我们的船从山角游过,山角的岩石已被水日月的冲洗,形成了深深的凹痕,那陡峭的岩石犹如鬼斧神工所赐。其间上天用神来之笔描绘出一幅幅天然之作,特别是那九马画山,九匹马栩栩如生,有的人还没辨清,船已驰过了,只好看迎面而来的山山水水。<br /><br />到中午时分,江面船只接连驰来,大船都排起了一条长队。江边的竹伐有的向上,有的向下,都坐满了游人。好像一串长长的蚱蚂。两船相向驰来,这船的人同那船的人谁都不认识谁但都挥手示好,那是愉悦的表现,这也给漓江美景增添了美色。</p></p>

</body>

</html>



4.Global.aspx.cs

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Threading;

using System.Globalization;

publicpartialclass Global : System.Web.UI.Page

{

protectedvoid Page_Load(object sender, EventArgs e)

{

}

protectedoverridevoid InitializeCulture()

{

if (Request.Form["DropDownList1"] != null)

{

string str = Request.Form["DropDownList1"].ToString();

this.UICulture = str;

this.Culture = str;

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(str);

Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(str);

}

base.InitializeCulture();

}

}




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI