本文介绍了本地化asp.net网站与一个全球资源构成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个一些资源文件是这样的:

  Mui.resx
Mui.fr.resx
Mui.es.resx
...

和我希望能够在我的codebehind是这样做的:

  Label1.Text = Mui.Hello;

在我的aspx是这样的:

 <%= Mui.Hello%GT;

有人知道如何做到这一点?这可能吗?


解决方案

是的,它是可能的。您可以从文件 - 新建 - 资源添加资源文件文件有你想要的英文或其他语言,您可以添加自己的资源键和值,

检查这些
并的

  • Get the resource using the following syntax:

    String welcome;
    welcome = Resources.WebResources.WelcomeText;
    

    Check the section Explicit Localization with ASP.NET on the link above.

    Example:

    label's text attribute now has an explicit expression stating the base file from which to retrieve the resource and the key to select.

    <asp:Label ID="Label2" Runat="server" Text="<%$ Resources:LocalizedText, Msg1 %>">
    

    And on your page:Simple call with full path of resource key.

    Check this great article - Resources and Localization that will explain you more about this.

    Edit- Web.Config Culture Settings:
    Add this
    <globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/> in web.config under <system.web>

    If you want it on some pages then use <@Page> directive's Culture and UICulture attributes.

    这篇关于本地化asp.net网站与一个全球资源构成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 20:17