TranslaTable (TranslaTable v0.2.0) View Source
TranslaTable
is a helper library for creating a translation schema inside your ecto schema.
Translation
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
import Ecto.Changeset
import TranslaTable
alias MyApp.PostTranslation
schema "post" do
field :title, :string
field :description, :string
field :author, :string
field :slug, :string
has_many_translations PostTranslation
timestamps()
end
@doc false
def changeset(post, attrs) do
post
|> cast(attrs, [:title, :description, :author, :slug])
|> cast_translation(PostTranslation)
end
end
Then create the translation module
defmodule MyApp.PostTranslation
alias MyApp.Post
alias MyApp.Language
use TranslaTable,
module: Post, # Module to be translated
lang_mod: Language, # Language schema table
fields: [:title, :description, :slug]
end
Then the TranslaTable Macro will create a schema with the given fields and make the relation with your Language
module.