Martin Normark's blog

Posted on by Martin Normark


Yesterday, I blogged about how you can use Google Translate to translate a string in C#. To make it more useful than just a simple translator, and because I need to translate some Global Resource files for an E-commerce website that I’m working on, I wanted to create a small Windows Application in C# that could read a Global Resource file (.resx) and translate it into a selected language using the method for translating a word in C# that i blogged about yesterday.

image

This is how it looks so far. You simply select the resource file you want to translate. Select the current language of the resource file in the middle box, and select the language you want to translate it to in the last box. Click Translate at it should work. The new resource file will be saved in the same location as the application itself.

About the author

Martin Normark Martin Normark works as a freelance web developer (consultant). He blogs about web, software and programming experiments, daily code battles, specific How To posts and what else comes to mind.

Posted on by Martin Normark | Posted in C#, Internationalization | Tagged ,

  • Cwe

    Hi, I thought the same idea too about generating resx files for different languages using Google Translate but not sure how. It will be very helpful if you can post up the source code about the windows app that you are working on :)

  • Martin Normark

    You can download the app, including source code, through the link to my Sky Drive. At the bottom of the post – ResxTranslator.zip :)

  • Chad

    Nicely done Martin, that certainly makes things easier getting started with translations. I have one suggestion though…in the Translator class, set the proxy credentials on your web client. Many corporations use a proxy server to allow access to the Internet.

    Just one line in the using statement of Translator.TranslateText:
    [b]webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;[/b]
    and it’ll use the current Windows credentials to pass to the proxy.

    Thanks and great job!

  • http://martinnormark.com Martin H. Normark

    Hey Chad

    That makes a lot of sense. Thanks for your input.

  • Nazar Kotylo

    Awesome!
    Sometimes resources can contain images. But the working folder is different so ResXResourceReader throws an exception when trying to read .resx file (GetEnumerator). This happens if you have relative links to the image files.

    The solution to this is to set the current working directory as:

    using (ResXResourceReader rr = new ResXResourceReader(resxFilePath))
    {
    string outputFilePath = String.Format("{0}.{1}.{2}", Path.GetFileNameWithoutExtension(resxFilePath), toLanguageShortname, Path.GetExtension(resxFilePath));
    [b]System.Environment.CurrentDirectory = Path.GetDirectoryName(resxFilePath);[/b]