为特定客户创建自定义区域性和关联资源文件的推荐方法是什么?

发布于 2024-09-26 21:15:45 字数 744 浏览 0 评论 0原文

我的客户想要为我的字符串资源子集指定他们自己的本地化内容版本。

为简单起见,这里是基本示例:
假设我有 2 个本地化字符串(显示英文内容)
PageTitle="你好世界"
PageDescription="这是 Hello World 的更冗长的版本!"

我希望本地化这些,以便我有资源文件。

  • Strings.resx (包含我的英语 字符串)
  • Strings.fr-ca.resx (包含我的法语-加拿大字符串)
  • Strings.fr-ca-clientX.resx (包含 我的客户字符串是 法裔加拿大人,因此非常 挑剔;) - 只是开玩笑)

理想情况下,“Strings.fr-ca-clientX”只能指定他们想要“覆盖”的字符串。换句话说,他们可能只想更改 PageTitle 并继续使用“fr-ca”资源文件中的 PageDescription。

那么我该如何在 .NET 中解决这个问题呢?理想情况下,我只需创建 resx 文件并在“Web.config”中指定区域性,它应该可以工作......

<globalization uiCulture="fr-ca-clientX" culture="fr-ca-clientX" />

但是,这不起作用。 “标签包含无效的‘文化’属性值”是我的第一个障碍。

谢谢,
贾斯汀

I have client that wants to specifiy their own version of localized content for a subset of my string resources.

For simplicity here is basic example:
Lets say I have 2 localized strings (showing english content)

PageTitle="Hello World"

PageDescription="This is a more wordy version of Hello World!"

I wish to localize these so I have resource files.

  • Strings.resx (contains my English
    string)
  • Strings.fr-ca.resx
    (contains my French-Canadian strings)
  • Strings.fr-ca-clientX.resx (contains
    my strings for a Client whom is
    French-Canadian and therfore very
    picky;) - just joking)

Ideally "Strings.fr-ca-clientX" can specify only the strings they want to "override". In other words they may just wish to change the PageTitle and continue using the PageDescription from the "fr-ca" resource file.

So how do I go about this in .NET? Ideally I would just create the resx file and specify the culture in my "Web.config" and it should work...

<globalization uiCulture="fr-ca-clientX" culture="fr-ca-clientX" />

However, this does not work. "The tag contains an invalid value for the 'culture' attribute" is my first obsticle.

Thanks,

Justin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

平生欢 2024-10-03 21:15:45
public void AddCustomCulture(string cultureName, string baseCulture)
    {
        var cultureBuilder = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None);

        cultureBuilder.LoadDataFromCultureInfo(new CultureInfo(baseCulture));

        var region = baseCulture.Substring(3, 2);

        cultureBuilder.LoadDataFromRegionInfo(new RegionInfo(region));

        cultureBuilder.Register();
    }
public void AddCustomCulture(string cultureName, string baseCulture)
    {
        var cultureBuilder = new CultureAndRegionInfoBuilder(cultureName, CultureAndRegionModifiers.None);

        cultureBuilder.LoadDataFromCultureInfo(new CultureInfo(baseCulture));

        var region = baseCulture.Substring(3, 2);

        cultureBuilder.LoadDataFromRegionInfo(new RegionInfo(region));

        cultureBuilder.Register();
    }
溺深海 2024-10-03 21:15:45

您可以使用以下代码创建一种新的文化:

        //Get culture info based on Great Britain
        CultureInfo cultureInfo = new CultureInfo( "en-GB" );
        RegionInfo regionInfo = new RegionInfo( cultureInfo.Name );

        CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder( txtCultureName.Text, CultureAndRegionModifiers.None );

        cultureAndRegionInfoBuilder.LoadDataFromCultureInfo( cultureInfo );
        cultureAndRegionInfoBuilder.LoadDataFromRegionInfo( regionInfo );

        // Custom Changes
        cultureAndRegionInfoBuilder.CultureEnglishName = txtCultureName.Text;
        cultureAndRegionInfoBuilder.CultureNativeName = txtNativeName.Text;

        cultureAndRegionInfoBuilder.Register();

我已经写了一篇关于创建应用程序来执行此操作的帖子..

http://wraithnath.blogspot.com/search/label/Globalization

You can create a new culture with the following code:

        //Get culture info based on Great Britain
        CultureInfo cultureInfo = new CultureInfo( "en-GB" );
        RegionInfo regionInfo = new RegionInfo( cultureInfo.Name );

        CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder( txtCultureName.Text, CultureAndRegionModifiers.None );

        cultureAndRegionInfoBuilder.LoadDataFromCultureInfo( cultureInfo );
        cultureAndRegionInfoBuilder.LoadDataFromRegionInfo( regionInfo );

        // Custom Changes
        cultureAndRegionInfoBuilder.CultureEnglishName = txtCultureName.Text;
        cultureAndRegionInfoBuilder.CultureNativeName = txtNativeName.Text;

        cultureAndRegionInfoBuilder.Register();

I have written a post on creating an app to do just that..

http://wraithnath.blogspot.com/search/label/Globalization

作业与我同在 2024-10-03 21:15:45

您可能需要创建自己的文化并注册它。您可以在此处找到有关该主题的 MSDN 文章。

您不需要更改区域性属性,它应该保留在“fr-CA”,因为 uiCulture 属性负责从资源加载字符串。

You probably need to create your own culture and register it. You'll find MSDN article on that topic here.

You don't need to alter culture attribute, it should stay at "fr-CA", as uiCulture attribute is responsible for loading strings from resources.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文