Strings in Ruby are a bit hard to understand if you're not an English speaker. What does
"hello world"
even mean? I for one didn't study enough English to understand that! But worry no more!
Just get a DeepL auth key and export it as follows:
export DEEPL_AUTH_KEY="your-api-token"
By default this gem uses the free DeepL servers, but you can also configure your own:
export DEEPL_HOST="non-free-host"
Now you can translate it to your language of chose with this gem!
"hello world".translate_to_ja
# 世界よ、ハローだ
What's even better is that you can also save some typing by using the shortened alias such as below:
"hello world".to_ja # or to_fi, to_ru... endless possibilities!
# 世界よ、ハローだ
This gem uses the wonderful DeepL for Ruby as its backend.
https://github.com/wikiti/deepl-rb
Add this line to your application's Gemfile:
gem 'translate_self'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install translate_self
Supported languages are: Bulgarian, Chinese, Czech, Danish, Dutch, English, Estonian, Finnish, French, German, Greek, Hungarian, Italian, Japanese, Latvian, Lithuanian, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Spanish, and Swedish.
You can assign a string a language:
finn = "Oon suomalainen"
finn.language = 'fi'
This language will be passed on to DeepL when translating.
You can also assign a to-language parameter:
finn = "Oon suomalainen"
finn.to_language = 'en'
This way you can just use translate
to get the string translated to English.
finn.translate
# I am a Finn