Last post Jun 27, 2008 01:30 PM by Tom_Regan
Jun 26, 2008 04:28 PM|Tom_Regan|LINK
Is there any way to use implicit localization (eg meta:ResourceKey="KeyInLocalResourceFile") AND select the particular resource file at run time?
We were tasked with creating a "generic," multi-lingual website that a number of different customers will use. We chose implicit localization. Now customers are coming back with the demand to customize the text for this, that, and the other control.
I don't want to abandon impliicit localization; I don't want to go back into the code and remove all of my "meta:ResourceKey" attributes and instead set the .Text and other properties explicity with a call to GetLocalResourceObject(). I know I can do that,
but I don't want to.
I would rather be able to leave all the "meta:ResourceKey" attributes alone, and instead choose an entirely different .resx file based upon some criteria I discover at runtime.
Is that possible? I'm guessing not. I'm guessing that the resource file is loaded before any Page event fires, and that in any case there is no way to override the choice of a resource file. I'd love to be wrong though!
Jun 27, 2008 01:30 PM|Tom_Regan|LINK
To answer my own question--what I need is a custom culture. In my case I'm basing my custom culture on United States English (en-US), which is the default for my web site. I'm then going to create new custom cultures with custom region names (en-AA, en-BB
and etc). When a customer who wants customized text visits my web site I'll set
Thread.CurrentThread.CurrentCulture/CurrentUICulture to the appropriate custom culture in the Page InitializeCulture event.
Here is how to register a custom culture on a machine. The "Save" call is not necessary, it simply saves the properties of the culture to an xml file. The CultureAndRegionInfoBuilder object has many more properties that can be set, but for
my purposes the only things I need to set are the Language and Region names.
builder.CultureEnglishName = ci.DisplayName.Replace(ri.DisplayName, txtNewRegionName.Text);
builder.CultureNativeName = ci.NativeName.Replace(ri.NativeName, txtNewRegionName.Text);
builder.RegionEnglishName = txtNewRegionName.Text;
builder.RegionNativeName = txtNewRegionName.Text;