人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

February 5, 2007

在Client JavaScript中支持多语言

Filed under: ASP.NET

一个小小的Trick:
在server端读出语言相关的字符串资源并注入到client端:
System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append(”<script type=’text/javascript’>”);
sb.Append(”var I18N = new Array();\n”);
sb.AppendFormat(”I18N[’{0}’] = ‘{1}’;\n”, “my_String_1″, GetResourceString(”my_String_1″));
sb.AppendFormat(”I18N[’{0}’] = ‘{1}’;\n”, “my_String_2″, GetResourceString(”my_String_2″));
sb.Append(”</script>”);

ClientScript.RegisterClientScriptBlock(GetType(), “I18N”, sb.ToString());

在客户端进行读取:
function getI18N(resourceId)
{

return I18N[resourceId];

}

var myString1 = getI18N(”myString_1″))

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2007/02/05/p214/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham