3

我正在制作一个使用apartment gem的多租户应用程序。我已经设置好了,一切都按预期工作。我还使用带有活动记录后端的Rails Internationalization(I18n)来存储翻译。我的当前设置I18n没有使用公寓宝石轨道加载翻译

转换表

class CreateTranslations < ActiveRecord::Migration[5.0] 
    def change 
    create_table :translations do |t| 
     t.string :locale 
     t.string :key 
     t.text :value 
     t.text :interpolations 
     t.boolean :is_proc, default: false 

     t.timestamps 
    end 
    end 
end 

Apartment.rb配置

我已经在所有住户增加了翻译模型来排除模型的列表,以便其全球

Apartment.configure do |config| 

    # Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace. 
    # A typical example would be a Customer or Tenant model that stores each Tenant's information. 
    # 
    config.excluded_models = %w{ User Workspace Translation } 
end 

在我的翻译表我有翻译英语(默认)和挪威语。在主域中,一切都按预期在英语和挪威语之间切换,但是一旦我加载租户,所有翻译都会丢失。在控制台中演示:

> Apartment::Tenant.switch! # switch to main tenant 
> I18n.locale = :en # use English translations 
> I18n.t('home.members_label') 
    => "Show Members" 

> Apartment::Tenant.switch! "elabs" # switch to a different tenant 
> I18n.t('home.members_label') 
    => "translation missing: en.home.members_label" 

我不确定译文在租用环境中时为何缺失。我正在弄清楚在excluded_models列表中的翻译模型应该做的伎俩,但似乎有什么地方是错的。任何线索?由于

回答

0

Translation模型在I18n::Backend::ActiveRecord::Translation实际上说明,因此有可能你就必须以添加一个扩展,在模型文件夹或尝试做以下,看看是否能工作的模型:

config.excluded_models = %w{ User Workspace I18n::Backend::ActiveRecord::Translation } 

或者可能是

Translation = I18n::Backend::ActiveRecord::Translation 
config.excluded_models = %w{ User Workspace Translation }