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

Undefined 'each' for nil when running translate-missing #283

Open
dylanjha opened this issue Mar 16, 2018 · 7 comments
Open

Undefined 'each' for nil when running translate-missing #283

dylanjha opened this issue Mar 16, 2018 · 7 comments

Comments

@dylanjha
Copy link

dylanjha commented Mar 16, 2018

running:

GOOGLE_TRANSLATE_API_KEY= i18n-tasks translate-missing

It seems to use the key correctly and make a request, but I'm getting this error:

ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:88:in `next': undefined method `each' for nil:NilClass (NoMethodError)
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:88:in `parse_value'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:86:in `block in parse_value'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:86:in `map'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:86:in `parse_value'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:63:in `from_values'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:40:in `fetch_google_translations'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:30:in `block in google_translate_list'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:29:in `each'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:29:in `map'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:29:in `google_translate_list'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:13:in `block in google_translate_forest'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/data/tree/nodes.rb:17:in `each'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/data/tree/nodes.rb:17:in `each'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:12:in `inject'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/google_translation.rb:12:in `google_translate_forest'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/command/commands/missing.rb:43:in `translate_missing'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/command/commander.rb:26:in `run'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/cli.rb:41:in `block in run'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-0.9.1/lib/i18n.rb:265:in `with_locale'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/cli.rb:39:in `run'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/cli.rb:19:in `block in start'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/cli.rb:201:in `auto_output_coloring'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/cli.rb:17:in `start'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/lib/i18n/tasks/cli.rb:11:in `start'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/gems/i18n-tasks-0.9.21/bin/i18n-tasks:15:in `<top (required)>'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/bin/i18n-tasks:23:in `load'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/bin/i18n-tasks:23:in `<main>'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/bin/ruby_executable_hooks:15:in `eval'
	from /Users/dylanjhaveri/.rvm/gems/ruby-2.4.1@pj/bin/ruby_executable_hooks:15:in `<main>'/da
@atd
Copy link
Contributor

atd commented Apr 11, 2018

I am finding the same issue. Maybe this is because we have blank keys? Like https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/es-ES.yml#L183

glebm added a commit that referenced this issue Aug 20, 2018
glebm added a commit that referenced this issue Aug 20, 2018
@glebm
Copy link
Owner

glebm commented Aug 20, 2018

Maybe this is because we have blank keys?

I don't think so, I've added a test in 4c83cf3 and it didn't fail.

See fc529e7 for where this is handled

@beneggett
Copy link

Same issue here. any ideas?

@pcothenet
Copy link

For what it's worth, I was getting this error while trying to use a locale that doesn't exist (I was using jp instead of ja)

@Andriy-Access
Copy link

Also had an issue for locales, that don't exist, but also had the same issue when tried translating from en to en.
Had to Monkey patch to catch an exception at lib/i18n/tasks/translators/base_translator.rb#translate pairs.
For me it looks like it doesn't handle exception from EasyTranslate properly.

Environment:
os: macOS arm
ruby: 2.7.1
rails: 6.0.4.8
easy_translate: 0.5.1
i18n-tasks: 0.9.37

Here is a stack trace:

Bad language pair: en|en
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/easy_translate-0.5.1/lib/easy_translate/request.rb:47:in `perform_raw'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/easy_translate-0.5.1/lib/easy_translate/translation.rb:34:in `request_translations'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/easy_translate-0.5.1/lib/easy_translate/threadable.rb:24:in `block in threaded_process'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/easy_translate-0.5.1/lib/easy_translate/threadable.rb:24:in `map'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/easy_translate-0.5.1/lib/easy_translate/threadable.rb:24:in `threaded_process'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/easy_translate-0.5.1/lib/easy_translate/translation.rb:20:in `translate'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/google_translator.rb:19:in `translate_values'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:52:in `fetch_translations'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:36:in `block in translate_pairs'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:34:in `each'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:34:in `map'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:34:in `translate_pairs'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:16:in `block in translate_forest'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/data/tree/nodes.rb:16:in `each'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/data/tree/nodes.rb:16:in `each'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:15:in `inject'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translators/base_translator.rb:15:in `translate_forest'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/translation.rb:18:in `translate_forest'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/command/commands/missing.rb:43:in `translate_missing'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/command/commander.rb:25:in `run'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/cli.rb:51:in `block in run'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-1.12.0/lib/i18n.rb:322:in `with_locale'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/cli.rb:49:in `run'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/cli.rb:19:in `block in start'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/cli.rb:212:in `auto_output_coloring'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/cli.rb:18:in `start'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/lib/i18n/tasks/cli.rb:12:in `start'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/i18n-tasks-0.9.37/bin/i18n-tasks:16:in `<top (required)>'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/bin/i18n-tasks:23:in `load'
/Users/Andriy_Lukashchuk/.rbenv/versions/2.7.2/bin/i18n-tasks:23:in `<main>'
{:to=>"en", :from=>"en"}

@basicfeatures
Copy link

Same issue here!

@viktorsmari
Copy link

Same issue here, any workarounds?

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

No branches or pull requests

8 participants