A multi-format internationalization (i18n) shard for Crystal.
Lens is designed to be fast, versatile and simple to use! Supports the likes of Gettext, Ruby YAML and more.
Why use Lens?
Lens was conceived due to various problems within crystal's internationalization ecosystem. As such, Lens aspires to overcome those issues. With lens:
- Support of multiple different formats
- Constant development of new features
- And soon, actual full number and time localization through CLDR
In short, Lens is packed full of features and designed for internationalization.
Note: Documentation below is for Master. For the stable release version, please see v0.1.0.
Lens supports numerous different formats:
|GNU Gettext PO||
|GNU Gettext MO||
To get started, simply initialize a backend:
backend = Gettext::MOBackend.new("locales")
And begin translating!
catalogue = backend.create["en_US"] # Basic catalogue.gettext("A message") # => "Translated message" # Plurals catalogue.ngettext("I have %d apple", "I have %d apples", 1) # => "Translated I have %d apples" # Context catalogue.pgettext("CopyPasteMenu", "copy") # => "Translated copy" # Context w/ Plurals catalogue.npgettext("CopyPasteMenu", "Export %d file", "Export %d files", 1) # => "Translated message with plural-form 0"
Note that each backend has a slightly different API.
- Add the dependency to your
dependencies: lens: github: syeopite/lens version: ~> v0.1.0
- Fork it (https://github.com/syeopite/lens/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
- syeopite - creator and maintainer