Home > Uncategorized > Google Translate bash function (Windows)

Google Translate bash function (Windows)

Friday, August 7th, 2015

I’ve noticed that since I switched to Windows 10, my Google Translate bash functions were broken. I suppose that something has changed in the way that explorer.exe interprets URLs (?). Anyway, here’s a fixed version, simply using a different way to construct the URL ;-)

I use the function below to translate from english to french:

enfr(){ (explorer "https://translate.google.com/?sl=en&tl=fr&text=$*" )& }

The only things to know to understand the above:

  • sl = source language
  • tl = translation language
  • text = what to translate :)
  • $* = arguments passed to the function (i.e., what you want translated)
  • calling this function will open a new tab in your default Web browser

I know that it could be improved because it needs proper escaping (e.g., running frnl c’est sympa will break it because of the ‘), but it’s just enough for what I need.

One could create a more intelligent function supporting multiple languages (please do :p) but I don’t need one =)

If you enjoyed this post, make sure you subscribe to my RSS feed!

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment