faker icon indicating copy to clipboard operation
faker copied to clipboard

Faker::Lorem.paragraph raises I18n::MissingTranslationData without manual locale override

Open rmm5t opened this issue 12 years ago • 37 comments

I18n::MissingTranslationData: translation missing: en.faker.lorem.words

This was introduced in v1.4.0 and is still a problem in v1.4.3. If I manually set the local to "en," it works as expected, but prior to v1.4.0, manually setting the locale wasn't necessary (tested with v1.2.0 and v1.3.0).

UPDATE: I was wrong about the locale override working. This appears to exhibit itself only when Faker is used inside an ERB file and when that ERB file is loaded from a rake file.

rmm5t avatar Nov 18 '14 18:11 rmm5t

I'm getting it when using faker from FactoryGirl factories, but those are driven by rake tasks.

drewish avatar Jan 02 '15 22:01 drewish

Actually doesn't seem like rake has anything to do with it:

$ bundle exec rails c
=> Threadsafe!
Loading qa environment (Rails 3.2.21)
irb(main):001:0> require 'faker'
=> true
irb(main):002:0> Faker::Lorem.words(2).join('_')
I18n::MissingTranslationData: translation missing: en.faker.lorem.words
  from /data/shared/bundle/ruby/2.1.0/gems/i18n-0.6.11/lib/i18n.rb:314:in `handle_exception'
  from /data/shared/bundle/ruby/2.1.0/gems/i18n-0.6.11/lib/i18n.rb:160:in `translate'
  from /data/shared/bundle/ruby/2.1.0/gems/faker-1.4.3/lib/faker.rb:128:in `rescue in translate'
  from /data/shared/bundle/ruby/2.1.0/gems/faker-1.4.3/lib/faker.rb:120:in `translate'
  from /data/shared/bundle/ruby/2.1.0/gems/faker-1.4.3/lib/faker/lorem.rb:12:in `words'
  from (irb):2
  from /data/shared/bundle/ruby/2.1.0/gems/railties-3.2.21/lib/rails/commands/console.rb:47:in `start'
  from /data/shared/bundle/ruby/2.1.0/gems/railties-3.2.21/lib/rails/commands/console.rb:8:in `start'
  from /data/shared/bundle/ruby/2.1.0/gems/railties-3.2.21/lib/rails/commands.rb:41:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'

drewish avatar Jan 02 '15 22:01 drewish

Anyone have ideas on a workaround? Getting this issue from rake and from the console, and for many methods, not just words:

± bin/rails c
Loading development environment (Rails 4.1.8)
[1] pry(main)> require 'faker'
=> true
[2] pry(main)> Faker::Lorem.words(2)
I18n::MissingTranslationData: translation missing: en.faker.lorem.words
from /Users/thom/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/i18n-0.6.11/lib/i18n.rb:314:in `handle_exception'
[3] pry(main)> Faker::Company.name
I18n::MissingTranslationData: translation missing: en.faker.company.name
from /Users/thom/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/i18n-0.6.11/lib/i18n.rb:314:in `handle_exception'
[4] pry(main)> Faker::VERSION
=> "1.4.3"
...

Calling Faker::Config.locale = 'en' doesn't seem to make any difference.

EDIT Found workaround: add I18n.reload! sometime after you first require 'faker' in your environment. Source: this super-old issue

thom-nic avatar Feb 05 '15 20:02 thom-nic

yeah the I18n.reload! got it working for me too.

drewish avatar Feb 25 '15 19:02 drewish

Still an issue :disappointed: We're using faker (1.4.3) and rails (= 4.2.0)

StyleOffDev avatar Apr 24 '15 17:04 StyleOffDev

:-1: Still an issue w/ 1.4.3 & 4.2.0

fuzzyalej avatar May 12 '15 07:05 fuzzyalej

same here with 1.5.0 and 4.2.4

lessless avatar Dec 12 '15 16:12 lessless

Seems its working, check following

Loading test environment (Rails 4.2.4)
2.2.0 :001 > require 'faker'
 => false 
2.2.0 :002 > Faker::Lorem.words(2)
 => ["magni", "facere"] 
2.2.0 :003 > Faker::Company.name
 => "Gleason, Stanton and McKenzie" 
2.2.0 :004 > Faker::VERSION
 => "1.6.3" 

swapnilchincholkar avatar Apr 05 '16 13:04 swapnilchincholkar

require 'faker'
I18n.reload!

fixed for me as well

coorasse avatar Apr 26 '16 08:04 coorasse

Still an issue with 1.6.3 and rails 3.2.22.1

dunyakirkali avatar May 10 '16 12:05 dunyakirkali

Still an issue with 1.6.5 and rails 4.2.7

krisleech avatar Jul 19 '16 09:07 krisleech

Still doesn't seems an issue

Loading test environment (Rails 4.2.7)
2.2.0 :001 > Faker::VERSION
 => "1.6.5" 
2.2.0 :002 > Faker::Lorem.words(2)
 => ["cumque", "et"] 
2.2.0 :003 > Faker::Company.name
 => "Kuhn-Lakin" 

@krisleech could you provide any more info to debug

swapnilchincholkar avatar Jul 21 '16 08:07 swapnilchincholkar

@swapnilchincholkar I think you can reproduce this by specifying gem 'faker', require: false in your Gemfile, and then manually requiring faker right before usage.

deivid-rodriguez avatar Dec 03 '16 12:12 deivid-rodriguez

This is still an issue for me on 1.9.1 using Faker::Beer.brand. None of the above workarounds worked.

thisismydesign avatar Oct 24 '18 09:10 thisismydesign

@thisismydesign which ruby version were you using? Could you provide a sample application that reproduces the bug?

vbrazo avatar Oct 24 '18 12:10 vbrazo

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Rails 5.2.1

thisismydesign avatar Oct 24 '18 13:10 thisismydesign

Same for me, I get this error with 1.9.1 using Faker::Educator.degree. Ruby version: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux] Rails 5.1.5.

mvdamme avatar Nov 10 '18 17:11 mvdamme

Hello we 're having the same problem with this setup: rails 3.2.22.2, ruby 2.3.7, faker 1.9.1 In the Gemfile i tried gem 'faker' with and without require: false Our default locale is :de. In config/environments/test.rb i specified config.i18n.default_locale = :en. The setting of Faker::Config.locale = :fr in spec_helper.rb is ignored.

$ rails c test             
Loading test environment (Rails 3.2.22.2)
irb(main):001:0> I18n.locale
=> :en
irb(main):002:0> require 'faker'
=> true
irb(main):003:0> I18n.reload!
=> nil
irb(main):004:0> Faker::StarWars.quote
I18n::MissingTranslationData: translation missing: en.faker.star_wars.quotes
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/i18n-0.8.6/lib/i18n.rb:311:in `handle_exception'
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/i18n-0.8.6/lib/i18n.rb:161:in `translate'
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/faker-1.9.1/lib/faker.rb:162:in `rescue in translate'
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/faker-1.9.1/lib/faker.rb:150:in `translate'
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/faker-1.9.1/lib/faker/star_wars.rb:65:in `quote'
        from (irb):4
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/railties-3.2.22.2/lib/rails/commands/console.rb:47:in `start'
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/railties-3.2.22.2/lib/rails/commands/console.rb:8:in `start'
        from /home/name/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/railties-3.2.22.2/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

How can i tell Faker to not try to translate the phrases?

TimThaler avatar Nov 20 '18 08:11 TimThaler

I juste never call require 'faker' directly in rails. Where should I add the I18n.reload! to make it work with Rspec ?

jeremygachet avatar Dec 04 '18 15:12 jeremygachet

I placed it in

config.before :suite do
  I18n.reload!
end

coorasse avatar Jan 14 '19 13:01 coorasse