asp.net
  • translate
  • resx
  • 2016-06-12 34 views 1 likes 
    1

    我正在开发一个asp.net网站。我有Resource.resx文件来翻译网站的术语。每一件事情都没问题,我想在使用Text ='<%#Resources.Resource。ارسال%>'时将按钮文本翻译为英文和波斯文,因为它不工作,并且不会显示文本。请帮助我解决这个问题如何在asp.net中的多语言网站上的按钮翻译文本

    <asp:Button ID="Button1" runat="server" Text='<%#Resources.Resource.ارسال %>' Width="94px" CssClass="btn btn-primary" OnClick="Button1_Click" /> 
    

    回答

    1
    1. 右键项目 - >添加 - >添加ASP.NET文件夹 - > App_GlobalResources文件
    2. 两种资源文件添加到该文件夹​​,一个是英语,另一个用于波斯语。我使用的是英文和法文。英文是默认文件,法文资源文件名为Resource.fr.resx。这个名字很重要,因此请确保您使用波斯文化来命名您的文件。

    Adding App_GlobalResources to project

  • 更改您的按钮标记来获取从资源文件中的文本:
  • 像这样:

    <asp:Button ID="Button1" runat="server" Text="<%$ Resources:Resource, Button1 %>" /> 
    
    1. 覆盖代码背后的InitializeCulture()方法,并根据哪种类型用户正在查看该Web应用程序。

    像这样:

    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应用全球化不同的方式一个伟大的视频。

    相关问题