Skip to content
Ruby library for converting gettext PO files to JSON
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.rubocop.yml
.travis.yml
CHANGELOG.md
Gemfile
Guardfile
LICENSE
README.md
Rakefile
po_to_json.gemspec

README.md

PoToJson

Gem Version Build Status Code Climate Test Coverage Dependency Status

Convert gettext PO files to JSON to use in your javascript app, based on po2json.pl by DuckDuckGo, Inc.. Ideally you'll use this on a Rake task that creates JSON versions of your PO files, which can later be used from javascript with Jed

Versions

This gem is tested on the following versions automated through TravisCI:

  • Ruby
    • 1.9.3
    • 2.0.0
    • 2.1.0
  • Json
    • 1.6.8
    • 1.7.7
    • 1.8.2

Installation

gem "po_to_json", "~> 0.1.0"

Usage

Most common use would be to generate a Jed ready javascript file. For example, in a Rails project:

require "po_to_json"

json = PoToJson.new(
  Rails.root.join("locale", "de", "app.po")
).generate_for_jed("de")

Rails.root.join("app", "assets", "javascripts", "locale", "de", "app.js").write(json)

If you need a pretty json, add pretty: true to generate_for_jed, like the following example:

require "po_to_json"

json = PoToJson.new(
  Rails.root.join("locale", "de", "app.po")
).generate_for_jed("de", pretty: true)

Rails.root.join("app", "assets", "javascripts", "locale", "de", "app.js").write(json)

The javascript file generated has a global "locales" object with an attribute corresponding to the generated language:

i18n = new Jed(locales["de"])
i18n.gettext("Hello World") // Should evaluate to "Hallo Welt"

Contributing

Fork -> Patch -> Spec -> Push -> Pull Request

Authors

License

MIT

Copyright

Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
You can’t perform that action at this time.