Automated Translation Tool

You may remember that I had written a post back in September of 2014 titled, Automate Your Translations.  If you are not familiar with this, please take a moment to read it now.  In that blog post; I proposed that you could automate your translating tasks when you do your localization using Localization With Angular-GetText.  I talked about the old manual way of performing translations with a tool such as PoEdit.  Updating your translation files manually is fine while you are learning or during a simple correction, but there had to be a better way of doing it.

In that same blog post I talked about and automated way of doing it.  I was able to get a basic and approximate translation from an on-line translation service such as Bing Translator or Google Translate.  I recommended in that post that with a little bit of code to automate the process, you could be a lot more efficient.  In this way you can your basic translations done and move on to the more important business of building software.

Recently we’ve built an application that was an AngularJS web application on the front end but completely Microsoft C# Web API on the back end.  This solution worked really well for us but we discovered that using Angular-GetText left us without a server side solution.  We do at times need to generate a report and we would want to translate the labels and things where we can.  We fell back to Microsoft String Resource Files.  Microsoft has an entire framework written around  Globalizing and Localizing .NET Framework Applications.  If you haven’t read this yet, please take a moment to familiarize yourself with it.

I took the idea that I blogged about and wrote some code around it.  You can find that code on my GitHub repository here.  I created the Automated Translation Tool so that others could benefit from the work already done here instead of requiring them to roll their own solution.  The project was created to allow Visual Studio developers to globalize their software. easily. This tool creates automatic translations using an on-line translation service.  It was built to support the new AngularJS GetText string translation library and the existing Microsoft String resource file. It is able to get a basic and approximate translation from an on-line translation service.  This tool was created to help developers update their resource files and be more productive.

But Eric, I don’t want to pull the code down and compile it myself, host it somewhere and be responsible for it.  I just want to use it.

No problem, I am with you on this.  I recently had to remove my little homespun solution and formalize it and publish it out to the Microsoft NuGet server.  If you are not familiar with NuGet; it is the package manager for the Microsoft development platform including .NET.  The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers.

Universal-Translator
I published the Automated Translation Tool so that it can be used in your build scripts, etc.  Here is a direct link to the Automated Translation Tool NuGet Package if needed.

Here is an example of how I use it in my PowerShell build script.

function ExecuteAutomatedTranslationTask {
    Param([Parameter(HelpMessage='The path to the source folder.  Example: ''C:\Dev\Solution\src\Project ''`n')]
          [string] $sourceFolder,
          [Parameter(HelpMessage='The full path to the AutomatedTranslation executable. Example: ''C:\Dev\Solution\src\packages\AutomatedTranslationTool.1.2.0\tools\AutomatedTranslation.exe''`n')]
          [string] $translationExecutable)

    if ([System.IO.File]::Exists($translationExecutable) -eq $false) {
		Write-Host 'Unable to find the Automated Translation tool.  Attempting to install it from NuGet.'
		Push-Location -Path ([System.IO.Path]::Combine($sourceFolder, "..\packages"))
		Invoke-Expression '..\.nuget\nuget install AutomatedTranslationTool -Version 1.2.1'
		Pop-Location
	}

    if ([System.IO.File]::Exists($translationExecutable) -eq $false) {
		Write-Error "Unable to find the Automated Translation Tool executable.  Please verify this is installed before you proceed.  It can be found at http://www.nuget.org"
		Throw "Automated Translation Tool application missing"
	}

    [System.Diagnostics.Process] $process = New-Object System.Diagnostics.Process
    $process.StartInfo.FileName = $translationExecutable
    $process.StartInfo.Arguments = ('/languagePath=' + [System.IO.Path]::Combine($sourceFolder, 'lang') + ' /strResourcePath=' + [System.IO.Path]::Combine($sourceFolder, 'Server\Resources'))
    $process.StartInfo.UseShellExecute = $false
    $process.Start()

    $process.WaitForExit();
    if ($process.ExitCode -ne 0) {
        throw ('Unable to perform the ' + $operation + ' correctly.  Please correct the error and try again.')
    }
}

While this function snippet is just a part of a larger script file, you can see that it uses NuGet to download the tool into the packages folder and extract it out. Using the path passed in the $translationExecutable variable, the tool will attempt to perform the translation for you.

I hope that you will find this tool helpful. If you have a suggestion fork my repository and make your modification. Then create a pull request. If it works I’ll be glad to include it in my next version!

One thought on “Automated Translation Tool

  1. Pingback: Automate Your Translations | OutOfMemoryException

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s