# g18n-dev

A small development-time generator for g18n webpage translations.

[![Package Version](https://img.shields.io/hexpm/v/g18n_dev)](https://hex.pm/packages/g18n_dev)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/g18n_dev/)

## Installation

Add the runtime package and the development generator:

```sh
gleam add g18n
gleam add --dev g18n_dev
```

## Translation files

Place one JSON file per language in your application's translation directory:

```text
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:

```json
{
  "page.title": "Welcome",
  "page.greeting": "Hello {name}!"
}
```

Or nested objects:

```json
{
  "page": {
    "title": "Welcome",
    "greeting": "Hello {name}!"
  }
}
```

Both formats may be used with the same command.

## Generate the module

```sh
gleam run -m g18n/dev generate
```

The generator writes `src/<project>/translations.gleam`. For `en.json`, it
creates:

- `en_translations() -> g18n.Translations`
- `en_translator() -> g18n.Translator`

It also creates:

- `available_languages() -> List(String)`
- `all_translators() -> List(#(String, g18n.Translator))`

Use the generated module directly in a webpage:

```gleam
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

```text
generate  Generate the translation module from every JSON file
help      Show command help
```

## License

MIT
