translecto v0.0.1 Translecto.Migration

Provides convenient functionality for creating tables that support translatable data.

Summary

Functions

Add a translatable field to a given table

Setup the table as a translation lookup. All fields in this table will now be translatable

Functions

translate(column, opts \\ [])

Specs

translate(atom, keyword) :: no_return

Add a translatable field to a given table.

This indicates that the field should be translated to access its contents. That it is a reference to a translation table.

create table(:ingredients) do
    translate :name, null: false
end
translation(opts \\ [])

Specs

translation(keyword) :: no_return

Setup the table as a translation lookup. All fields in this table will now be translatable.

Translation groups (groups of equivalent data) are specified using the :translate_id field. While the different translations for those individual groups is specified using the :locale_id, which will be of the type specified by the config or in the options argument under the :locale key. The following variants are:

# Adds a FK reference from :locale_id to the specified table. Optionally passing in
# any options specified.
{ :table, name }
{ :table, name, options }

# Adds a field of the specified type for the :locale_id field. Optionally passing in
# any options specified.
{ :type, type }
{ :type, type, options }

Unless overriden in the options, the table should have its default primary key set to false. While the new :translate_id and :locale_id fields become the composite primary keys.

create table(:ingredient_name_translations, primary_key: false) do
    translation
    add :term, :string, null: false
end

create table(:item_translations, primary_key: false) do
    translation locale: { :type, :char, [size: 2, null: false] }
    add :name, :string, null: false
    add :description, :string, null: false
end