Crystal implementation of gettext. Exposes similar API to Python gettext
with additional support for PO
files.
-
Add the dependency to your
shard.yml
:dependencies: gettext: github: omarroth/gettext.cr
-
Run
shards install
require "gettext"
es_mo = Gettext::MoParser.new(File.open("examples/locales/es.mo"))
es_po = Gettext::PoParser.new(File.open("examples/locales/es.po"))
puts es_mo.ngettext("Time: %1 second", "Time: %1 seconds", 10) # => Czas: %1 sekundy
puts es_mo.ngettext("Time: %1 second", 10) # => Time: %1 second
puts es_po.ngettext("Time: %1 second", "Time: %1 seconds", 1) # => Czas: %1 sekunda
puts es_po.ngettext("Time: %1 second", 1) # => Czas: %1 sekunda
translations = Gettext.find("examples/locales", nil)
puts translations.ngettext("es-US", "Time: %1 second", "Time: %1 seconds", 10) # => Czas: %1 sekundy
puts translations.gettext("es", "Logarithmic Scale") # => logaritamska skala
- Fork it (https://github.com/omarroth/gettext.cr/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
- Omar Roth - creator and maintainer