jdellasala
Well-known Member
- Joined
- Dec 11, 2020
- Messages
- 755
- Office Version
- 365
- Platform
- Windows
- Mobile
- Web
Inspired by @smozgur's articles on using Google Translate in Power Query, I created functions to translate to and from English. They're working fine, and now I've discovered that using sl=auto will automatically detect the source language. In a test of translating an English Phrase into the 134 supported languages and then those translations back into English, 54 languages got it nearly perfect, and the other 80 were similar enough to pass.
In using the the function to Auto Detect the source language so that only the source text and target language are needed for the function, only 9 languages failed out of the 134 when compared to the two step translation to another language and back to English. Here's the function:
Here's my question. I have a table of all the supported languages and their codes. How can I have the function present the list of languages like a Data Validation list when invoking the function? Right now one needs to either manually specify the Language Code or it needs to be in a column. Is that even possible?
In using the the function to Auto Detect the source language so that only the source text and target language are needed for the function, only 9 languages failed out of the 134 when compared to the two step translation to another language and back to English. Here's the function:
Power Query:
(SrcTxt as text, LangCode as text ) as text =>
// SrcTxt = Text to be translated, LangCode = the language CODE to translate to.
let
URL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" & LangCode & "&dt=t&q=" & SrcTxt,
Source = Json.Document( Web.Contents( URL ) ),
Translation = Source{0}{0}{0}
in
Translation