.net中多语言资源的访问(使用assemble和卫星assemble的方法)

来源:互联网 发布:java判断stringbuffer 编辑:程序博客网 时间:2024/06/03 22:53
!WebApplication1.cs!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Resources;
using System.Reflection;
using System.Threading;


namespace WebApplication1
{

    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox TextBox1;
   
        private void Page_Load(object sender, System.EventArgs e)
        {


            CultureInfo ci = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentUICulture = ci;

            String AssemblyPath = "string";

            Assembly asm = Assembly.Load(AssemblyPath);

            ResourceManager rm = new ResourceManager("string",asm);

            TextBox1.Text = rm.GetString("txtGreeting");
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
       
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {   
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}
 
compile.bat
echo on

RM string.resources
RM string.ja-JP.resources


RM string.dll
RM ja-JP/string.resources.dll


resgen string.txt
resgen string.ja-JP.txt


al /out:string.dll /embed:string.resources
al /t:lib /culture:ja-JP /embed:string.ja-JP.resources /out:ja-JP/string.resources.dll

PAUSE
原创粉丝点击