Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Microsoft Translator Support?

Hi,

 

I was planing to use the Microsoft Translator support for translating text in Power BI. Similar to the following example: https://www.youtube.com/watch?v=jZQ4BZmtseo . Base on the post https://community.powerbi.com/t5/Desktop/Sample-Power-BI-multilingual-support-report/td-p/57354 it seems to be that Microsoft Translator is not supported anymore. is that correct? Is there another way to use the API of Microsoft Translator?

 

Thanks a lot.

 

Cheers,

Dom

  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi v-huizhn-msft,

     

    I was able to fix that issue.

     

    First, to avoid the issue  "A web API key can only be specified when a web API key name is provided" I had to set the "Data source settings" to "Anonymous". Because the M code is providing the API key logic there is no need to specify the key in the GUI of Power BI.

     

    Second, in Power BI are two kinds of Data source settings: "Data source in current file" and "Global permissions". As far as I experienced it, the permission settings for the URL I'm using should be the same in either Global or Current File setting. Not sure if this is 100% correct but it worked for my case. Therefore, I set it credential type to "Anonymous" and privacy level to "None".

     

     

    Afterwards I received the error message "Formula.Firewall: Query references other queries or steps, so it may not directly access data source. Please rebuild this data combination". To get rid of this error I set Power BI to ingore the Privacy in either Global or Current File setting under Option as mentioned in http://community.powerbi.com/t5/Desktop/Formula-Firewall-Query-references-other-queries-or-steps/td-p/150725.

     

     

    Now, the translation feature is working without any errors.

     

    Thanks for your help.

     

    Cheers,

    Dom

7 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-huizhn-msft,

       

      Thanks for your support.

      I read the blog post and tried to establish a connection by using the template DATACHANT is providing.

      Unfortunately, I get the following error message when I fill in my Ocp-Apim-Subscription-Key: "A web API key can only be specified when a web API key name is provided". I am aware of serveral post discussing that issue but I still not sure what to do about it.

      The function I am using to get the translater access looks like this:

       

      let
          EmptyContent = Text.ToBinary("", TextEncoding.Ascii),
          
          Response =
              Web.Contents("https://api.cognitive.microsoft.com/sts/v1.0/issueToken",
                  [
                      Headers =
                          [
                              #"Content-Type"="application/json",
                              Accept="application/jwt",
                              #"Ocp-Apim-Subscription-Key"= TranslatorKey
                          ],
                      Content=EmptyContent
                  ]),
          #"Imported Text" = Table.FromColumns({Lines.FromBinary(Response,null,null,20127)}),
          Res = #"Imported Text"{0}[Column1]
      in
          Res

       

       

      The function to translate the text looks like this:

       

      (textToTranslate, TranslateTolanguage) =>    
      let
          URL = "https://api.microsofttranslator.com/v2/http.svc/Translate?appid=Bearer " & GetTranslatorAccessToken & "&text=" & textToTranslate & "&to=" & TranslateTolanguage,
          Response = Web.Contents(
              URL,
              [
                  Headers = [Accept="application/xml"]
              ]
          ),
          XML = Xml.Tables(Response, null, 65001),
          TranslatedText = XML{0}[#"Element:Text"]
      in
          TranslatedText

       

      Apart from that, I already checked if my Ocp-Apim-Subscription-Key is valid by using http://docs.microsofttranslator.com/oauth-token.html#/ . So far the key is valid since I received the response code 200.

      BTW the variable TranslatorKey is stored as a parameter in Power BI.

       

      Do you have any suggestions?

       

      Cheers,

      Dom