ASP.NET - A complete translation framework through Powershell and Google Translate

In this blog post, I present a complete framework for automatic localization in ASP.NET, ability to customize what is produced by this framework and a completely functional ASP.NET app demonstrating the features and process.

In February this year, I published my Powershell scripts that perform much of the processing required for localization in ASP.NET. If you have not already done so, it would be useful (but not required) to go through that blog post once:
ASP.NET - Using Powershell and Google Translate to provide automatic localization

In a nut-shell, those scripts:

  1. Go through your .aspx/.ascx files and add meta:resourcekey attributes to eligible tags.
  2. Create primary resource (.resx) files by extracting translatable attributes to these files from .aspx/.ascx files.
  3. Create secondary resource files for the desired locales you want to support in your ASP.NET application.
  4. Use Google Translate to automatically provide string translations in the secondary resource files.
  5. Extract translatable strings from javascript files.
  6. Create resource files again and provide automatic translation for these javascript strings through resource files.
  7. Create new javascript files (e.g. myfile.fr.js) which you can include on the page and your javascript strings wrapped in Rahul.t method call become translatable automatically.

The clients for whom I originally created this entire infrastructure was pretty happy with what they got and the time we delivered it in. But hey, the world is not enough... They soon got back to us saying it works great, but is it possible for us to override strings you show in the UI.

We said why not, and we added the ability for them to customize strings in resource files. Custom TranslationFor this, I added an ASP.NET page called CustomTranslation.aspx that uses an ExtJs TreePanel to list all resource files in the application. When you click on a Tree node, all the strings in it are shown on the right-hand side in a grid (see screenshot) where the first column shows the string in English (read-only) and the second column is an editable one where you can override the string in desired locale.

Lately some people contacted me personally after reading my earlier blog post requesting if I can post a stand-alone functional sample for my framework. And I got an opportunity for that couple of hours back.

So I have now created a complete sample asp.net application (attached below) that allows you to test my translation framework, customize it and do all sorts of things you can imagine.

There are 3 simple steps you need to do to get started with using it:

  1. Download the attached sample application, extract it and configure it in IIS. you can use it with Visual Studio's built-in Cassini web-server also.
  2. Open "resources\localize\Controller.ps1" file from the attached code. On 5th line, update the application's path.
  3. Open "resources\localize\GTranslate.ps1" file and on third line, update your Google Translate's API key. You can generate the same from here: https://code.google.com/apis/console/

That is it, you are ready now. Right-click "resources\localize\Controller.ps1" and select "Execute with Powershel". Or open a Powershell window and execute it from there. I would recommend opening a Powershell window because the scripts produce a detailed log of what they are doing and you would be able to see the same on the shell window. Right-clicking and executing the script would close the Powershell window once execution is complete not giving you a chance to analyze the log.

You might want to create a copy of your application before running the scripts over them. After you run the scripts, you might want to diff the entire directory over which the scripts were run using either your Version Control System's integrated Diff viewer or an external Diff'ing program (KDiff is a good choice). I would atleast advise you to start with the attached sample application, creates its copy, run the scripts over the copy and then compare the copied directory with the original one to have a good idea on what these scripts do and what changes you should expect. Recall they change your aspx/ascx files also.

The scripts allow many customization and extension points to control the automatic translation behavior. To understand what each script does, and what all options are available, please read the original blog post where these scripts were posted:
ASP.NET - Using Powershell and Google Translate to provide automatic localization

In case of any issues, feel free to use the comment form below.

 

AttachmentSize
Package icon asp.net-localization.zip4.19 MB