开发者

What is the recommend way to create a custom culture and associated resource files for a specific Client?

开发者 https://www.devze.com 2023-01-19 19:50 出处:网络
I have client that wants to specifiy their own version of localized content for a subset of my string resources.

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


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();
    }


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号