Jonathan
Jonathan

Reputation: 2358

CultureInfo and (resx) Resource Files

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.

Upvotes: 8

Views: 6319

Answers (1)

Shan Plourde
Shan Plourde

Reputation: 8726

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.

Upvotes: 1

Related Questions