Search code examples
c#xmlglobalization

Globalization of configuration files


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!


Solution

  • 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.