faker: 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. <del>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).</del>
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.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 2
- Comments: 37 (10 by maintainers)
Commits related to this issue
- Add gemfile group for testing a production-like deployment * Add production_test gemfile group, to cover gems that are not strictly needed in production, but still required to test a production-l... — committed to adisandro/Markus by adisandro 8 years ago
- Add gemfile group for testing a production-like deployment * Add production_test gemfile group, to cover gems that are not strictly needed in production, but still required to test a production-l... — committed to adisandro/Markus by adisandro 8 years ago
- Merge #1938 1938: Scheduled weekly dependency update for week 31 r=rehandalal a=pyup-bot ### Update [botocore](https://pypi.org/project/botocore) from **1.12.164** to **1.12.200**. <details> ... — committed to mozilla/normandy by bors[bot] 5 years ago
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 issueAfter some experimenting, I found for my case that it was the
enforce_available_localethat was causing this.I have only one available locale set in my rails app (:fr), so when Faker fallback to
:enlocale 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 :
Notice how if
enforce_available_localeis 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_localeso it could be used as well when loading the locales :To fix it in the Rails app, I manually set up
config.i18n.enforce_available_locales = falsein myconfig\environments\test.rbso 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.
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
fixed for me as well
Warning: This error will also occur if you accidentally use
.uniqinstead of.unique.Do you think we could possibly add this as an alias?
Any solutions to this 5 year old problem?
I tried
I18n.reload!without successFaker::Config.localealso did nothing for meAs @OlecsandrKirpa said. If u have more then one locale available for the application, just let rails know in config/application.rb
Note the answer from @vbrazo above: The right solution to this error is to change
Faker::Name.titletoFaker::Job.titlein 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 yourconfig/locales/en.yml(or other locale) file:Also seeing this with
Faker::Name.titleon Ruby 2.6.2I’m getting it when using faker from FactoryGirl factories, but those are driven by rake tasks.
It would be helpful if someone could provide a sample app and info on the environment that can reliably reproduce this error.
@DaKaZ Faker doesn’t provide
Faker::Name.titleanymore. It was deprecated last year and removed recently. Please useFaker::Job: https://github.com/stympy/faker/blob/master/doc/default/job.md.I juste never call require ‘faker’ directly in rails. Where should I add the I18n.reload! to make it work with Rspec ?
Hello we 're having the same problem with this setup:
rails 3.2.22.2, ruby 2.3.7, faker 1.9.1In the Gemfile i tried gem ‘faker’ with and withoutrequire: falseOur default locale is:de. Inconfig/environments/test.rbi specifiedconfig.i18n.default_locale = :en. The setting ofFaker::Config.locale = :frinspec_helper.rbis ignored.How can i tell Faker to not try to translate the phrases?
This is still an issue for me on
1.9.1usingFaker::Beer.brand. None of the above workarounds worked.yeah the
I18n.reload!got it working for me too.