Saturday 13 January 2018

Dynamic Language Translation In Power BI

Dynamic Language Translation In Power BI

Problem statememt

There was requirement to see the product name in different languages as per region and country. But storing all the various language translation in database was not an option. The only option left was to do the language translation in Power BI on the fly. This document illustrates the steps to achieve dynamic translation in Power BI.

Solution Overview

This problem statement was solved by using following technologies
·       Azure Cogitative Services (Language Translation API)
·       Power BI Desktop Services
Following sections will explain the implementation in detail.

Azure coginative services    

User should be register for “Azure Cogitative Services” to use the translation APIs.

data files used for exmaple

There are 3 files used for this example,
PRODUCT.txt: This file contains names of the product.
LANGUAGE.txt: This file contains language name and their code
PRODUCTSOLD.txt: this is sample file to test

Import these files in Power bi

Import these 3 files in the Power BI desktop.

cross join Product & language

The product and the language must be crossed join so that each product can be represented in all the available languages. For this will do little hack. Dummy column ‘CrossJoinHack’ with values as 1 was added in both the tables.

Once this is done, established relationship between the 2 tables
And now the language table can be merged to Product table to produce the cross join. This will bring the new column in the Product table.
Now expand the column and cross join will be produced in Product table. Rename ‘Language.Language’ to ‘Language’ & ‘Language.Code’ to ‘LanguageCode’

Important Step: calling congnitive service

To get each row of the product translated, cognitive services needs to be called. This service will be called in the custom column and 2 parameters ‘text’ & ‘to’ will be passed, where ‘text’ is text that needs to be translated (product name in this example) and ‘to’ is language code to which it needs to be translated.
Here is the code for the column. Click this link for API Reference. Please replace the keys with your Cognitive Service key.
each Table.FromColumns({Lines.FromBinary(
Web.Contents("https://api.microsofttranslator.com/V2/Http.svc/Translate?text=" & [ProductName] & "&to="&[LanguageCode], [Headers=[#"Ocp-Apim-Subscription-Key"="213e9cxxxxxxxxxxx63eaeef"]])
)})
In the below figure please note that query string is formed by using ProductName and LanguageCode from the available columns.

After the above step the Custom column has been added to the Product table.
Next step is expanding the column, after expanding the XML output us shown. Need to format the column as XML to get the actual translation.

After these steps will get the translation for each product for each language. Yeppeee!

creating role for testing

Next create roles for testing for each language

Next test for each role. First will test for Hindi.

Next for Chinese,
Hurry! Done!

7 comments:

  1. How to change the language of column name ??

    ReplyDelete
  2. How to change the language of column name dynamically based on country ??

    ReplyDelete
  3. Does the same syntax work with V3 of the API? Alternatively how to handle the error in translation if using V2 of the API e.g. in case of unsupported languages

    ReplyDelete
  4. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. Chinese translation

    ReplyDelete
  5. I am glad to find amazing information from the blog. Thanks for sharing the information. for more useful Information visit:
    translation companies in dubai

    ReplyDelete
  6. Thank you for sharing wonderful information with us to get some idea about that content.This article is very much helpful and i hope this will be an useful information for the needed one.Keep on updating these kinds of informative things

    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    oracle online training

    hadoop training in chennai

    hadoop training in bangalore


    ReplyDelete