Internationalization with .NET

Posted by lorenb on 10/21/2004 in projects |

After a couple of false starts, I’m now ready to develop world-ready applications :) . The way things work is basically you have a text file with name/value pairs for strings:

testID = sst-2004-0001

You then use the program resgen to generate the resources file:

$ resgen testinfo.txt
Read in 4 resources from 'testinfo.txt'
Writing resource file... Done.

Typically you’d have one text file for each language that your program supports. Something like [basename].[countrycode].txt. Those would all be compiled into a single resource file.

Next, when you have compile the test you embed the resource file in the assembly:

$ /usr/bin/mcs -target:library -out:sst-2004-0001.dll ./main.cs AssemblyInfo.cs -r Sussen.Stf.dll -resource:testinfo.resources
Compilation succeeded

To use the resouces is pretty simple, for example:

Assembly a = Assembly.LoadFrom (testFilename);
ResourceManager rm = new ResourceManager("testinfo", a);
CultureInfo ci = new CultureInfo("en");
Console.WriteLine ("localized testID: " + rm.GetString ("testID", ci));

It’s similar to gettext if you’ve ever used that before.

Copyright © 2004-2010 LB Technology Services Blog All rights reserved.
Desk Mess Mirrored v1.7 theme from BuyNowShop.com.