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
Using I18n.reload! doesn't seem to fix it for me with rails 5.5.2, faker 1.9.3, rspec-core 3.8.0, and ruby 2.5.1
I tried all the ways without any success with rails (5.2.2), faker (1.9.3) and ruby 2.5.0.
Despite I configure Faker::Config.locale in a faker.rb, on every try the Faker tries to load en.yml.
Also seeing this with Faker::Name.title on Ruby 2.6.2
$ irb
2.6.2 :001 > require 'faker'
=> true
2.6.2 :002 > Faker::VERSION
=> "1.9.3"
2.6.2 :003 > Faker::Name.title
Traceback (most recent call last):
11: from /Users/mskazmie/.rvm/rubies/ruby-2.6.2/bin/irb:23:in `<main>'
10: from /Users/mskazmie/.rvm/rubies/ruby-2.6.2/bin/irb:23:in `load'
9: from /Users/mskazmie/.rvm/rubies/ruby-2.6.2/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
8: from (irb):3
7: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:192:in `method_missing'
6: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:151:in `translate'
5: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:163:in `rescue in translate'
4: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:244:in `disable_enforce_available_locales'
3: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:164:in `block in translate'
2: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/i18n-1.6.0/lib/i18n.rb:195:in `translate'
1: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/i18n-1.6.0/lib/i18n.rb:357:in `handle_exception'
I18n::MissingTranslationData (translation missing: en.faker.name.title)
2.6.2 :004 > Faker::Config.locale
=> :en
2.6.2 :005 > I18n.reload!
=> nil
2.6.2 :006 > Faker::Name.title
Traceback (most recent call last):
11: from /Users/mskazmie/.rvm/rubies/ruby-2.6.2/bin/irb:23:in `<main>'
10: from /Users/mskazmie/.rvm/rubies/ruby-2.6.2/bin/irb:23:in `load'
9: from /Users/mskazmie/.rvm/rubies/ruby-2.6.2/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
8: from (irb):6
7: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:192:in `method_missing'
6: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:151:in `translate'
5: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:163:in `rescue in translate'
4: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:244:in `disable_enforce_available_locales'
3: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/faker-1.9.3/lib/faker.rb:164:in `block in translate'
2: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/i18n-1.6.0/lib/i18n.rb:195:in `translate'
1: from /Users/mskazmie/.rvm/gems/ruby-2.6.2/gems/i18n-1.6.0/lib/i18n.rb:357:in `handle_exception'
I18n::MissingTranslationData (translation missing: en.faker.name.title)
@DaKaZ Faker doesn't provide Faker::Name.title anymore. It was deprecated last year and removed recently. Please use Faker::Job: https://github.com/stympy/faker/blob/master/doc/default/job.md.
@vbrazo ahhh, sorry, stupid user error ;) I didn't even think to check that the API had changed. Thanks
Any solutions to this 5 year old problem?
I tried I18n.reload! without success
Faker::Config.locale also did nothing for me
I am having the I18n::MissingTranslationData (translation missing: en.faker) in my test suite as well.
I run with RSpec.config.order = :random and sometimes the tests all pass, and sometimes they all fail due to faker running into missing translation error.
If I run with no random order, then I encounter no errors.
I isolated multiple seeds in which the tests all fail. I have no idea if this could be a lead onto something. (38629 , 56820 )
I'm just going to disable the random order for now, but I'm eager to see this bug resolved as it is not a viable solution.
Also depending if I run my test suite with bundle exec rspec or rspec I have differents outputs (all fail => all pass).
In conclusion I believe it's just related to the order in which the files are required, as I have a default case in which everything works fine.
My env:
Rails.config.action_view.raise_on_missing_translations = false
I18n.config.available_locales = :fr
I18n.config.default_locale = :fr
Faker::Config.locale = 'fr'
ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
------
faker-1.9.6
i18n-1.6.0
------
Rails 5.2.3
------
RSpec 3.8
- rspec-core 3.8.2
- rspec-expectations 3.8.4
- rspec-mocks 3.8.1
- rspec-rails 3.8.2
- rspec-support 3.8.2
@stympy ping
It would be helpful if someone could provide a sample app and info on the environment that can reliably reproduce this error.
After some experimenting, I found for my case that it was the enforce_available_locale that was causing this.
I have only one available locale set in my rails app (:fr), so when Faker fallback to :en locale then it raises MissingTranslation because :en locale was not loaded in a first place :
When faker load its locales, the enforce available locale is defaulted to true by Rails if not set, and so the :en locale file is skipped, raising later a MissingTranslation error in case the fallback to :en is needed.
Here is how I18n filter the given .yml in load_paths :
def store_translations(locale, data, options = EMPTY_HASH)
if I18n.enforce_available_locales &&
I18n.available_locales_initialized? &&
!I18n.available_locales.include?(locale.to_sym) &&
!I18n.available_locales.include?(locale.to_s)
return data
end
locale = locale.to_sym
translations[locale] ||= {}
data = data.deep_symbolize_keys
translations[locale].deep_merge!(data)
end
Notice how if enforce_available_locale is true then the .yml locale must be specified in available_locales in order to be loaded.
Maybe Faker could force load the :en yml locale files into I18n, because it is needed internally by Faker, even if the whole Rails app doesnt need english at all.
This can handle the case where the fallback to :en locale is needed , but the Rails env has no :en in available locale and enforce is true by default.
I noticed Faker already plays with enforce_available_locale so it could be used as well when loading the locales :
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
I18n.reload! if I18n.backend.initialized?
To fix it in the Rails app, I manually set up config.i18n.enforce_available_locales = false in my config\environments\test.rb so when Faker loads the locales, nothing is skipped.
Other solution could be to add :en to available_locale for the test env, before Faker is loading yml locales.
Note the answer from @vbrazo above: The right solution to this error is to change Faker::Name.title to Faker::Job.title in your code.
But if you just want to make the error go away, and I18n.reload! isn't working for you, you can add the missing translation to your config/locales/en.yml (or other locale) file:
en:
faker:
name:
title: 'Title'
Warning: This error will also occur if you accidentally use .uniq instead of .unique.
Do you think we could possibly add this as an alias?
I have this problem with locale de for de.faker.lorem.punctuation.space.
This happen, because faker do not have translations for this key in de locale and I do not load the en locale as fallback
or you use the fallback, but then you need to define all fallbacks:
require 'i18n/backend/fallbacks'
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.fallbacks = { de: [:de, :en], en: [:en] }
Most helpful comment
Anyone have ideas on a workaround? Getting this issue from rake and from the console, and for many methods, not just
words:Calling
Faker::Config.locale = 'en'doesn't seem to make any difference.EDIT Found workaround: add
I18n.reload!sometime after you firstrequire 'faker'in your environment. Source: this super-old issue