views:

101

answers:

3

Hi,

I have multiple configuration files describing Addins to my system. I'm looking for a way to globalize some of the tags in the configuration file (i.e - support multiple languages)

for example: in the file activity.xml i want to globalize some of the attributes:

<?xml version="1.0" encoding="UTF-8"?>
<Resource
  type="Activity"
  id="123456.ConcatenateStrings"
  version="1.0.0"
  group="String Manipulation"
  shortName="$$Concatenate_Strings"
  description="$$Concatenates_Strings_Description"
  assembly="VTDBasicActivities.dll"
  className="ConcatenateStringsActivity"
  visible="true"> 
</Resource>

I want the values of some of the attributes (shotName, description) to be taken from a different configuration file (resx probably) where the values could be written in any language.

I need a way to mark the values of some attributes, so that the xml parser would know to take their value from a configuration file (in my example I wrote "$$" before those values)

what is the best way for doing this? I'm parsing the xml file with C#

Thanks!

A: 

You need to use resource files. See here: http://ondotnet.com/pub/a/dotnet/2002/09/30/manager.html

Konamiman
A: 

Use Resource files instead

Instead of providing the actual string in configuration, rather provide Resource key and keep strings in resource files with different translations. That's what Resource files are for and you should use them as well. Don't reinvent the wheel.

How Resources work (in a nutshell)?

Have Resources.resx with default translation that all non localised languages will default to. Then create separate resource files for each language you'd like to support:

Resources.sl.resx
Resources.en-ie.resx
Resources.de.resx
etc...

So when a spanish person would access your application they will get default language, Slovenians will get their own translation, so will Irish and German users... All of these files will have the same resource keys but provide different translations. All you need to do is to use these keys inside of your configuration file. Single one - language neutral.

Robert Koritnik
Hi,The thing is - I need a way to mark the value of a specific attribute so with some sort of tag that would indicate that the value should be taken from a resx file. for example:description = "$$description" (where $$description should reference me to a resx file)
Shai Rubinshtein
Your $$ notation could be fine but for the sake of maintainability it would probably be better to use something like `shortName="fromResource(ShortNameKey)"` and replace using RegEx. This way you'll know exactly where to look for the value even after a few years. With $$ you'll probably have to check your code how it works to make a change...
Robert Koritnik
I don't know if you're aware of this, but there are open source templating projects like **NVelocity** that could as well be used in this scenario.
Robert Koritnik
+1  A: 

From my conversations with my IT/Support friend. Typically configuration files are kept in English. Its not the most friendly solution, however the configuration mapping is specified information that is hard coded into the program its self. (The keys are, not the values)

Also you have to remember: The people who are working with the configuration file are typically informed users, so your user base that is modifying the files are smaller.

monksy
Exactly correct. This is why "translated" programming languages never took off.
Jeremy McGee
I'm kinda glad they didn't. Not all (natural languages) can handle it.
monksy