crababel v0.3.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 at compile time from shard defaults in lib/**/config/locales/**/*.yml and project translations in config/locales/**/*.yml, then exposed as methods on the locale module. Project translations override shard defaults. A single project 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 within the shard-default group or project group. Crababel raises at compile time for conflicts within either group while allowing project keys to replace shard defaults.
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
- 2
- 1
- about 5 hours ago
- January 2, 2026
MIT License
Sat, 26 Sep 2026 12:39:13 GMT