https://github.com/salif/aham
[Mirror] Build multilingual Gleam applications
https://github.com/salif/aham
gleam gleam-lang i18n internationalization localisation localization
Last synced: 5 months ago
JSON representation
[Mirror] Build multilingual Gleam applications
- Host: GitHub
- URL: https://github.com/salif/aham
- Owner: salif
- License: bsl-1.0
- Created: 2024-07-22T11:49:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T11:52:24.000Z (almost 2 years ago)
- Last Synced: 2025-10-06T20:56:57.645Z (8 months ago)
- Topics: gleam, gleam-lang, i18n, internationalization, localisation, localization
- Language: Gleam
- Homepage: https://hex.pm/packages/aham
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# aham
[](https://hex.pm/packages/aham)
[](https://hexdocs.pm/aham/)
```sh
gleam add aham@1
```
```gleam
import aham
import gleam/io
import locale
// Esperanto
const messages_eo: aham.Bundle = [#("Hello", "Saluton"), #("world", "mondo")]
// Turkish
const messages_tr: aham.Bundle = [#("Hello", "Merhaba"), #("world", "dünya")]
// Bulgarian
const messages_bg: aham.Bundle = [#("Hello", "Здравей"), #("world", "свят")]
// Bulgarian Test (made-up)
const messages_bg_test: aham.Bundle = [#("Hello", "Zdravei")]
pub fn main() {
// The examples use the Esperanto locale
// There are two ways to use:
// With values
let messages =
aham.new_with_values()
|> aham.auto_add_bundle(locale.get_locale(), [
#("eo", "", messages_eo),
#("tr", "TR", messages_tr),
#("bg", "BG", messages_bg),
#("bg", "TEST", messages_bg_test),
])
messages |> aham.get("Hello") |> io.println
// Prints "Saluton" in Esperanto
messages |> aham.get("Not translated yet") |> io.println
// Prints "Not translated yet" in English
// With keys
let messages2 =
aham.new_with_keys([
#("key1", "Hello"),
#("key2", "world"),
#("key1000", "I am not translated"),
])
|> aham.auto_add_bundle(locale.get_locale(), [
#("eo", "", [#("key1", "Saluton"), #("key2", "mondo")]),
])
messages2 |> aham.get_key("key1") |> io.println
// Prints "Saluton" in Esperanto
messages2 |> aham.get_key("key1000") |> io.println
// Prints "I am not translated" in English
messages2 |> aham.get_key("key.does.not.exist") |> io.println
// Prints an empty string
}
```
Further documentation can be found at .
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```