rex
Version, currently 0.1.06 versions
github.com/GrottoPress/rex
A simple i18n adapter interface for Crystal
Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
rex:
github: GrottoPress/rex
version: ~> 0.1.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
Rex
Rex is a simple i18n adapter interface for Crystal. It allows a shard to define translatable text, enabling apps that require the shard to use any i18n shard of choice as backend.
Installation
-
Add the dependency to your
shard.yml:dependencies: rex: github: GrottoPress/rex -
Run
shards update -
Require Rex:
# ... require "rex" # ...
Usage
-
Call the i18n helpers in your shard as required:
# Translation Rex.t(:some_key, name: "Ama") Rex.t("some_key", {name: "John"}) Rex.t("some.key", 45, "Judith") Rex.t(:another_key) # Localization Rex.l(Time.utc) Rex.l(123_456, :arg) -
The consumer application defines their adapter:
# ->>> src/config/i18n.cr require "some_i18n_shard" struct SomeAppI18nAdapter include Rex::Adapter def translate(key : String | Symbol, *args) : String # You may use any i18n shard as backend Somei18nShard.translate(key, *args) end def localize(value, *args) : String # You may use any i18n shard as backend Somei18nShard.localize(value, *args) end # You may add more `#translate` and `#localize` overloads # as needed end -
The consumer application configures Rex to use this adapter:
# ->>> src/config/i18n.cr Rex.configure do |settings| settings.adapter = SomeAppI18nAdapter.new endIf the i18n backend evaluates translations at compile time (eg: Rosetta), the application should define a
Rex.tmacro instead:# ->>> src/config/i18n.cr module Rex macro t(text, **named_args) Rosetta.find({{ text.id.stringify }}) .t({{ named_args unless named_args.empty? }}) end end -
The consumer application sets up translations according to whatever backend they are using.
Testing
Rex comes with Rex::DevAdapter which may be used for tests:
# ->>> spec/my_app/spec_helper.cr
Rex.configure do |settings|
settings.adapter = Rex::DevAdapter.new
end
# ->>> spec/my_app/some_spec.cr
# `Rex::DevAdapter` returns the key passed to `Rex.t` unchanged
Rex.t(:some_key, {name: "Kwame"}).should(eq "some_key")
Development
Run tests with crystal spec.
Contributing
- Fork it
- Switch to the
masterbranch:git checkout master - Create your feature branch:
git checkout -b my-new-feature - Make your changes, updating changelog and documentation as appropriate.
- Commit your changes:
git commit - Push to the branch:
git push origin my-new-feature - Submit a new Pull Request against the
GrottoPress:masterbranch.
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Aug 10, 2026
- Commit
5aba2a9aa33f- Indexed
- not yet
Dependents
Repository
github.com/GrottoPress/rex
Metadata
- Created
- Aug 12, 2026
- Updated
- Sep 26, 2026
- Synced
- Sep 26, 2026
- Versions
- 6