View Source TranslaTable (TranslaTable v0.3.1)

TranslaTable is a helper library for creating a translation schema inside your ecto schema.

Translation

Inside your config.exs add your locale config

config :transla_table, :config, locale_schema: MyApp.Locale

To define a translation schema it just need to use the TranslaTable helper inside your schema to be translated

defmodule MyApp.Post do
  use Ecto.Schema
  use TranslaTable.Schema,
    translation_schema: MyApp.PostTranslation

  import Ecto.Changeset

  alias MyApp.PostTranslation

  schema "post" do
    field :title, :string
    field :description, :string
    field :author, :string
    field :slug, :string

    has_many_translations()

    timestamps()
  end

  @doc false
  def changeset(post, attrs) do
    post
    |> cast(attrs, [:title, :description, :author, :slug])
    |> cast_translation()
  end
end

Then create the translation module

defmodule MyApp.PostTranslation
  use TranslaTable,
    schema: MyApp.Post,
    fields: [:title, :description, :slug]
end

Then the TranslaTable Macro will create a schema with the given fields and make the relation with your Locale schema.