Project

po_to_json

0.46
There's a lot of open issues
No release in over a year
Convert gettext PO files to JSON objects so that you can use it in your application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

>= 1.6.0
 Project Readme

po_to_json

Test Status Join the Matrix chat at https://matrix.to/#/#webhippie:matrix.org Codacy Badge Gem Version

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

For a list of the tested and supported Ruby and JSON versions please take a look at the wokflow.

Installation

gem "po_to_json", "~> 2.0"

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency "po_to_json", "~> 2.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>