Is there a way to detect what foreign language a piece of text is in Excel using VBA without calling an external API that requires an API key?

160 views Asked by At

I am able to detect and get the foreign language code for an arbitrary piece of text in Excel using VBA and either the Google Translate API or the Microsoft Azure Translate API, but both of those require API keys and accounts with Google or Microsoft, and the client would prefer not to do that.

So I found another solution where I send the text over to Word using VBA automation and then use Word's Selection.DetectLanguage() feature to determine the language. However, the issue with that is it requires that Word be installed with 200+ language packs for every user, and the client doesn't prefer to do that either.

Lastly, I found a hack where you can programmatically and anonymously call https://translate.google.com/m and translate an arbitrary short amount of text with no API key, but while that site detects and translates the language, it does not tell you what language it is.

So my question is, does anyone know of a programmatic way in VBA to do this other than the ways I described above? Thank you so much for any ideas you can provide as I've been Googling and Bing Chatting and ChatGPTing this one for about 4 hours now and I'm stumped.

2

There are 2 answers

0
Derek On BEST ANSWER

Thanks to @hennep in a comment to my question, there is a way to anonymously detect the language of a snippet of text by submitted a GET message to a URL and scraping the resulting HTML that comes back.

How to do this in Excel VBA is shown in the YouTube video "Excel VBA - Google Translate Function in Excel - PART 1 | XLStudio" - https://www.youtube.com/watch?v=UYITBpG7p2Y

The website to use for this is (for example): https://duckduckgo.com/?q=translate+%22wat+is+dit+voor+taal%22+to+english&t=h_&ia=web

Which returns "Dutch detected," which can then be scraped from the HTML.

1
hennep On

If you also want to translate the text, I recently received a link to deepl.com with the comment that it would be a better translator than google: https://www.deepl.com/en/translator#nl/en/wat%20is%20dit%20voor%20taal%0A

If "deepl" is short for "deep learning", it would make sense.

This site shows a similar "Dutch (detected)" response. Nice to have a backup.