View Source EctoI18n.Schema (ecto_i18n v0.3.0)

Provides i18n extensions for Ecto.Schema.

Summary

Functions

Creates a field for storing localized contents.

Functions

Link to this macro

locales(name, list)

View Source (macro)

Creates a field for storing localized contents.

Example

defmodule MyApp.Shop.Product do
  use Ecto.Schema
  use EctoI18n.Schema, default_locale: "en", locales: ["zh-Hans", "zh-Hant"]

  schema "products" do
    field :sku, :string
    field :name, :string

    locales :locales do
      field :name, :string
    end
  end
end

In above code, calling:

locales :locales do
  field :name, :string
end

equals to:

embeds_one :locales, Locales do
  embeds_one :"zh-Hans", Fields
  embeds_one :"zh-Hant", Fields
end

The Locales and Fields modules will be generated automatically.