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