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

3

17

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

Jurisdiction answered 8/10, 2010 at 20:39 Comment(1)
I wouldn't recommend this way of providing localization. It is far from easy, but for such demands I would probably create some Resource Facade which will be single point of decision on what strings to load at runtime.Annamarieannamese
E
2
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();
    }
Echevarria answered 17/6, 2011 at 7:38 Comment(0)
M
2

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

Mezuzah answered 15/11, 2011 at 15:23 Comment(0)
B
1

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.

Besetting answered 9/10, 2010 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.