如何在asp.net中的多语言网站上翻译按钮上的文本

时间:2016-06-12 05:53:43

标签: asp.net translate resx

我正在开发一个asp.net Website.I有Resource.resx文件来翻译网站的术语。当我使用Text ='<%#Resources.Resource。ارسال%>'时,我想将按钮文本翻译成英语和波斯语。对于文本它不起作用,并且不显示文本。

{{1}}

1 个答案:

答案 0 :(得分:1)

  1. 右键单击项目 - >添加 - >添加ASP.NET文件夹 - > App_GlobalResources文件
  2. 将两个资源文件添加到此文件夹,一个用于英语,另一个用于波斯语。我使用英语和法语。英语是默认语言,法语资源文件名为 Resource.fr.resx 。这个名称很重要,所以请确保用波斯文化命名你的名字。
  3. Adding App_GlobalResources to project

    1. 更改按钮标记以从资源文件中获取文本:
    2. 像这样:

      <asp:Button ID="Button1" runat="server" Text="<%$ Resources:Resource, Button1 %>" />
      
      1. 覆盖后面代码中的InitializeCulture()方法,并根据查看Web应用程序的用户类型设置区域性。
      2. 像这样:

        public partial class GlobalizationExample : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
        
            }
        
            protected override void InitializeCulture()
            {
                //Get the language that the client prefers from the browser
                string preferredLanguage = Request.UserLanguages[0];
        
                //Set the language for the page
                System.Threading.Thread.CurrentThread.CurrentUICulture = 
                    new System.Globalization.CultureInfo(preferredLanguage);
        
                System.Threading.Thread.CurrentThread.CurrentCulture =
                   System.Globalization.CultureInfo.CreateSpecificCulture(preferredLanguage);
            }
        }
        

        如果上述内容无法帮助您here,那么这是一个关于在ASP.NET中应用全球化的不同方式的精彩视频。