Trek::Translatable
Multi-language attributes, backed by Mobility. Translated values are stored in jsonb columns keyed by locale.
API
ruby
class Page < ApplicationRecord
include Trek::Translatable
translate_attributes :title, :description
endtranslate_attributes(*attr_names) declares the translatable attributes (it delegates to Mobility's translates).
Usage
ruby
page = Page.create(title: "Home")
I18n.with_locale(:fr) { page.update(title: "Accueil") }
page.title # => "Home" (current locale)
I18n.with_locale(:fr) { page.title } # => "Accueil"Stored as:
json
{ "en": "Home", "fr": "Accueil" }