Add the linguist library from Chris McCord for internationalization in Elixir language or the Phoenix framework.
Usage
Create a .exs file for each language, defining a list of nested translations. Here’s one you could use for English:
[
greetings: [
morning: "Good Morning",
afternoon: "Good Afternoon"
]
]
In your code module:
defmodule I18n do
# import the linguist module
use Linguist.Vocabulary
# load each language's .exs file
locale "en", Path.join([__DIR__, "en.exs"])
end
# use the translation
I18n.t!("en", "greetings.morning")
Interpolation
The documentation on that page shows how to make translations with interpolation (including values and names in the translated text).
[
greetings: [
morning: "Good morning, %{name}!"
]
]
And in your source code:
defmodule I18n
use Linguist.Vocabulary
locale "en", Path.join([__DIR__, "en.exs"])
end
I18n.t!("en", "greetings.morning", name: "Dave")
Upgrading from Phoneix <= 0.6.x
In December 2014, Phonenix 0.7.x removed linguist as a default dependency. You need to include linguist as a dependency for your app.
Unsupported
The linguist library does not currently support multilingual plurals.
Follow this issue on GitHub.