This repository has been archived by the owner. It is now read-only.

gettext.cr

Crystal implementation of gettext

gettext.cr

Crystal implementation of gettext. Exposes similar API to Python gettext with additional support for PO files.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      gettext:
        github: omarroth/gettext.cr
    
  2. Run shards install

Usage

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

Contributing

  1. Fork it (https://github.com/omarroth/gettext.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

gettext.cr

Owner
Statistic
  • 5
  • 0
  • 0
  • 0
  • 1
  • almost 5 years ago
  • May 27, 2019
License

GNU General Public License v3.0

Links
Synced at

Mon, 06 May 2024 09:05:49 GMT

Languages