8
votes

Ive been using C#s (Visual Studios) resourcing mechanism and its worked nicely. I have a need to be able to use resources but instead of using CultureInfo as the determinator use something else. This is my current setup which works fine however I have to workout which Resource Manager to use. Either Brussels or Paris. The Resource Manager then works out which resource to use within Brussels or Paris to invoke. What I want is one resource manager for both, so I dont need to decide which resource manager to use. Part of the problem is the PublicResXFileCodeGenerator Custom Tool generates the code for you (which is very nice if you use the standard approach)

This is what it currently looks like (This is working fine)

Brussels Resources

  • brussels.en-GB.resx
  • brussels.ja-JP.resx
  • brussels.fr-FR.resx
  • brussels.resx

Paris

  • paris.en-GB.resx
  • paris.ja-JP.resx
  • paris.fr-FR.resx
  • paris.resx

I dont want to use the CultureInfo but instead specify my own resx identifier. Is there a way to do this using resx file?

etc

Brussels and Paris Resources

  • MyResourceManager.brussels-en-GB.resx
  • MyResourceManager.brussels-ja-JP.resx
  • MyResourceManager.brussels-fr-FR.resx
  • MyResourceManager.paris-en-GB.resx
  • MyResourceManager.paris-ja-JP.resx
  • MyResourceManager.paris-fr-FR.resx
  • MyResourceManager.resx

EDIT: An example of how I would like to use it (or something similar)

MyResourceManager.Header

instead of

brussels.Header

paris.Header

An example of a similar problem but solved through Custom Cultures can be found here. How to load different RESX files based on some parameter I dont want to do this however as installing cultures on different machines is not an option.

1
Could you please provide a specific example of the result you want? (It seems a little odd to be saying that you don't want to consider the culture when you have culture-specific resources for each of the Brussels and Paris resource sets.)Nicole Calinoiu
Do you have a lot of these to do, or just one?Nicole Calinoiu
@NicoleCalinoiu would you please clarify what you mean by "a lot of these"?Jonathan
Do you have the same sort of scenario repeated many times, or is this a one-off thing for cities (or whatever Brussels and Paris represent)? I'm trying to figure out if you need a generalized implementation or something specific to your cities case.Nicole Calinoiu
Just for Paris (English, Japanese, French) and Brussels (English, Japanese, French). I implemented two seperate resource managers which did the trick and loaded them based on my routing information.Jonathan

1 Answers

1
votes

Use CultureInfo to determine the resource set to load, it will be easier since it integrates into the Thread.CurrentUICulture.

If you have cultures that are not standard out of the box supported cultures, use CultureAndRegionInfoBuilder to build any additional cultures that you need. See http://msdn.microsoft.com/en-us/library/system.globalization.cultureandregioninfobuilder.aspx. There should be ample StackOverflow examples of using this API, i.e. Create custom culture in ASP.NET.