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

Switch to 18n is not playing nice with rails #5

Closed
morgoth opened this issue Dec 22, 2010 · 29 comments
Closed

Switch to 18n is not playing nice with rails #5

morgoth opened this issue Dec 22, 2010 · 29 comments

Comments

@morgoth
Copy link

morgoth commented Dec 22, 2010

Faker should not change I18n locale (however this can be easly fixed by setting Faker::Config.locale).

Other problem after updating faker gem, when running specs in rails application is lots of failing tests:

Expected errors to include "translation missing: en.errors.messages.blank" when user_id is set to nil, got errors: user_id translation missing: en.activerecord.errors.models.billing.attributes.user_id.blank (nil)app_id translation missing: en.activerecord.errors.models.billing.attributes.app_id.blank (nil)

Rails 2.3.10, Ruby ree-1.8.7-2010.02

@stympy
Copy link
Contributor

stympy commented Dec 22, 2010

I just released 0.9.1 which doesn't stomp on the default locale any more. I'll have to take a longer look at the failing test issue.

@stympy
Copy link
Contributor

stympy commented Dec 22, 2010

And now 0.9.2 is out. :) This version stops clobbering the load path, which may have been the test problem.

@morgoth
Copy link
Author

morgoth commented Dec 22, 2010

Now is working fine.
Thanks.

@sporkd
Copy link

sporkd commented Dec 23, 2010

Just got the ripple effect from this. Thanks for the quick fix!

@rafaelfranca
Copy link

It's not working for me. The default locale of application don't work in test environment in the 0.9.2 version. The gem change the locale for 'en' and my default locale is 'pt_BR'

@stympy
Copy link
Contributor

stympy commented Dec 28, 2010

rafael, perhaps you could put together a sample app that shows the problem?

@rafaelfranca
Copy link

Sure! It's here: https://github.com/rafaelfranca/faker_test

@stympy
Copy link
Contributor

stympy commented Dec 29, 2010

rafael, I just pushed some changes that should fix the problem for you (the test app now passes the tests). Also, note the change in the readme about setting locale in Rails.

@rafaelfranca
Copy link

Nice! Thanks.

@lgrains
Copy link

lgrains commented Feb 18, 2011

I'm seeing more of these types of errors:

=> nil
ruby-1.9.2-p136 :003 > Factory(:merchant)
NoMethodError: private method rand' called for "translation missing: en.faker.name.last_name":String from /Users/lrains/.rvm/gems/ruby-1.9.2-p136@hazzoo/gems/faker-0.9.5/lib/faker.rb:37:infetch'
from /Users/lrains/.rvm/gems/ruby-1.9.2-p136@hazzoo/gems/faker-0.9.5/lib/faker/name.rb:10:in last_name' from /Users/lrains/.rvm/gems/ruby-1.9.2-p136@hazzoo/gems/faker-0.9.5/lib/faker/company.rb:35:inblock

I'm running Rails 3, ruby 1.9.2, and faker 0.9.5. This only happens in Rails Console. It's working fine inside my application.

@roberthead
Copy link

I'm having the same problem as lgrains.

@marklocklear
Copy link

I was having problems running faker on Heroku. The error I was getting was was: rake task error is: private method `rand' called for "translation missing: en.faker.address.street_address":String

I was able to fix this by adding the faker version of the locals/en.yml to my heroku repo.

@agenteo
Copy link

agenteo commented Apr 7, 2011

same problem as Igrains here, with

private method `rand' called for "translation missing: en.faker.name.first_name":String

faker 0.9.5 (testing a Radiant 0.9.1 extension with rspec 1.1.12)
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin10.7.0]

@rubiety
Copy link

rubiety commented Apr 11, 2011

Just wanted to comment that I was still running into an issue with this myself with faker 0.9.5. I fixed it by explicitly telling I18n to reload after requiring "faker" in my spec_helper.rb:

I18n.reload!

