Something went wrong. Try again.
JSON translation code generator for g18n projects
Something went wrong. Try again.
Gleam 100%
README.md
g18n-dev #
A small development-time generator for g18n webpage translations.
Installation #
Add the runtime package and the development generator:
gleam add g18n
gleam add --dev g18n_dev
Translation files #
Place one JSON file per language in your application's translation directory:
src/<project>/translations/
├── en.json
├── es.json
└── fr.json
The filename identifies the language but has no runtime semantics. g18n does not apply locale or language rules.
Each file may use flat dotted keys:
{
"page.title": "Welcome",
"page.greeting": "Hello {name}!"
}
Or nested objects:
{
"page": {
"title": "Welcome",
"greeting": "Hello {name}!"
}
}
Both formats may be used with the same command.
Generate the module #
gleam run -m g18n/dev generate
The generator writes src/<project>/translations.gleam. For en.json, it
creates:
en_translations() -> g18n.Translationsen_translator() -> g18n.Translator
It also creates:
available_languages() -> List(String)all_translators() -> List(#(String, g18n.Translator))
Use the generated module directly in a webpage:
import g18n
import my_app/translations
let translator = translations.en_translator()
g18n.translate(translator, "page.title")
Your application chooses the generated translator. The generator does not parse locales, negotiate languages, apply plural rules, or add browser runtime code.
Commands #
generate Generate the translation module from every JSON file
help Show command help
License #
MIT