Translating Languages with PowerShell

When you come from another country, it can be difficult living in the Netherlands sometimes. Dutch is not as difficult as you’ll hear from others, but sometimes you want to make sure the sentence you’ve read means what you think. Mistakes can be embarrassing, expensive, or something that falls into the general I-should-have-checked-that-first category. Trust me, I know……..

Normally for translation I’ll use the Google Translate web site. The translation is not always 100% accurate, but usually enough to understand things. And it’s quick.

For automation, Google provide a web services API, but this is a paid-for service.  Fortunately, Microsoft provide a free translation web service, not costing you anything unless you plan to translate more than 1,000,000 characters a month.

There are some steps that we need to do to be able to use Microsoft’s translation web service before we can begin scripting.

Sign up for the Microsoft Translator Web Service

1.  Visit the Microsoft Azure Marketplace at https://datamarket.azure.com/home/

Azure Marketplace Front
2
.  Click Sign In at the top right of the screen.

Azure Marketplace Logon
3. Sign-in with your Microsoft account credentials (create a Microsoft account if you do not have one before continuing).

microsofttranslatorsearch4. Begin to type Microsoft Translator into the search box at the top right.
5. In the search list, click Microsoft Translator.

Microsoft Azure Marketplace
6. Click Sign Up on the free option.

signup
7. Select the I have read and agree to the above publisher’s Offer Terms and Privacy Policy check box.
8. Click Sign Up.

Register your Application

Now it’s time to register our application which will be use the Microsoft Translator web service.
Register your application

1. In the Client ID box, type a name that you wish you be associated with your application. This can be a mixture of numbers, letters, hyphens and underscores.
2. In the Name box, type a suitable name for your application. This property is not used in the cmdlet we will be writing.
3. In the Client secret box, type a password for the application. Keep this information secure.
4. In the Redirect URI box, type any valid URL. This property is also not used in our script.
5. In the Description box, type a description if you wish for later reference.
6. Click CREATE

RegistedApplications
7. Select Sign Out.
8. Close your browser window.

Script the Cmdlet

With the previous steps complete, we can start to script the cmdlet. This cmdlet borrows code from MSDN, so I’d recommend visiting the Microsoft Translator pages for more information on the web service and examples.

The cmdlet uses input parameters of Text for the string to be converted, and From and To ones, which you use to indicate the original language the string is in, and the one you want it translated to. You can find the most recent list of supported languages at the Translator Language Codes webpage, also on MSDN.

I’ve enclosed an example below, together with the type of result you should expect.

SpeakEnglish

2 thoughts on “Translating Languages with PowerShell

  1. Hello,

    I confirm that the Microsoft Translator API is a good alternative to the Google Translate API ($20 per 1 M characters of text), the translations are not perfect, but understandable.

    To build my FAQ (http://powershell-guru.com), I use the WordPress Rest API to get and edit my posts, and I use the MS Translator API to translate the questions (until I get some real translators, I will do that way).

    A good tip is to create some HTML tags next to the text you want to translate so you can easily identify them with a script, in my case this is how I do :

    How to reverse the order of items in a array with Powershell ?
    $array = @(“A”,”B”,”C”)
    [array]::Reverse($array) # C,B,A

    Steve

  2. Hey Steve,

    Thanks for the feedback. Your site’s pretty cool, like the way you’ve done that.

    I’m using wordpress.com at the moment, but it’s definitely something I would look at including if I ever move to .org

    cheers,

    Tim

Leave a Reply

Your email address will not be published. Required fields are marked *