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 method `sample' #202

Closed
frodrigo opened this issue Aug 26, 2016 · 7 comments
Closed

undefined method `sample' #202

frodrigo opened this issue Aug 26, 2016 · 7 comments
Labels
Milestone

Comments

@frodrigo
Copy link

I run i18n_tasks in a locale without provided translation (fr). But it's fails on a:

NoMethodError: undefined method sample' for "translation missing: fr.i18n_tasks.cmd.encourage":String /home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/reports/terminal.rb:151:inprint_success'
/home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/reports/terminal.rb:55:in unused_keys' /home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/command/options/data.rb:80:inprint_forest'
/home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/command/commands/usages.rb:29:in unused' /home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/command/commands/health.rb:20:inhealth'
/home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/command/commander.rb:26:in run' /home/fred/.gem/gems/i18n-tasks-0.9.5/lib/i18n/tasks/cli.rb:44:inrun'

I unsuccessfully locate where come from the sample method.

frodrigo added a commit to Mapotempo/i18n-tasks that referenced this issue Nov 22, 2016
@glebm
Copy link
Owner

glebm commented Dec 8, 2016

This happens because i18n-tasks doesn't have its messages translated to French.
Please make sure the internal_locale is set to en in the config (or contribute a French translation: https://github.com/glebm/i18n-tasks/tree/master/config/locales).

@glebm
Copy link
Owner

glebm commented Jan 9, 2017

Can you post the new stack trace and the output of i18n-tasks config?

@frodrigo
Copy link
Author

frodrigo commented Jan 9, 2017

NoMethodError: undefined method `sample' for "translation missing: fr.i18n_tasks.cmd.encourage":String
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/reports/terminal.rb:160:in `print_success'
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/reports/terminal.rb:55:in `unused_keys'
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/command/options/data.rb:83:in `print_forest'
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/command/commands/usages.rb:30:in `unused'
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/command/commands/health.rb:20:in `health'
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/command/commander.rb:25:in `run'
/home/fred/.gem/gems/i18n-tasks-0.9.8/lib/i18n/tasks/cli.rb:41:in `run'
/home/fred/secret_project/code/secret_project/lib/tasks/test_enhance.rake:23:in `block in <top (required)>'
/home/fred/secret_project/code/secret_project/lib/tasks/test_enhance.rake:29:in `block in <top (required)>'
/home/fred/.gem/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
/home/fred/.gem/ruby/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
/home/fred/.gem/ruby/2.3.0/bin/bundle:23:in `load'
/home/fred/.gem/ruby/2.3.0/bin/bundle:23:in `<main>'
Tasks: TOP => i18n_health

@glebm
Copy link
Owner

glebm commented Jan 9, 2017

  1. Looks like you're calling i18n-tasks programmatically. How do you call it?
  2. Can you please post the output of i18n-tasks config here?
  3. Does i18n-tasks missing work if you call it directly?

@frodrigo
Copy link
Author

frodrigo commented Jan 9, 2017

  1. I'm run i18n-tasks missing from tests via rake. For testing purpose my test are done with locale fr.
begin
  if Gem::Specification.find_by_name('i18n-tasks')
    require 'i18n/tasks/cli'

    task :i18n_health do
      I18n::Tasks::CLI.new.run(['health'])
      I18n.locale = :fr
    end

    Rake::Task['test'].enhance do
      if !ENV.key?('I18N') || ENV['I18N'] != 'false'
        Rake::Task[:i18n_health].invoke
      end
    end
  end
rescue Gem::LoadError
end
$ bundle exec i18n-tasks config
internal_locale: en
base_locale: en
locales:
- en
- fr
data:
  adapter: I18n::Tasks::Data::FileSystem
  read:
  - config/locales/%{locale}.yml
  write:
  - config/locales/%{locale}.yml
  yaml:
    write:
      line_width: -1
search:
  paths:
  - app/
  relative_roots:
  - app/controllers
  - app/helpers
  - app/mailers
  - app/presenters
  - app/views
  scanners:
  - - "::I18n::Tasks::Scanners::RubyAstScanner"
    - only:
      - "*.rb"
  - - "::I18n::Tasks::Scanners::PatternWithScopeScanner"
    - exclude:
      - "*.rb"
      ignore_lines:
        opal: "^\\s*#(?!\\si18n-tasks-use)"
        haml: "^\\s*-\\s*#(?!\\si18n-tasks-use)"
        slim: "^\\s*(?:-#|/)(?!\\si18n-tasks-use)"
        coffee: "^\\s*#(?!\\si18n-tasks-use)"
        erb: "^\\s*<%\\s*#(?!\\si18n-tasks-use)"
  strict: true
  exclude:
  - app/assets/images
  - app/assets/fonts
ignore_missing:
- "{devise,leaflet_draw}.*"
ignore_unused:
- "*"
  1. $ bundle exec i18n-tasks missing works fine

@glebm
Copy link
Owner

glebm commented Jan 9, 2017

The run method currently doesn't set the locale, it is set in the start method instead.

I'll move it to run, but in the meantime you can either use start (if you don't mind the command exiting on failure) or do this instead:

task :i18n_health do
  I18n.with_locale 'en' do
    I18n::Tasks::CLI.new.run(['health'])
  end
end

This line is unnecessary:

I18n.locale = :fr

@frodrigo
Copy link
Author

Ok, it works for me like this.

glebm added a commit that referenced this issue Jan 10, 2017
Simplifies direct usage of the run method.

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

No branches or pull requests

2 participants