View Source EctoI18n.Schema (ecto_i18n v0.5.0)

Provides i18n extensions for Ecto.Schema.

Summary

Functions

Creates a virtual field and an embed for storing localized data.

Functions

Link to this macro

field_i18n(name, type \\ :string, opts \\ [])

View Source (macro)

Creates a virtual field and an embed for storing localized data.

Example

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

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

In above code, calling:

field_i18n :name, :string

equals to:

field :name, :string, virtual: true
embeds_one :name_i18n, NameI18n do
  field :"en", :string
  field :"zh-Hans", :string
end

The NameI18n module will be generated automatically.