Module: Mobility::Backend::Table

Defined in:


Stores attribute translation as rows on a model-specific translation table (similar to Globalize). By default, the table name for a model Post with table posts will be post_translations, and the translation class will be Post::Translation. The translation class is dynamically created when the backend is initialized on the model class, and subclasses ActiveRecord::ModelTranslation (for AR models) or inherits Sequel::ModelTranslation (for Sequel models).

The backend expects the translations table (post_translations) to have:

  • a string column named locale to store the locale of the translation

  • columns for each translated attribute that uses the table (in general, this will be all attributes of the model)

  • an integer column with name post_id (where post is the name of the model class)

Unlike Globalize, attributes need not all be on one table. Mobility supports any number of translation tables for a given model class (all of the structure described above), provided the association_name option is different for each. Some translations can be stored on one translation table, others on another, and Mobility will handle mapping reads/writes to each. The subclass used in this case will be generated from the association_name by singularizing it and converting it to camelcase.

For more details, see examples in ActiveRecord::Table.

Backend Options


Name of association on model. Defaults to :mobility_model_translations. If specified, ensure name does not overlap with other methods on model or with the association name used by other backends on model (otherwise one will overwrite the other).


Name of translations table. By default, if the table used by the model is posts, the table name used for translations will be post_translations.


Foreign key to use in defining the association on the model. By default, if the model is a Post, this will be post_id. Generally this does not need to be set.


Subclass to use when dynamically generating translation class for model, by default :Translation. Should be a symbol. Generally this does not need to be set.

Defined Under Namespace

Classes: TranslationsCache

Method Summary

Methods included from OrmDelegator

#for, included