多语言环境翻译的种子文件

Seed file for multiple locale translations

我正在使用 db/seeds.rb 来播种一些段落;但我需要为多种语言 (I18n) 提供种子。

这是我的:

school = Building.create(
  :body => 'My school'
)

这是我假装的:

school = Building.create(
  :body => 'My school'
)
# here I should change locale
school.create(
  :body => 'Mi escuela'
)

我应该如何编写代码才能在同一个种子文件中为多个语言环境播种?

我会使用全球化 Gem:https://github.com/globalize/globalize。请务必查看安装和模型设置说明。

这是一个例子:

class Post < ActiveRecord::Base
  translates :title, :name
end

然后在你的种子文件中:

I18n.locale = :en
post.title # => 'Globalize rocks!'
post.name  # => 'Globalize'

I18n.locale = :nl
post.title # => ''
post.name  # => 'Globalize'