gem install google-cloud-translate
You will need a Google Cloud API account.
PROJECT_ID
withintranslate.rb
needs to be configured to your project id.- You must set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path to the downloaded JSON configuration file.
For Community Translate posts from Malinda:
load 'translate.rb'
Translate.malinda(lines)
For general use:
load 'translate.rb'
t = Translate.new(steps: 10) do
[
'This is a test.',
'These will be translated too much.',
'You have been warned.'
]
end
t.run # Calls the API
t.text # The resultant text.
t.text_pairs # The resultant text pairs.
t.languages_used(true) # The names of the languages used.
You can also specify which languages to use:
t = Translate.new(
use_languages: [
{ 'name' => 'French', 'code' => 'fr' },
{ 'name' => 'German', 'code' => 'de' }
]
) do
[
'This is a test.',
'These will be translated too much.',
'You have been warned.'
]
end