Populating globalized (Globalize2) DB using db:seed
I,m using Globalize2. I'd like to populate DB with db:seed for different locales: en, de and ru. Is there a better solution then:
categories = [{ :en => 'Health & Beauty', :ru => 'Красота и здоровье', :de => 'Beauty & Gesundheit'},
{ :en => 'Baby', :ru => 'Детские товары', :de => 'Baby' }]
categories.each_index do |i|
I18n.locale = 'en'
Category.create(:name => categories[i][开发者_JAVA技巧:en])
I18n.locale = 'ru'
cat = Category.find(:last)
cat.name = categories[i][:ru]
cat.save
I18n.locale = 'de'
cat.name = categories[i][:de]
cat.save
end
?
As Globalize2 version 0.2.0 released, we can use a little simplier code:
categories = [{ :en => 'Health & Beauty', :ru => 'Красота и здоровье', :de => 'Beauty & Gesundheit'},
{ :en => 'Baby', :ru => 'Детские товары', :de => 'Baby' }]
categories.each_index do |i|
I18n.locale = 'en'
cat = Category.new :name => categories[i][:en]
I18n.locale = 'ru'
cat.name = categories[i][:ru]
I18n.locale = 'de'
cat.name = categories[i][:de]
cat.save
end
精彩评论