Further documentation can be found at https://hexdocs.pm/translate.
gleam add translate
Create a file for each locale in src/
src/
└── locale/
└── de-CH/
└── lang.json
└── en-US/
└── lang.json
de-CH/lang.json
{
"hello": {
"value": "Willkommen"
},
"amount_planets": {
"value": "Es gibt {AMOUNT} Planeten. Aber es waren mal {AMOUNT_BEFORE}."
}
}
en-US/lang.json
{
"hello": {
"value": "Welcome"
},
"amount_planets": {
"value": "There are {CURRENT} planets"
}
}
And use the translator like this
import translate/translator
let assert Ok(translator) =
translator.new_translator("de-CH")
|> translator.with_directory("src/locale")
|> translator.from_json()
let assert Ok(value) =
translator
|> translator.get_key("hello")
// value -> Willkommen
let assert Ok(value) =
translator
|> translator.get_key_with_args("amount_planets", [#("CURRENT", "7"), #("BEFORE", "8")])
// Es gibt 7 Planeten. Aber es waren mal 8.
Fork the project and clone it
You can run the tests with:
gleam test