Lens - A multiformat internationalization shard

Hello!

A couple months ago, I started working on a GNU Gettext shard for the Invidious project. Since then, its scope has widened significantly, now aiming to support numerous formats and provide bindings for CLDR stuff as a proper internationalization shard.

It’s still early in it’s development but Gettext translations:

backend = Gettext::MOBackend.new("locales")
catalogue = backend.create["en_US"]

catalogue.gettext("A message")     # => "Translated message"
catalogue.ngettext("I have %d apple", "I have %d apples", 1) # => "Translated I have %d apples"
catalogue.npgettext("CopyPasteMenu", "Export %d file", "Export %d files", 1) # => "Translated message with plural-form 0"

Support for ruby-i18n YAML:

catalogue = RubyI18n::Yaml.new("locales")
catalogue.translate("en", "translation") # => "Translated Message"
catalogue.translate("en", "possessions.fruits.apples", 50) # => "I have 50 apples"
catalogue.localize("en", 10_250_000_000, type: "humanize", format: "decimal") # => "10.2 Billion"

And the beginning of CLDR bindings:

rules, metadata = CLDR::Numbers::PatternParser.new("0.00+;0.00-").parse
formatter = CLDR::Numbers::PatternFormatter(CLDR::Languages::EN).new(rules, metadata)

formatter.format(1000.129) # => "1000.13+"
formatter.format(-1000.129) # => "1000.13-"

Are all currently present as of master!

There are still quite a lot to finish on the roadmap (PRs welcome), but if you’ve been looking for an internationalization shard, try out Lens! I think you’d enjoy it.

7 Likes