crababel v0.2.0
crababel
TODO: Write a description here
Installation
-
Add the dependency to your
shard.yml:dependencies: crababel: github: your-github-user/crababel -
Run
shards install
Usage
require "crababel"
Translations are generated from config/locales/**/*.yml at compile time and are exposed as methods on the locale module. A single file such as config/locales/en.yml still works, and larger projects can split translations by domain:
# config/locales/en.yml
en:
greeting: "Hello"
# config/locales/errors.yml
en:
errors:
not_found: "Not found"
Crababel.locales # => ["en", "de"]
Crababel.locale("en").greeting # => "Hello"
Crababel.locale("de").errors.not_found # => "Nicht gefunden"
Locale files are loaded in sorted path order so generated code is deterministic. Files are deep-merged by namespace, but each full translation key may be defined only once. Crababel raises at compile time when two files define the same translation key, or when one file defines a key as a value and another defines the same key as a namespace.
Placeholder interpolation
Crababel generates method arguments for placeholders written as Crystal interpolation expressions. Each unique #{name} placeholder becomes a required String argument, and repeated placeholders reuse the same argument.
For example:
en:
welcome_user: "Hello #{name}"
route: "From #{origin} to #{destination}"
Crababel.locale("en").welcome_user(name: "Alice") # => "Hello Alice"
Crababel.locale("en").route(origin: "Berlin", destination: "Paris") # => "From Berlin to Paris"
Escape interpolation syntax with a backslash when it should remain literal text:
en:
literal: "Hello \\#{name}"
Crababel.locale("en").literal # => "Hello #{name}"
Development
Install dependencies and run the specs:
shards install
crystal spec
Contributing
- Fork it (https://github.com/your-github-user/crababel/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Stefan Bilharz - creator and maintainer
crababel
- 0
- 1
- 0
- 1
- 1
- 6 days ago
- January 2, 2026
MIT License
Tue, 30 Jun 2026 19:59:31 GMT