Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't translate using Google #189

Open
thromera opened this issue Feb 11, 2016 · 15 comments
Open

can't translate using Google #189

thromera opened this issue Feb 11, 2016 · 15 comments

Comments

@thromera
Copy link

There is a problem when I try to translate my missing keys. Please find below my command line :).

✗ i18n-tasks translate-missing --from base fr
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.4-compliant syntax, but you are running 2.2.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
/Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:94:in `next': undefined method `each' for nil:NilClass (NoMethodError)
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:94:in `parse_value'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:92:in `block in parse_value'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:92:in `map'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:92:in `parse_value'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:67:in `from_values'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:40:in `fetch_google_translations'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:30:in `block in google_translate_list'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:29:in `each'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:29:in `map'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:29:in `google_translate_list'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:13:in `block in google_translate_forest'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/data/tree/nodes.rb:16:in `each'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/data/tree/nodes.rb:16:in `each'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:12:in `inject'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/google_translation.rb:12:in `google_translate_forest'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/command/commands/missing.rb:39:in `translate_missing'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/command/commander.rb:26:in `run'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/cli.rb:42:in `run'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/cli.rb:19:in `block in start'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/cli.rb:203:in `auto_output_coloring'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/cli.rb:17:in `start'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/lib/i18n/tasks/cli.rb:10:in `start'
    from /Users/thomasromera/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.9.4/bin/i18n-tasks:16:in `<top (required)>'
    from /Users/thomasromera/.rbenv/versions/2.2.3/bin/i18n-tasks:23:in `load'
    from /Users/thomasromera/.rbenv/versions/2.2.3/bin/i18n-tasks:23:in `<main>'
@bartimaeus
Copy link

@Erowlin what permissions do you have in the Google developer console (https://console.developers.google.com) for the Google Translate API? I think my account required a credit card on file before it would work.

@thromera
Copy link
Author

We added a card aswell, the same API key is working for Crowdin :). (I tried with a new one also, paid too)

@glebm
Copy link
Owner

glebm commented Feb 21, 2016

Looks like it's failing when translating a key with an array value. This should be working though.
Could you post the key/value that's failing here?

@borisrorsvort
Copy link

@glebm I've similar issue

i18n-tasks translate-missing
/Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:90:in `next': undefined method `each' for nil:NilClass (NoMethodError)
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:90:in `parse_value'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:88:in `block in parse_value'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:88:in `map'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:88:in `parse_value'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:63:in `from_values'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:36:in `fetch_google_translations'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:27:in `block in google_translate_list'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:26:in `each'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:26:in `map'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:26:in `google_translate_list'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:13:in `block in google_translate_forest'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/data/tree/nodes.rb:16:in `each'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/data/tree/nodes.rb:16:in `each'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:12:in `inject'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/google_translation.rb:12:in `google_translate_forest'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/command/commands/missing.rb:38:in `translate_missing'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/command/commander.rb:26:in `run'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/cli.rb:41:in `run'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/cli.rb:18:in `block in start'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/cli.rb:201:in `auto_output_coloring'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/cli.rb:16:in `start'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/lib/i18n/tasks/cli.rb:9:in `start'
    from /Users/boris/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i18n-tasks-0.8.7/bin/i18n-tasks:13:in `<top (required)>'
    from /Users/boris/.rbenv/versions/2.2.3/bin/i18n-tasks:23:in `load'
    from /Users/boris/.rbenv/versions/2.2.3/bin/i18n-tasks:23:in `<main>'

@glebm
Copy link
Owner

glebm commented Mar 17, 2016

Could you post the key/value that's failing here? You can find it by attaching a debugger / printing where it's failing.

@anthonypenner
Copy link

I was getting this exact error as well. Initially it looks though there is an issue with nil enumerators here:

# p p "#{untranslated}: #{each_translated.inspect}"
# result from above: "You agree that you will not engage in any: #<Enumerator: nil:each>"
restore_interpolations(untranslated, each_translated.next)

But I traced it all the way back through the call stack and it turns out my API key was not being set properly but wasn't blank, it seems like you can recreate this by setting a bad API key on purpose as well.

@Adsidera
Copy link

Hi I have a similar issue as well when running i18n-tasks translate-missing...are there any updates?
image

@glebm
Copy link
Owner

glebm commented Nov 10, 2017

@Adsidera Set the API key

@thromera
Copy link
Author

Hi, I'm no longer using this project, so I can't help further on the issue. Should I close it? Thanks.

@Adsidera
Copy link

@glebm the api key was already set, but as a reference I managed to solve the issue by installing easytranslate in the gemfile, I set the google API key without double quotes in the config file and I run the translate-missing command with a bundle exec. It worked like a charm for me. Thank you for this awesome gem!

@tomprats
Copy link

tomprats commented Dec 7, 2017

This error seems to be generated when EasyTranslate.translate(to_values(list), opts) returns nil, I think this happens for a variety of reasons. One thing I'm noticing is:

  • EasyTranslate.translate(to_values(list), opts) => returns nil for my list of 136
  • EasyTranslate.translate("tom", opts) => EasyTranslate::EasyTranslateException: Daily Limit Exceeded
  • EasyTranslate.translate(["tom", "tim"], opts) => EasyTranslate::EasyTranslateException: Daily Limit Exceeded

So it seems like when the list is too long, it just returns nil and swallows any errors. I can open a bug on EasyTranslate for this, but it sounds like I18n Tasks should be handling a use-case where EasyTranslate returns nil by moving this check into from_values.

This is a helpful gem, so let me know if I can help

@glebm
Copy link
Owner

glebm commented Dec 8, 2017

@tomprats I would prefer that this EasyTranslate does not return nil if there is an error.

See also: seejohnrun/easy_translate#35

@fschwahn
Copy link

I think I'm running into a similar problem. I hit the "100.000 characters per 100 seconds" limitation (which I cannot change), and this raises an exception in easy_translate, which bubbles and in fact discards all translations so far (resulting in a bit of wasted money).

I forked easy_translate to just fill in empty translations in that case (which I can manually remove and rerun the task after 100 seconds to continue), but I think this should be handled more gracefully. Not sure whether this has to be done in i18n-tasks or easy_translate. But easy_translate raises an exception which i18n-tasks could catch and abort the translate-missing task gracefully.

@scarroll32
Copy link
Contributor

scarroll32 commented Dec 7, 2019

It's important to run bundle exec to have the env variables picked up.

bundle exec i18n-tasks translate-missing --from=en fr

You can also prepend the env variable this way

GOOGLE_TRANSLATE_API_KEY=<redacted> i18n-tasks translate-missing --from=en fr

@rebuilt
Copy link

rebuilt commented Feb 5, 2021

@glebm the api key was already set, but as a reference I managed to solve the issue by installing easytranslate in the gemfile, I set the google API key without double quotes in the config file and I run the translate-missing command with a bundle exec. It worked like a charm for me. Thank you for this awesome gem!

Thank you. I didn't know why it stopped working for me. I removed the quotes from around my google API key and got it working again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants