File: README.md

package info (click to toggle)
ruby-po-to-json 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88 kB
  • sloc: ruby: 234; makefile: 3
file content (112 lines) | stat: -rw-r--r-- 3,309 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# po_to_json

[![Test Status](https://github.com/webhippie/po_to_json/actions/workflows/testing.yml/badge.svg)](https://github.com/webhippie/po_to_json/actions/workflows/testing.yaml) [![Join the Matrix chat at https://matrix.to/#/#webhippie:matrix.org](https://img.shields.io/badge/matrix-%23webhippie%3Amatrix.org-7bc9a4.svg)](https://matrix.to/#/#webhippie:matrix.org) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/6e015952f83d42d4bfc7e335d856554a)](https://app.codacy.com/gh/webhippie/po_to_json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Gem Version](https://badge.fury.io/rb/po_to_json.svg)](https://badge.fury.io/rb/po_to_json)

Convert gettext PO files to JSON to use in your javascript app, based on
po2json.pl by [DuckDuckGo, Inc.](http://duckduckgo.com/). 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](http://slexaxton.github.io/Jed/)


## Versions

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

## Installation

```ruby
gem 'po_to_json', '~> 3.0.1'
```

## Versioning

This library aims to adhere to [Semantic Versioning 2.0.0][semver]. 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][pvc] with two digits of precision.

For example:

```ruby
spec.add_dependency 'po_to_json', '~> 3.0.1'
```

## Usage

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

```ruby
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:

```ruby
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:

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

## Contributing

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

## Authors

*   [Thomas Boerger](https://github.com/tboerger)
*   [Nubis](https://github.com/nubis)
*   [Other contributors](https://github.com/webhippie/po_to_json/graphs/contributors)

## License

MIT

## Copyright

```
Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
```

[workflow]: https://github.com/webhippie/po_to_json/blob/master/.github/workflows/testing.yml
[semver]: http://semver.org
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint