Faker::Lorem.paragraph raises I18n::MissingTranslationData without manual locale override
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.
I'm getting it when using faker from FactoryGirl factories, but those are driven by rake tasks.
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>'
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
yeah the I18n.reload! got it working for me too.
Still an issue :disappointed: We're using faker (1.4.3) and rails (= 4.2.0)
:-1: Still an issue w/ 1.4.3 & 4.2.0
same here with 1.5.0 and 4.2.4
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"
require 'faker'
I18n.reload!
fixed for me as well
Still an issue with 1.6.3 and rails 3.2.22.1
Still an issue with 1.6.5 and rails 4.2.7
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 I think you can reproduce this by specifying gem 'faker', require: false in your Gemfile, and then manually requiring faker right before usage.
This is still an issue for me on 1.9.1 using Faker::Beer.brand. None of the above workarounds worked.
@thisismydesign which ruby version were you using? Could you provide a sample application that reproduces the bug?
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Rails 5.2.1
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.
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?
I juste never call require 'faker' directly in rails. Where should I add the I18n.reload! to make it work with Rspec ?
I placed it in
config.before :suite do
I18n.reload!
end