https://github.com/gvl/exi18n
ExI18n is key-based internationalization library for Elixir.
https://github.com/gvl/exi18n
elixir i18n internationalisation translation yaml
Last synced: 3 months ago
JSON representation
ExI18n is key-based internationalization library for Elixir.
- Host: GitHub
- URL: https://github.com/gvl/exi18n
- Owner: gvl
- License: mit
- Created: 2017-02-27T12:51:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-10-26T16:07:52.000Z (almost 4 years ago)
- Last Synced: 2025-04-06T04:41:13.508Z (7 months ago)
- Topics: elixir, i18n, internationalisation, translation, yaml
- Language: Elixir
- Homepage:
- Size: 71.3 KB
- Stars: 7
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ExI18n
[](https://hex.pm/packages/exi18n) [](https://travis-ci.org/gvl/exi18n) [](https://coveralls.io/r/gvl/exi18n?branch=master) [](http://inch-ci.org/github/gvl/exi18n)
**ExI18n** is key-based internationalization library for Elixir.
## Table of Contents
* [Installation](#installation)
* [Configuration](#configuration)
* [Configuration parameters](#configuration-parameters)
* [Loaders](#loaders)
* [YAML](#yaml)
* [Custom](#custom)
* [Documentation](#documentation)## Installation
Add `exi18n` to your list of dependencies and to `applications` in `mix.exs`:
```elixir
# mix.exsdef deps do
[
{:exi18n, "~> 0.9.0"},
]
enddef application do
[applications: [
:exi18n,
]]
end
```## Configuration
Add configuration to your `config/config.exs`:
```elixir
# config.exsconfig :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
```elixir
# mix.exsdef deps do
[
{:exi18n, "~> 0.9.0"},
{:yaml_elixir, "~> 2.0"},
]
enddef application do
[applications: [
:exi18n,
:yaml_elixir,
]]
end
```#### Configuration
| Option | Required | Description |
| :-- | :--: | :-- |
| path | **Yes** | Path to locale files. |```elixir
# config.exsconfig :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:
```elixir
defmodule MyApp.Loader do
def load(locale, _options) do
%{
"en" => %{...},
"de" => %{...}
}[locale]
end
end
```#### Dependencies
```elixir
# mix.exsdef deps do
[
{:exi18n, "~> 0.9.0"},
]
enddef application do
[applications: [
:exi18n,
]]
end
```#### Configuration
```elixir
# config.exsconfig :exi18n,
loader: MyApp.Loader,
loader_options: %{my_config: "value"}
```## Documentation
[https://hexdocs.pm/exi18n](https://hexdocs.pm/exi18n)