2

我被要求设计一个多语言应用程序,我需要建议,哪些是最好的方法与Rails。多种语言模型

基本上所有的表格都有一些不需要翻译的常见字段,还有一些需要翻译的字段。

谢谢

+1

外观在此:http://stackoverflow.com/questions/6700054/rails-i18n-via-database-column – apneadiving

回答

6

为此,将接近宝石globalize3。使用方便。

在你的Gemfile:

gem 'globalize' 

型号:

class Article < ActiveRecord::Base 
    translates :title, :text 
end 

和迁移:

class CreateArticles < ActiveRecord::Migration 
    def up 
    create_table :articles do |t| 
     t.timestamps 
    end 
    Article.create_translation_table! :title => :string, :text => :text 
    end 

    def down 
    drop_table :articles 
    Article.drop_translation_table! 
    end 
end 

和运行

rake db:migrate 
+0

Github网址已更改:https://github.com/globalize/globalize – Max

+0

谢谢,@Max!我已经更新了答案 – railscard