For my app, I believe this was because a translation was accessed in an initializer before faker was required. This probably means that I18n loaded everything in the I18n.load_path before faker added to the load path. So even though faker is adding to the load path, it is not forcing a reload of I18n. In most cases this is fine (as in, when no translations are accessed before faker is required), but in my case it was not.

@stympy It may be worthwhile forcing an I18n reload after you modify the load_path in the gem anyways; this is probably good practice, just in case.

@maca
Copy link

maca commented Apr 14, 2011

Same issue here: private method `rand' called for "translation missing: pt-BR.faker.address.street_address":ActiveSupport::SafeBuffer

Whats the fix?

@rubiety
Copy link

rubiety commented Apr 14, 2011

@maca Check out my last comment - until this is done within the faker gem, you should call this immediately after requiring faker in your spec_helper.rb:

I18n.reload!

@maca
Copy link

maca commented Apr 14, 2011

Thanks it did the trick, I tried before

I had to add gem 'faker', :require => nil to my Gemfile

and manually requiring in spec_helper, in the line below I added I18n.reload!

@stympy
Copy link
Contributor

stympy commented Apr 14, 2011

@rubiety, thanks for the tip - I have pushed this change. if you and @maca could try it out and let me know if it works for you, I'll push a new gem.

Thanks!

@maca
Copy link

maca commented Apr 15, 2011

Hi, I used your last pull with no luck.

I still have to manually require faker in my spec_helper instead of using the Gemfile and do the I18n reload.

@maca
Copy link

maca commented Apr 15, 2011

It actually works for rspec but not for cucumber

my env.rb:

       require 'cucumber/rails'
       require 'faker'

       I18n.reload!

       Dir[Rails.root.join("test/factories/**/*.rb")].each {|f| require f}
       ...

@maca
Copy link

maca commented Apr 19, 2011

Had to switch back to 0.3.1 and ignore deprecation warnings for #returning

@haarts
Copy link

haarts commented Apr 28, 2011

I still have this issue.

@JonKernPA
Copy link

@rubiety thanks for preserving the hair on my head... I spent 30 minutes wondering WTF was going on with Faker inside my FactoryGirl stuff for errors like this:

private method `rand' called for "translation missing: en.faker.name.first_name"

and your tip worked like a charm!

require 'factory_girl'
require 'faker'
I18n.reload!  # <== Thanks @rubiety

I also had to do this in environment.rb:

config.i18n.default_locale = :en

or you can do this:

config.i18n.locale = :en

@hoblin
Copy link

hoblin commented Jun 23, 2011

Still have this issue. It appears on Jenkins builds.
I18n.reload! not helps
https://gist.github.com/1041713
Rails 2.3.8
Ruby 1.8.7 p334 (RVM)
Feel free to ask additional info

@cimm
Copy link

cimm commented Jul 20, 2011

Pulling the gem from github after commit 22a9476 fixed it for me (Rails 3.1 and Ruby 1.9.2). Thanks!

@hoblin
Copy link

hoblin commented Jul 20, 2011

I'm switch to ffaker gem =)

shapeshed pushed a commit to shapeshed/faker that referenced this issue Sep 16, 2011
@mulderp
Copy link

mulderp commented Sep 22, 2011

I am also setting in config/application.rb

config.i18n.locale = :de

Because I still see a problem that :en locale is taken as default with ruby 1.8.7, Rails 3.0.10 Faker 1.0

@simicic
Copy link

simicic commented Feb 5, 2015

Setting :en for me was not an option and switching to ffaker worked out well, if someone else still has this issue...

@lreardon
Copy link

lreardon commented May 9, 2023

FWIW I was running into the same issue and none of the above workarounds were, well, working.

In my case, I was just not calling the right method. Eg. I was calling Faker::Name.firstname, but the actual method is Faker::Name.first_name. Take care of snake-case in method names!

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

No branches or pull requests