当使用自定义文化的ResourceManager没有选择正确的资

当使用自定义文化的ResourceManager没有选择正确的资

本文介绍了当使用自定义文化的ResourceManager没有选择正确的资源集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用code本地化的MVC网站上发现的。

I have created a localized MVC website using the code found on this blog by Alex Adamyan.

这是伟大的工作,如果我使用现有的文化。不过,我想本地化为他加禄语(TL或TL-PH)。 Windows没有这种文化内置的,所以我已创建了一个(我曾经尝试都TL与TL-PH),按下面的code:

This is working great if I use an existing culture. However, I am trying to localize for Tagalog (tl or tl-PH). Windows does not have this culture built in so I have created one (I have tried both tl and tl-PH) as per the code below:

public static void CreateCustomCultures()

{

    var cultureBuilder = new CultureAndRegionInfoBuilder(
                            "tl", CultureAndRegionModifiers.Neutral);

    cultureBuilder.LoadDataFromCultureInfo(new CultureInfo("en-US"));
    cultureBuilder.LoadDataFromRegionInfo(new RegionInfo("US"));
    cultureBuilder.IsMetric = true;
    cultureBuilder.CultureEnglishName = "Tagalog";
    cultureBuilder.CultureNativeName = "Tagalog";
    cultureBuilder.RegionEnglishName = "Tagalog";
    cultureBuilder.RegionNativeName = "Tagalog";
    cultureBuilder.TwoLetterISOLanguageName = "tl";
    cultureBuilder.ThreeLetterISORegionName = "PH";
    cultureBuilder.Register();

    var cultureBuilder2 = new CultureAndRegionInfoBuilder(
                            "tl-PH", CultureAndRegionModifiers.None);

    cultureBuilder2.LoadDataFromCultureInfo(new CultureInfo("en-US"));
    cultureBuilder2.LoadDataFromRegionInfo(new RegionInfo("US"));
    cultureBuilder2.IsMetric = true;
    cultureBuilder2.CultureEnglishName = "Tagalog";
    cultureBuilder2.CultureNativeName = "Tagalog";
    cultureBuilder2.RegionEnglishName = "Tagalog";
    cultureBuilder2.RegionNativeName = "Tagalog";
    cultureBuilder2.TwoLetterISOLanguageName = "tl";
    cultureBuilder2.ThreeLetterISORegionName = "PH";
    cultureBuilder2.Register();

}

我也有我的测试场地位于〜/查看/首页/资源四个资源文件:

I also have four resource files on my test site located in ~/Views/Home/Resources:

  • Home.aspx.resx;
  • Home.aspx.tl.resx
  • Home.aspx.tl-PH.resx
  • Home.aspx.de.resx

当我建,我让我的bin目录在三个适当命名的目录,每一个适当命名的DLL。

When I build, I get three appropriately named directories under my bin directory, each with a an appropriately named dll.

所以,当我去我的网站首页的http://本地主机:1907年我得到默认的(英文),语言字符串。

So when I go to my website home page http://localhost:1907 I get the default (english) language strings.

当我去德国(DE)主页的http://本地主机:1907 /德我得到德国版的网站。

When I go to the german (de) home page http://localhost:1907/de I get the german version of the site.

当我去他加禄语版本的http://本地主机:1907 / TL 或的,我得到的英文版本,而不是他加禄语版本。

When I go to the tagalog versions http://localhost:1907/tl or http://localhost:1907/tl-PH, I get the english version instead of the Tagalog version.

我已经把断点在资源获取code,并确认了当前线程的文化和UI文化设置正确的菲律宾语文化和他加禄语是传递给resourceManager.GetString文化(键,文化)

I have placed breakpoints in the resource fetching code and have confirmed that the current thread's culture and UI culture are correctly set to the Tagalog culture and that Tagalog is the culture being passed to resourceManager.GetString(key, culture).

有什么想法?难道我没有正确地创建我的文化?

Any thoughts? Did I not create my cultures correctly?

推荐答案

我觉得你的文化是永远不会注册,其中至少有一个是没有的。

I think your cultures are never registered, at least one of them isn't.

在code以下将抛出一个异常,因为你不能为一个区域性指定区域的值。就像你不能为一个中立的文化创建的DateTimeFormatInfo对象。

The code below will throw an exception since you cannot specify regional values for a neutral culture. Just like you cannot create a DateTimeFormatInfo object for a neutral culture.

var cultureBuilder = new CultureAndRegionInfoBuilder(
                        "tl", CultureAndRegionModifiers.Neutral);

cultureBuilder.LoadDataFromCultureInfo(new CultureInfo("en-US"));
cultureBuilder.LoadDataFromRegionInfo(new RegionInfo("US"));
cultureBuilder.IsMetric = true;
cultureBuilder.CultureEnglishName = "Tagalog";
cultureBuilder.CultureNativeName = "Tagalog";
cultureBuilder.RegionEnglishName = "Tagalog";
cultureBuilder.RegionNativeName = "Tagalog";
cultureBuilder.TwoLetterISOLanguageName = "tl";
cultureBuilder.ThreeLetterISORegionName = "PH";
cultureBuilder.Register();

这应该是这样的。

It should be something like this

var cultureBuilder = new CultureAndRegionInfoBuilder(
                        "tl", CultureAndRegionModifiers.Neutral);

cultureBuilder.LoadDataFromCultureInfo(new CultureInfo("en-US"));
cultureBuilder.CultureEnglishName = "Tagalog";
cultureBuilder.CultureNativeName = "Tagalog";
cultureBuilder.TwoLetterISOLanguageName = "tl";
cultureBuilder.Register();

第二个具体的文化似乎好了。

The second specific culture seems alright.

这篇关于当使用自定义文化的ResourceManager没有选择正确的资源集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:12