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

Faker::Address.country does not work if your apps does not use :en as a locale #266

Closed
bsylvain opened this issue Oct 22, 2014 · 12 comments · Fixed by #1785
Closed

Faker::Address.country does not work if your apps does not use :en as a locale #266

bsylvain opened this issue Oct 22, 2014 · 12 comments · Fixed by #1785

Comments

@bsylvain
Copy link

Rail 3.2
Faker 1.4.3

When I use Faker::Address.country with config.i18n.available_locales = [:fr,:it] I have the following error :

Failure/Error: let(:user) { FactoryGirl.create(:user_with_recurring_order_to_generate)}
 I18n::InvalidLocale:
   :en is not a valid locale

It stop if I remove Faker::Address.country from my factory or if I ad :en to available locales.

@allaire
Copy link

allaire commented Nov 3, 2014

Same here, adding :en to available_locales seems to do it.

@markoudev
Copy link

Had the same issue with Faker::Company.name. Adding this to your config/environments/test.rb resolves the issue for now:

config.i18n.available_locales += %w(en)

The issue is in faker.rb, over here: https://github.com/stympy/faker/blob/master/lib/faker.rb#L128 -- For apps that don't have 'en' as a valid locale, this won't work.

@coorasse
Copy link

coorasse commented Dec 3, 2015

Same with Faker::Internet.mail

@coorasse
Copy link

coorasse commented Jul 4, 2017

This issue is still open and Faker does not work for apps which don't support english. I am stuck at version 1.5.0

@vbrazo
Copy link
Member

vbrazo commented May 13, 2018

@bsylvain @coorasse I'm a new collaborator, and I'm trying to solve and close the issues.

I know it's been a while since you guys discussed about this issue. I would like to ask you if we still need to work on this issue and how I could help.

Thanks 👍

@coorasse
Copy link

Hello @vbrazo, yes. the issue is still open and valid. I haven't investigated what is causing it so I cannot help you on which direction to follow to solve it. I think the expected behaviour is that the generator works also if english is not available.

@bsylvain
Copy link
Author

bsylvain commented Jun 7, 2018

I still have to add :en on the test env on my apps using Faker. It makes the test env different from production.

@deivid-rodriguez
Copy link
Contributor

This was fixed by #1377.

@vbrazo vbrazo closed this as completed Oct 11, 2018
@coorasse
Copy link

coorasse commented Jan 4, 2019

It doesn't seem like. If I use the latest version on master I obtain the following:

irb(main):002:0> Faker::Address.country
Traceback (most recent call last):
        1: from (irb):2
I18n::MissingTranslationData (translation missing: en.faker.address.country)

@deivid-rodriguez
Copy link
Contributor

Oops, sorry for the false notice then! :S

@stympy stympy reopened this Jan 4, 2019
@coorasse
Copy link

coorasse commented May 2, 2019

I recently faced it again with Faker::Name.last_name

@anderscarling
Copy link

I worked around it by dropping this in my test_helper.rb (must run after faker is loaded).

# Workaround for optimization where I18n::Backend::Simple doesn't load
# translations for locales not in available_locales, thus making them
# unavailable even though faker disables enforce_available_locales while
# looking up translations..
i18n_did_enforce_available_locales = I18n.enforce_available_locales
begin
  I18n.enforce_available_locales = false
  I18n.reload!
  I18n.eager_load!
ensure
  I18n.enforce_available_locales = i18n_did_enforce_available_locales
end

It's not really pretty, but gets the job done and since available_locales are enforced by I18n on both lookup and loading of translations, it should hopefully not change behaviour for other users.

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

Successfully merging a pull request may close this issue.

8 participants