3

I am making a multi tenancy app using the apartment gem. I have it all set up and everything works as expected. I'm also using Rails Internationalization (I18n) with active record backend to store translations. My current setup

Translation Table

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 configuration

I've added the Translation model to the list of excluded models so its global across all tenants

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

In my translations table I have translations for both English (default) and Norwegian. On the main domain everything works as expected switching between English and Norwegian but all translations go missing once I load a tenant. Demo in console:

> 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"

I'm not sure why translations are missing when in a tenanted environment. I was figuring having the Translation model in the list of excluded_models should do the trick but it seems something is wrong somewhere. Any clues? Thanks

Joseph N.
  • 2,437
  • 1
  • 25
  • 31

1 Answers1

0

The Translation model is actually defined in I18n::Backend::ActiveRecord::Translation, so it's possible you'll have to either add a model that extends that in model folder or try doing the following and see if that works:

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

or perhaps

Translation = I18n::Backend::ActiveRecord::Translation
config.excluded_models = %w{ User Workspace Translation }
typeoneerror
  • 55,990
  • 32
  • 132
  • 223