Giter VIP home page Giter VIP logo

exi18n's Introduction

ExI18n

hex.pm version Build Status Coverage Status Inline docs

ExI18n is key-based internationalization library for Elixir.

Table of Contents

Installation

Add exi18n to your list of dependencies and to applications in mix.exs:

# mix.exs

def deps do
  [
    {:exi18n, "~> 0.9.0"},
  ]
end

def application do
  [applications: [
    :exi18n,
  ]]
end

Configuration

Add configuration to your config/config.exs:

# config.exs

config :exi18n,
  default_locale: "en",
  locales: ~w(en),
  fallback: false,
  loader: :yml,
  loader_options: %{path: "priv/locales"},
  var_prefix: "%{",
  var_suffix: "}"

Configuration parameters

Option Description Default
default_locale Default locale in your application. "en"
locales Supported locales. ["en"]
fallback Fallback to default locale if translation empty. false
loader Translation loader. Supported types: :yml, :http, MyApp.Loader. :yml
loader_options Translation loader options. %{}
var_prefix Prefix for values in translations. "%{"
var_suffix Suffix for values in translations. "}"

Loaders

YAML

This loader will use yaml files from path to load translations.

Module

ExI18n.Loader.YAML

Dependencies

# mix.exs

def deps do
  [
    {:exi18n, "~> 0.9.0"},
    {:yaml_elixir, "~> 2.0"},
  ]
end

def application do
  [applications: [
    :exi18n,
    :yaml_elixir,
  ]]
end

Configuration

Option Required Description
path Yes Path to locale files.
# config.exs

config :exi18n,
  loader: :yml,
  loader_options: %{
    path: "priv/locales" # or {MyHelper, :path, ["priv/locales"]}
  }

Custom

Module

MyApp.Loader

Make sure that your custom loader has load/2 function that accepts locale and options as parameters and returns Map with translations.

Example:

defmodule MyApp.Loader do
  def load(locale, _options) do
    %{
      "en" => %{...},
      "de" => %{...}
    }[locale]
  end
end

Dependencies

# mix.exs

def deps do
  [
    {:exi18n, "~> 0.9.0"},
  ]
end

def application do
  [applications: [
    :exi18n,
  ]]
end

Configuration

# config.exs

config :exi18n,
  loader: MyApp.Loader,
  loader_options: %{my_config: "value"}

Documentation

https://hexdocs.pm/exi18n

exi18n's People

Contributors

gvl avatar mavuio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.