Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

omarroth/gettext.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Crystal implementation of gettext

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published