隨着互聯網的發展日益壯大和活躍,網上購物交易愈來愈頻繁,一個網站支持多種語言在所不免,因此國際化和本地化在如今的網站中的做用愈來愈大,一個網站的使用量和搜索量有可能受國際化的影響一點。因此在當今作一個網站支持國際化和本地化很是重要。不只網站,任何一個產品,若是支持國際化,那麼他的使用價值就打打的提升了,全部下面我說一下怎麼給一個網站作國際化和本地化,Windows Forms 怎麼作國際化和本地化。web
Asp.net 網站國際化windows
1. 新建一個Asp.net web 程序 ,而後添加一個web頁面,如Login.aspx,而後在項目上右擊add,添加Asp.net Fold 下面就由App_LocalResources 和 App_GlobalResouces,通常添加App_LocalResources,而後再在這個fold 下面添加資源文件,若是你想支持中文,就添加Login.aspx.zh-CN.resx, 若是你想支持英文,就添加Login.aspx.en-US.resx,添加好了以後就去給這幾個資源文件中加入須要支持中英文的控件,如圖所示:瀏覽器
名稱這一列至關於key值,後面的是value,key值是控件的ID和控件要顯示的屬性。網站
在aspx頁面須要以下代碼:this
<%@ Page Language="C#" AutoEventWireup="true" UICulture="Auto" Culture ="Auto" CodeBehind="Login.aspx.cs" Inherits="GlobalizationTest.Login" %>.net
<div>
<br />
<asp:Label ID="lblName" runat="server" Text="" meta:resourcekey="lblName"></asp:Label>
<br />
<asp:Button ID="btnSave" runat="server" Text="" meta:resourcekey="btnSave" />
<br />orm
前面是一種方式server
這是第二種方式:
<asp:Button ID="btnCancel" runat="server" Text="<%$ Resources:btnCancel.Text %>" />
</div>blog
而後運行此頁面,以後修改瀏覽器的語言,就能夠看到不一樣的語言下的網頁內容。資源
Windows Forms 國際化
1.新建一個windows forms 項目,而後自動生成一個form1 的窗體, 而後如同上面添加幾個不一樣的資源文件,裏面值和上面的同樣,如後在Form1.Designer.cs文件中修改對應的控件的屬性,將顯示屬性所有爲空,
//
// button1
//
this.button1.Location = new System.Drawing.Point(43, 151);
this.button1.Name = "btnSave";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 3;
this.button1.Text = "";
this.button1.UseVisualStyleBackColor = true;
而後在Form1.cs文件中加入一個Combox用來選擇不一樣的語言,Combox 的項能夠手動輸入,也能夠用代碼寫,
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(comboBox1.Text);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(comboBox1.Text);
ApplyResource();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 1;
}
private void ApplyResource()
{
System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(Form1));
foreach (Control ctl in Controls)
{
res.ApplyResources(ctl, ctl.Name);
}
}
這樣在運行起來以後能夠選擇不一樣的語言顯示不一樣的語言的內容。