Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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".

 

02-11-2017 13-45-32.jpg

 

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-....

 

large.png

 

Now, the translation feature is working without any errors.

 

Thanks for your help.

 

Cheers,

Dom

View solution in original post

7 REPLIES 7
v-huizhn-msft
Employee
Employee

Hi @Anonymous,

You can use Translator Text API in Power BI, more details, please follow the guide in the blog: Translate Text In Power BI Or Excel With Microsoft Translator Text API.

Best Regards,
Angelia

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

I still have the same issue...

 

coding in M Query language...

 

My code to create a custom translation function:

let
Source = Web.Contents("https://api.cognitive.microsoft.com/sts/v1.0", [Headers=[#"Ocp-Apim-Subscription-Key"="xxxxxxx"]])
in
Source

 

My result:
404 Error Resource Not found.....

 

DataSource.Error: Web.Contents failed to get contents from 'https://api.cognitive.microsoft.com/sts/v1.0' (404): Resource Not Found

Details:
DataSourceKind=Web
DataSourcePath=https://api.cognitive.microsoft.com/sts/v1.0
Url=https://api.cognitive.microsoft.com/sts/v1.0

 

 

I have tried many other names for the api key [Header]:
apikey
apitoken
Authorization

 

 

 

Why is the resource not found?

 

In Azure, the subscription gave me the url which I copy and pasted. I see other users using this URL - they have also had problems connecting.

 

I chose "Anonymous" authentication, as has been indicated.

this is a basic query that works - doesn't do exactly what i need to do, but at least i can all the api...

 

let

 

body =  "[{""Text"":""Have a good day""}]",

 

jsonContent = Text.ToBinary(body, TextEncoding.Ascii),

 

source= Web.Contents(

 

"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=fr-FR",

 

[

 

Headers=

 

[#"Ocp-Apim-Subscription-Key"="xxxxxxxxxxxxx",

 #"Content-Type"="application/json", 

 #"Accept"="application/json"],

 

Content=jsonContent

 

]

 

),

 

json = Json.Document(source),

 

    json1 = json{0},

 

    translations = json1[translations],

 

    translations1 = translations{0}

 

 

in

    translations1

Hi @Anonymous,

The error means you need to specify an API key name in the headers area of Web.Contents using the advanced editor. I am not specific with API which is a part of developer,  please see Chris Webb's post on this for a good example: https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/.  Or please create a new thread in Power BI developer community, where you can get professional support.  And welcome to share your workaround if you get answer.

Best Regards,
Angelia

Anonymous
Not applicable

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".

 

02-11-2017 13-45-32.jpg

 

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-....

 

large.png

 

Now, the translation feature is working without any errors.

 

Thanks for your help.

 

Cheers,

Dom

This did not solve my issue...

 

coding in M Query language...

 

My code to create a custom translation function:

 

let
Source = Web.Contents("https://api.cognitive.microsoft.com/sts/v1.0", [Headers=[#"Ocp-Apim-Subscription-Key"="xxxxxxx"]])
in
Source

 

My result:


404 Error Resource Not found.....

DataSource.Error: Web.Contents failed to get contents from 'https://api.cognitive.microsoft.com/sts/v1.0' (404): Resource Not Found
Details:
DataSourceKind=Web
DataSourcePath=https://api.cognitive.microsoft.com/sts/v1.0
Url=https://api.cognitive.microsoft.com/sts/v1.0

 

 

I have tried many other names for the api key [Header]:
apikey
apitoken
Authorization

 

 

Why is the resource not found?

 

In Azure, the subscription gave me the url which I copy and pasted. I see other users using this URL - they have also had problems connecting.

 

I chose "Anonymous" authentication, as has been indicated.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.