2011-10-18 74 views
0

我開發了一個Web應用程序,它是一個動態網站。我可以爲我的網站放置多語言選項嗎?多語言應用程序,Microsoft Visual Studio?

如果是,是否有插件?我怎樣才能進一步開發多語言應用程序?

+0

指http://stackoverflow.com/questions/256229/多語種網絡應用程序如何做我檢測用戶語言在ASP網 –

回答

0

我們有DropdownList控件。在其SelectedIndexChanged事件,這回發然後我們改變網站的文化,然後加載相應的資源文件...

DropDownList的ASP.NET代碼

<asp:DropDownList ID="ddlLanguage" runat="server" CssClass="select-language" AutoPostBack="true"> 
    <asp:ListItem Value="en-US" Text="English" title="/images/Flag_USA.gif"></asp:ListItem> 
    <asp:ListItem Value="it-IT" Text="Italiano" title="/images/Flag_Italian.gif"></asp:ListItem> 
    <asp:ListItem Value="fr-FR" Text="Française" title="/images/Flag_French.gif"></asp:ListItem> 
</asp:DropDownList> 

通用類的所有繼承的網頁

using System; 
using System.Web; 
using System.Threading; 
using System.Globalization; 

public class languagebase : System.Web.UI.Page 
{ 
    protected override void InitializeCulture() 
    { 
     try 
     { 
      string LanguageCode = Request["ctl00$ucMenu$ddlLanguage"]; // Language Drop Down Control in Front End 
      if (!LanguageCode.IsNullOrEmpty()) 
      { 
       setCulture(LanguageCode); // Set Culture language from drop down 
       Request.Cookies["LanguageCode"].Value = LanguageCode; // Update REQUEST Cookie language from drop down 
       SetCookies(LanguageCode); // Set Cookie language from drop down 
      } 
     } 
     catch(Exception ex) 
     { 
      setCulture("en-US"); // Set default language 
      Request.Cookies["LanguageCode"].Value = "en-US"; // Update REQUEST Cookie language to default 
      SetCookies("en-US"); // Set default language 
     } 
     base.InitializeCulture(); 
    } 

    private static void setCulture(string LanguageValue) 
    { 
     Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageValue); 
     Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(LanguageValue); 
    } 

    public void SetCookies(string strLanguage) 
    { 
     System.Web.HttpContext.Current.Response.Cookies["LanguageCode"].Value = strLanguage; 
     System.Web.HttpContext.Current.Response.Cookies["LanguageCode"].Expires = DateTime.Now.AddDays(15); 
    } 
} 

擴展方法(只爲信息的緣故)

public static Boolean IsNullOrEmpty(this String original) 
{ 
    return string.IsNullOrEmpty(original); 
} 

請開始實施前審查這些鏈接:

  1. Globalization Architecture
  2. [jQuery的全球化在ASP.NET MVC使用技巧]可以在ASP.NET是有益也。
  3. My question here defines the way to implement multi-language code
  4. How to create and use Global language resources in ASP.NET

這讓所有的頁面使用來自languagebase類,如下繼承:

using System; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class Default : languagebase 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
    } 
} 
+0

謝謝你,我會盡力讓你知道這一點。 –

+0

它給出了一個錯誤:找不到合適的方法覆蓋 –

+0

在我的答案中的哪個代碼點? –