0

現在我有模型Territory - id, territory_title_locale_key在我的數據庫如何做出更好的Rails的I18n(整理和翻譯搜索)

我有en.ymlru.yml文件與翻譯。將來,我想添加更多的區域設置。現在我展示價值 - I18n.t("translate_path.#{territory.territory_title_locale_key}")

但我無法通過標題的價值快速搜索區域並按標題排序。

我看到的變體:

更改數據庫Territory - id, title, en, ru, es, ...始終鍵入Territory.where(my_condition).select("#{I18n.locale} as title")(爲每個新的語言環境,我必須添加列到數據庫)。

或者創建附加表格Translations,其中包含多態引用,翻譯和locale_ids。

如何讓它變得更好?

回答

0

看看全球化的寶石,它會做你正在尋找的東西。 https://github.com/globalize/globalize

實施例:

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

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

I18n.locale = :he 
post.title # => גלובאלייז2 שולט!