Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I18n::MissingTranslationData: translation missing: en.faker error when seeding db

I want to seed the database with Faker, the problem is that I am getting an error when I do a:

rake db:reset

I get this message:

rake aborted!
I18n::MissingTranslationData: translation missing: en.faker.name.name
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:311:in `handle_exception'
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:161:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:128:in `rescue in translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:120:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:86:in `fetch'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:99:in `parse'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker/name.rb:8:in `name'
/Users/hbendev/code/wikitec/db/seeds.rb:6:in `block in <top (required)>'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `times'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:setup => db:seed

I don't know why is that error appearing, since I haven't got any problems with Faker before, I just wanted to reset the db to update the seeds.

I google it but I can't find anything related that solves the problem.

I tried to add:

I18n.reload!

After require 'faker' in my seeds.rb file, but no luck.

Looks like the problem is with Faker itself, because the database is being created properly, when I do a rake db:drop db:create db:migrate it works, until there, but when I try to seed the database with Faker with rake db:seed or rake db:reset, I get the error.

What can I do? Thanks in advance.

UPDATE - I included seeds.rb and en.yml files

seeds.rb:

require 'faker'

# Create Users
5.times do
  user = User.new(
    name: Faker::Name.name,
    email: Faker::Internet.email,
    password: Faker::Lorem.characters(10)
  )
  user.skip_confirmation!
  user.save!
end
users = User.all

# Create Wikis
25.times do
  Wiki.create!(
    title: Faker::Lorem.sentence,
    body: Faker::Lorem.paragraph,
    :private => false,
    user: users.sample
  )
end

# Create Admin account
admin = User.new(
  name: 'Admin User',
  email: '[email protected]',
  password: 'helloworld',
  role: 'admin'
  )
admin.skip_confirmation!
admin.save!

# Create Premium account
premium = User.new(
  name: 'Premium User',
  email: '[email protected]',
  password: 'helloworld',
  role: 'premium'
  )
premium.skip_confirmation!
premium.save!

# Create Standard account
standard = User.new(
  name: 'Standard User',
  email: '[email protected]',
  password: 'helloworld',
  role: 'standard'
  )
standard.skip_confirmation!
standard.save!

puts "Seed finished"
puts "#{Wiki.count} wikis created"
puts "#{User.count} users created"

en.yml:

en:
  hello: "Hello world"
like image 224
bntzio Avatar asked May 11 '15 19:05

bntzio


2 Answers

In my case, the I18n available_locales config did not include en:

config.i18n.available_locales = %i[de de_en]

I reverted it back to

config.i18n.available_locales = %i[de en]

and it worked.

like image 166
Motine Avatar answered Oct 26 '22 12:10

Motine


Check the I18n Faker configuration info here:

https://github.com/stympy/faker#customization

Looks like you should enforce the I18n Faker locale in case you are using a non standard locale in your app.

Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.

like image 25
Jorge de los Santos Avatar answered Oct 26 '22 14:10

Jorge de los Santos