Click here to Skip to main content
14,382,347 members

Multi-lingual Resource file generator using the Google Translation API

Rate this:
4.86 (16 votes)
Please Sign up or sign in to vote.
4.86 (16 votes)
23 Apr 2009CPOL
This is a command line utility for generating Japanese and French resource files from English using the Google Translation API.


This utility is developed to generate Japanese and French resource files from default resource files of an ASP.NET web page or user control. This utility is for translating resource files using the Google translation API.

Before running this utility, create a folder "conversion" in your c: drive and put all your default resource files (.resx) within the folder.


Couple of days back, my team was working on converting my applications for multiple languages (English, French, and Japanese) to address audiences of different regions. Enabling an ASPX page and user control (.ascx) for multiple languages is very easy, and for doing so, we need to maintain resource files (*.resx) for each and every language, and easily generate resource file(s).

To generate a resource file, open the ASPX (or ASCX) page in Design mode, then go to Tools-->Generate Local resource. Now, we will have a default resource file, like Webform1.aspx.resx. Now we need to create for French and Webform1.aspx.ja.resx for Japanese.

For translating any string, go to the Google language translation page:

I own around 40 applications, a lot of dashboards (user controls), and a huge portal application. For me, this would be a very tiresome method for language translation. So, I have developed a console utility for it. You have to create a folder "conversion" under your c drive and put all your default RESX files in it.

Code Discussion

I search for all RESX files in c:\Converion and create Japanese and French RESX files, and each file is translated by calling the Dotranslation function.

foreach (string file in files)
    Program _p = new Program();
    Console.WriteLine("Conversion of file started: {0} {1}", 
                      file, " to Japanese");
    _p.DoTranslation(Google.API.Language.Japanese, file);
    Console.WriteLine("Conversion of file completed.");
    Console.WriteLine("Conversion of file started: {0} {1}", 
                      file, " to French");
    _p.DoTranslation(Google.API.Language.French, file);
    Console.WriteLine("Conversion of file completed.");

In the DoTranslation function, I pass the language of type Google.API.Language and the default resource file. I open a .resx file by using XmlDocument and read all data nodes. Each data node again gets iterated to get the child nodes. A node value is translated using the Translate function of the Translate class of the Google API. I have attached GoogleTranslateAPI.dll, provided by Google-api-for-dotnet.

protected void DoTranslation(Google.API.Language language, string resxFilePath)
    XmlDocument doc = new XmlDocument();
    XmlNodeList dataNodes = doc.SelectNodes("//root/data");

    using (ResXResourceReader rr = new ResXResourceReader(resxFilePath))
       //New resx file
        string outputFilePath = resxFilePath.Replace("resx", "") + 
               language.ToString().Substring(0, 2).ToLower() + ".resx";

        using (ResXResourceWriter rw = new ResXResourceWriter(outputFilePath))
            IDictionaryEnumerator di = rr.GetEnumerator();

            foreach (DictionaryEntry de in rr)
                string key = de.Key as string;
                string value = de.Value as string;
                   //ignore emply keys
                if (!String.IsNullOrEmpty(key) && 

                    //translation using google translation api
                    string translatedValue = Translator.Translate(value, 
                           Google.API.Language.English, language);
                    rw.AddResource(key, translatedValue);
Utility screenshot:

Image 1

Points of Interest

This is a very small utility, but saves a lot of time when a large enterprise web application needs to be converted for multi-lingual support.


  • Uploaded on April 23, 2009.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Aneesur Rehman Khan
Team Leader
India India
Anees is working as Sr. Team Lead based in Delhi(India).He is Post graduated in Computer applications and science.

He is having around 11 years of design,analysis and coding experience in Sharepoint, ASP.NET, C#, VB.NET, SQL Server 2000/05, Reporting Services,Analysis Services,VB 6.0 and Crystal Reports.

Comments and Discussions

QuestionReally very useful ...but How to use this for other languages Pin
Member 102776468-Feb-14 5:54
professionalMember 102776468-Feb-14 5:54 
GeneralGoogle.Api.Translate option is not coming Pin
Rachna latiyan19-May-10 22:17
memberRachna latiyan19-May-10 22:17 
Generalits giving English output for Spanish laguage Pin
vijendraAver12325-Sep-09 2:43
membervijendraAver12325-Sep-09 2:43 
GeneralRe: its giving English output for Spanish laguage Pin
Aneesur Rehman Khan25-Sep-09 2:54
memberAneesur Rehman Khan25-Sep-09 2:54 
GeneralMy vote of 2 Pin
OPerttilä30-Apr-09 2:38
memberOPerttil√§30-Apr-09 2:38 
GeneralRe: My vote of 2 Pin
Troy Tamas7-May-12 20:10
memberTroy Tamas7-May-12 20:10 
Generalvery interesting Pin
Jeff Circeo27-Apr-09 22:39
memberJeff Circeo27-Apr-09 22:39 
Generalcool Pin
radioman.lt23-Apr-09 21:05
memberradioman.lt23-Apr-09 21:05 
GeneralAgainst Google TOS Pin
Michael Teper23-Apr-09 17:06
memberMichael Teper23-Apr-09 17:06 
GeneralWarning: quality Pin
Mihai Nita23-Apr-09 7:35
memberMihai Nita23-Apr-09 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 23 Apr 2009


45 bookmarked