3

apartment gemを使用してマルチテナントアプリを作成しています。私はそれをすべてセットアップし、すべてが期待どおりに動作します。また、翻訳を保存するためにアクティブなレコードバックエンドを持つRails Internationalization(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 } 
関連する問題