简体   繁体   English

多语言应用程序,Microsoft Visual Studio?

[英]Multi-lingual application, Microsoft Visual Studio?

I developed a web application and it is a dynamic site. 我开发了一个Web应用程序,它是一个动态网站。 Can I place a multilingual option for my site? 我可以为我的网站放置多语言选项吗?

If yes, are there any plugins for that? 如果是,那是否有任何插件? How can I go further to develop a multilingual application? 如何进一步开发多语言应用程序?

We have the DropdownList control. 我们有DropdownList控件。 On its SelectedIndexChanged event, it postbacks and we then change the site culture, and it then loads the respective resource files... 在其SelectedIndexChanged事件上,它回发,然后我们更改站点区域,然后加载相应的资源文件...

DropDownList ASP.NET Code 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>

Common class inherited by all of the web pages 所有网页继承的通用类

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);
    }
}

Extension Method (just for sake of information) 扩展方法(仅供参考)

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

Please review these link before starting to implement: 在开始实施之前,请查看以下链接:

  1. Globalization Architecture 全球化架构
  2. [jQuery globalization tricks used in ASP.NET MVC] which can be helpful in ASP.NET also. [ASP.NET MVC中使用的jQuery全球化技巧]在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 如何在ASP.NET中创建和使用全局语言资源

These make all of your pages to use inherit from the languagebase class as below: 这些使您要使用的所有页面都继承自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)
    {
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 分割多语言字符串 - Splitting a multi-lingual string 如何创建多语言网站 - How to create a multi-lingual site 多语言ASP.NET网站的动态生成句子 - Dynamically Generated Sentences for Multi-Lingual ASP.NET Website ASP.NET MVC4多语言数据注释 - ASP.NET MVC4 Multi-lingual Data Annotations InfoPath无法启动Microsoft Visual Studio Tools for Application - InfoPath cannot start Microsoft Visual Studio Tools for Application 可以通过Microsoft Visual Studio访问IBM Lotus Notes应用程序吗? - Will IBM Lotus Notes Application can be accessed through Microsoft Visual Studio ? 一个国家的多语言网站 - Multi lingual site for one country Microsoft Visual Studio 中的引用不起作用 - References in Microsoft Visual Studio not working Microsoft Bot应用程序模板在Visual Studio 2017中不可见。如何添加Bot应用程序模板? - Microsoft bot application template is not visible in Visual studio 2017. How to add bot application template? 使用 Microsoft Visual Studio 2013 和更新版本时,我应该使用什么来远程调试应用程序 - What should I use to debug an application remotely when using Microsoft Visual Studio 2013 and newer versions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM