po_to_json 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -0
- data/README.md +44 -27
- data/lib/po_to_json/version.rb +2 -3
- data/lib/po_to_json.rb +16 -20
- metadata +6 -14
- data/spec/fixtures/test.po +0 -69
- data/spec/po_to_json_spec.rb +0 -196
- data/spec/spec_helper.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ab57440da3785238977fb3246d8305688f0a490e151059a19ecc136b9b041f2a
|
4
|
+
data.tar.gz: b6584d675e28cab73dba69d901ba0a43697ca60666860777759d47de15f0a8a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f42bc6cc2b01fda254d2fe09bbbc881955778f06a0b3d3d580dea4ff823dde3e2a2a88275b3acffc18de647dc5429ece8d9cd9efa7499d0875d1d483e871687
|
7
|
+
data.tar.gz: fbacac7f8a161137973a406b20e6df11748542b8017295e7673091ee752c2c41a711e7c76717e859b049ddcfec7d0648f122be924877df1dfaed53ccadf7eff3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [2.0.0](https://github.com/webhippie/po_to_json/releases/tag/v2.0.0) - 2023-07-18
|
4
|
+
|
5
|
+
* Fix escape double quote in msgid (@chaomao)
|
6
|
+
|
7
|
+
## [1.1.0](https://github.com/webhippie/po_to_json/releases/tag/v1.0.1) - 2023-04-28
|
8
|
+
|
9
|
+
* Optionally remove var keyword to use a global (@illiatdesdindes)
|
10
|
+
|
3
11
|
## [1.0.1](https://github.com/webhippie/po_to_json/releases/tag/v1.0.1) - 2015-11-03
|
4
12
|
|
5
13
|
* Stop using bundler within the core lib (@tboerger)
|
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# po_to_json
|
2
2
|
|
3
|
-
[](https://travis-ci.org/webhippie/po_to_json)
|
5
|
-
[](https://codeclimate.com/github/webhippie/po_to_json)
|
6
|
-
[](https://codeclimate.com/github/webhippie/po_to_json)
|
7
|
-
[](https://gemnasium.com/webhippie/po_to_json)
|
3
|
+
[](https://github.com/webhippie/po_to_json/actions/workflows/testing.yaml) [](https://matrix.to/#/#webhippie:matrix.org) [](https://app.codacy.com/gh/webhippie/po_to_json/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [](https://badge.fury.io/rb/po_to_json)
|
8
4
|
|
9
5
|
Convert gettext PO files to JSON to use in your javascript app, based on
|
10
6
|
po2json.pl by [DuckDuckGo, Inc.](http://duckduckgo.com/). Ideally you'll use
|
@@ -14,24 +10,31 @@ later be used from javascript with [Jed](http://slexaxton.github.io/Jed/)
|
|
14
10
|
|
15
11
|
## Versions
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
* Ruby
|
20
|
-
* 1.9.3
|
21
|
-
* 2.0.0
|
22
|
-
* 2.1.0
|
23
|
-
* Json
|
24
|
-
* 1.6.8
|
25
|
-
* 1.7.7
|
26
|
-
* 1.8.2
|
27
|
-
|
13
|
+
For a list of the tested and supported Ruby and JSON versions please take a
|
14
|
+
look at the [wokflow][workflow].
|
28
15
|
|
29
16
|
## Installation
|
30
17
|
|
31
18
|
```ruby
|
32
|
-
gem "po_to_json", "~>
|
19
|
+
gem "po_to_json", "~> 2.0"
|
33
20
|
```
|
34
21
|
|
22
|
+
## Versioning
|
23
|
+
|
24
|
+
This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
|
25
|
+
of this scheme should be reported as bugs. Specifically, if a minor or patch
|
26
|
+
version is released that breaks backward compatibility, a new version should be
|
27
|
+
immediately released that restores compatibility. Breaking changes to the public
|
28
|
+
API will only be introduced with new major versions.
|
29
|
+
|
30
|
+
As a result of this policy, you can (and should) specify a dependency on this
|
31
|
+
gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
32
|
+
|
33
|
+
For example:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
spec.add_dependency "po_to_json", "~> 2.0"
|
37
|
+
```
|
35
38
|
|
36
39
|
## Usage
|
37
40
|
|
@@ -45,7 +48,14 @@ json = PoToJson.new(
|
|
45
48
|
Rails.root.join("locale", "de", "app.po")
|
46
49
|
).generate_for_jed("de")
|
47
50
|
|
48
|
-
Rails.root.join(
|
51
|
+
Rails.root.join(
|
52
|
+
"app",
|
53
|
+
"assets",
|
54
|
+
"javascripts",
|
55
|
+
"locale",
|
56
|
+
"de",
|
57
|
+
"app.js"
|
58
|
+
).write(json)
|
49
59
|
```
|
50
60
|
|
51
61
|
If you need a pretty json, add `pretty: true` to `generate_for_jed`, like the
|
@@ -58,7 +68,14 @@ json = PoToJson.new(
|
|
58
68
|
Rails.root.join("locale", "de", "app.po")
|
59
69
|
).generate_for_jed("de", pretty: true)
|
60
70
|
|
61
|
-
Rails.root.join(
|
71
|
+
Rails.root.join(
|
72
|
+
"app",
|
73
|
+
"assets",
|
74
|
+
"javascripts",
|
75
|
+
"locale",
|
76
|
+
"de",
|
77
|
+
"app.js"
|
78
|
+
).write(json)
|
62
79
|
```
|
63
80
|
|
64
81
|
The javascript file generated has a global "locales" object with an attribute
|
@@ -69,27 +86,27 @@ i18n = new Jed(locales["de"])
|
|
69
86
|
i18n.gettext("Hello World") // Should evaluate to "Hallo Welt"
|
70
87
|
```
|
71
88
|
|
72
|
-
|
73
89
|
## Contributing
|
74
90
|
|
75
91
|
Fork -> Patch -> Spec -> Push -> Pull Request
|
76
92
|
|
77
|
-
|
78
93
|
## Authors
|
79
94
|
|
80
|
-
*
|
81
|
-
*
|
82
|
-
*
|
83
|
-
|
95
|
+
* [Thomas Boerger](https://github.com/tboerger)
|
96
|
+
* [Nubis](https://github.com/nubis)
|
97
|
+
* [Other contributors](https://github.com/webhippie/po_to_json/graphs/contributors)
|
84
98
|
|
85
99
|
## License
|
86
100
|
|
87
101
|
MIT
|
88
102
|
|
89
|
-
|
90
103
|
## Copyright
|
91
104
|
|
92
105
|
```
|
93
106
|
Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
|
94
107
|
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
|
95
108
|
```
|
109
|
+
|
110
|
+
[workflow]: https://github.com/webhippie/po_to_json/blob/master/.github/workflows/testing.yml
|
111
|
+
[semver]: http://semver.org
|
112
|
+
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
data/lib/po_to_json/version.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
2
1
|
#
|
3
2
|
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
|
4
3
|
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
|
@@ -25,9 +24,9 @@
|
|
25
24
|
|
26
25
|
class PoToJson
|
27
26
|
class Version
|
28
|
-
MAJOR =
|
27
|
+
MAJOR = 2
|
29
28
|
MINOR = 0
|
30
|
-
PATCH =
|
29
|
+
PATCH = 0
|
31
30
|
|
32
31
|
PRE = nil
|
33
32
|
|
data/lib/po_to_json.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
2
1
|
#
|
3
2
|
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
|
4
3
|
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
|
@@ -27,16 +26,9 @@ gem "json", version: ">= 1.6.0"
|
|
27
26
|
require "json"
|
28
27
|
|
29
28
|
class PoToJson
|
30
|
-
autoload :Version, File.expand_path("
|
29
|
+
autoload :Version, File.expand_path("po_to_json/version", __dir__)
|
31
30
|
|
32
|
-
attr_accessor :files
|
33
|
-
attr_accessor :glue
|
34
|
-
attr_accessor :options
|
35
|
-
attr_accessor :errors
|
36
|
-
attr_accessor :values
|
37
|
-
attr_accessor :buffer
|
38
|
-
attr_accessor :lastkey
|
39
|
-
attr_accessor :trans
|
31
|
+
attr_accessor :files, :glue, :options
|
40
32
|
|
41
33
|
def initialize(files, glue = "|")
|
42
34
|
@files = files
|
@@ -50,7 +42,8 @@ class PoToJson
|
|
50
42
|
generated = build_json_for(build_jed_for(@parsed))
|
51
43
|
|
52
44
|
[
|
53
|
-
|
45
|
+
@options[:variable_locale_scope] ? "var" : "",
|
46
|
+
"#{@options[:variable]} = #{@options[:variable]} || {};",
|
54
47
|
"#{@options[:variable]}['#{@options[:language]}'] = #{generated};"
|
55
48
|
].join(" ")
|
56
49
|
end
|
@@ -61,7 +54,7 @@ class PoToJson
|
|
61
54
|
|
62
55
|
generated = build_json_for(build_json_for(@parsed))
|
63
56
|
|
64
|
-
|
57
|
+
raise "Not implemented yet, current value is #{generated}!"
|
65
58
|
end
|
66
59
|
|
67
60
|
def parse_document
|
@@ -92,6 +85,7 @@ class PoToJson
|
|
92
85
|
|
93
86
|
values[""][0].split("\\n").each do |line|
|
94
87
|
next if line.empty?
|
88
|
+
|
95
89
|
build_header_for(line)
|
96
90
|
end
|
97
91
|
|
@@ -148,7 +142,7 @@ class PoToJson
|
|
148
142
|
msgctxt = buffer[:msgctxt]
|
149
143
|
msgid = buffer[:msgid]
|
150
144
|
|
151
|
-
if msgctxt && msgctxt.
|
145
|
+
if msgctxt && !msgctxt.empty?
|
152
146
|
[msgctxt, glue, msgid].join("")
|
153
147
|
else
|
154
148
|
msgid
|
@@ -157,24 +151,24 @@ class PoToJson
|
|
157
151
|
|
158
152
|
def detect_plural
|
159
153
|
plural = buffer[:msgid_plural]
|
160
|
-
plural if plural && plural.
|
154
|
+
plural if plural && !plural.empty?
|
161
155
|
end
|
162
156
|
|
163
157
|
def build_trans
|
164
158
|
buffer.each do |key, string|
|
165
|
-
trans[$1.to_i] = string if key.to_s
|
159
|
+
trans[$1.to_i] = string if key.to_s =~ /^msgstr_(\d+)/
|
166
160
|
end
|
167
161
|
|
168
162
|
# trans.unshift(detect_plural) if detect_plural
|
169
163
|
end
|
170
164
|
|
171
165
|
def assign_trans
|
172
|
-
values[detect_ctxt] = trans
|
166
|
+
values[detect_ctxt] = trans unless trans.empty?
|
173
167
|
end
|
174
168
|
|
175
169
|
def push_buffer(value, key = nil)
|
176
170
|
value = $1 if value =~ /^"(.*)"/
|
177
|
-
value.gsub(/\\"/, "\"")
|
171
|
+
value.gsub!(/\\"/, "\"")
|
178
172
|
|
179
173
|
if key.nil?
|
180
174
|
buffer[lastkey] = [
|
@@ -191,7 +185,8 @@ class PoToJson
|
|
191
185
|
defaults = {
|
192
186
|
pretty: false,
|
193
187
|
domain: "app",
|
194
|
-
variable: "locales"
|
188
|
+
variable: "locales",
|
189
|
+
variable_locale_scope: true
|
195
190
|
}
|
196
191
|
|
197
192
|
defaults.merge(options)
|
@@ -207,7 +202,8 @@ class PoToJson
|
|
207
202
|
|
208
203
|
def build_header_for(line)
|
209
204
|
if line =~ /(.*?):(.*)/
|
210
|
-
key
|
205
|
+
key = $1
|
206
|
+
value = $2
|
211
207
|
|
212
208
|
if headers.key? key
|
213
209
|
errors.push "Duplicate header: #{line}"
|
@@ -266,7 +262,7 @@ class PoToJson
|
|
266
262
|
end
|
267
263
|
|
268
264
|
def generic_rejects?(line)
|
269
|
-
if line.match(/^$/) || line.match(/^(#[^~]
|
265
|
+
if line.match(/^$/) || line.match(/^(#[^~]|\#$)/)
|
270
266
|
flush_buffer && true
|
271
267
|
else
|
272
268
|
false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: po_to_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Boerger
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: yard
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
@@ -96,9 +96,6 @@ files:
|
|
96
96
|
- README.md
|
97
97
|
- lib/po_to_json.rb
|
98
98
|
- lib/po_to_json/version.rb
|
99
|
-
- spec/fixtures/test.po
|
100
|
-
- spec/po_to_json_spec.rb
|
101
|
-
- spec/spec_helper.rb
|
102
99
|
homepage: https://github.com/webhippie/po_to_json
|
103
100
|
licenses:
|
104
101
|
- MIT
|
@@ -118,13 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
115
|
- !ruby/object:Gem::Version
|
119
116
|
version: '0'
|
120
117
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.4.5.1
|
118
|
+
rubygems_version: 3.1.2
|
123
119
|
signing_key:
|
124
120
|
specification_version: 4
|
125
121
|
summary: Convert gettext PO files to JSON
|
126
|
-
test_files:
|
127
|
-
- spec/fixtures/test.po
|
128
|
-
- spec/po_to_json_spec.rb
|
129
|
-
- spec/spec_helper.rb
|
130
|
-
has_rdoc:
|
122
|
+
test_files: []
|
data/spec/fixtures/test.po
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# SOME DESCRIPTIVE TITLE.
|
2
|
-
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
3
|
-
# This file is distributed under the same license as the PACKAGE package.
|
4
|
-
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
5
|
-
msgid ""
|
6
|
-
msgstr ""
|
7
|
-
"Project-Id-Version: version 0.0.1\n"
|
8
|
-
"POT-Creation-Date: 2009-02-26 19:50+0100\n"
|
9
|
-
"PO-Revision-Date: 2011-12-04 18:54+0900\n"
|
10
|
-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
11
|
-
"Language-Team: LANGUAGE <LL@li.org>\n"
|
12
|
-
"MIME-Version: 1.0\n"
|
13
|
-
"Content-Type: text/plain; charset=UTF-8\n"
|
14
|
-
"Content-Transfer-Encoding: 8bit\n"
|
15
|
-
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
16
|
-
|
17
|
-
#: app/helpers/translation_helper.rb:3
|
18
|
-
msgid "%{relative_time} ago"
|
19
|
-
msgstr "vor %{relative_time}"
|
20
|
-
|
21
|
-
#: app/views/cars/show.html.erb:5
|
22
|
-
msgid "1 Axis"
|
23
|
-
msgid_plural "%{num} Axis"
|
24
|
-
msgstr[0] "1 Achse"
|
25
|
-
msgstr[1] "%{num} Achsen"
|
26
|
-
|
27
|
-
#: app/controllers/cars_controller.rb:47
|
28
|
-
msgid "Car was successfully created."
|
29
|
-
msgstr "Auto wurde erfolgreich gespeichert"
|
30
|
-
|
31
|
-
#: app/controllers/cars_controller.rb:64
|
32
|
-
msgid "Car was successfully updated."
|
33
|
-
msgstr "Auto wurde erfolgreich aktualisiert"
|
34
|
-
|
35
|
-
#: app/views/cars/show.html.erb:1 locale/model_attributes.rb:3
|
36
|
-
msgid "Car|Model"
|
37
|
-
msgstr "Modell"
|
38
|
-
|
39
|
-
msgid "Untranslated"
|
40
|
-
msgstr ""
|
41
|
-
|
42
|
-
#: app/views/cars/show.html.erb:3 locale/model_attributes.rb:4
|
43
|
-
msgid "Car|Wheels count"
|
44
|
-
msgstr "Räderzahl"
|
45
|
-
|
46
|
-
#: app/views/cars/show.html.erb:7
|
47
|
-
msgid "Created"
|
48
|
-
msgstr "Erstellt"
|
49
|
-
|
50
|
-
#: app/views/cars/show.html.erb:9
|
51
|
-
msgid "Month"
|
52
|
-
msgstr "Monat"
|
53
|
-
|
54
|
-
#: locale/model_attributes.rb:2
|
55
|
-
msgid "car"
|
56
|
-
msgstr "Auto"
|
57
|
-
|
58
|
-
#: locale/testlog_phrases.rb:2
|
59
|
-
msgid "this is a dynamic translation which was found!"
|
60
|
-
msgstr ""
|
61
|
-
"Dies ist eine dynamische Übersetzung, die "
|
62
|
-
"gefunden wurde!"
|
63
|
-
|
64
|
-
#: locale/test_escape.rb:2
|
65
|
-
msgid "You should escape '\\' as '\\\\'."
|
66
|
-
msgstr "Du solltest '\\' als '\\\\' escapen."
|
67
|
-
|
68
|
-
msgid "Umläüte"
|
69
|
-
msgstr "Umlaute"
|
data/spec/po_to_json_spec.rb
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
|
4
|
-
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
-
# a copy of this software and associated documentation files (the
|
8
|
-
# "Software"), to deal in the Software without restriction, including
|
9
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
-
# the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be
|
15
|
-
# included in all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
-
#
|
25
|
-
|
26
|
-
require "spec_helper"
|
27
|
-
|
28
|
-
describe PoToJson do
|
29
|
-
let(:po_to_json) do
|
30
|
-
@subject = PoToJson.new(
|
31
|
-
File.expand_path("../fixtures/test.po", __FILE__)
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "parsing" do
|
36
|
-
subject do
|
37
|
-
po_to_json.parse_document
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should find the last author" do
|
41
|
-
expect(subject[""]["Last-Translator"]).to(
|
42
|
-
eq("FULL NAME <EMAIL@ADDRESS>")
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should parse embedded variables" do
|
47
|
-
expect(subject["%{relative_time} ago"]).to(
|
48
|
-
eq(["vor %{relative_time}"])
|
49
|
-
)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should match pluralizations" do
|
53
|
-
expect(subject["1 Axis"]).to(
|
54
|
-
eq(["1 Achse", "%{num} Achsen"])
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should match glued values" do
|
59
|
-
expect(subject["Car|Model"]).to(
|
60
|
-
eq(["Modell"])
|
61
|
-
)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should match embedded glue" do
|
65
|
-
expect(subject["Car|Wheels count"]).to(
|
66
|
-
eq(["Räderzahl"])
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return empty strings as well" do
|
71
|
-
expect(subject["Untranslated"]).to(
|
72
|
-
eq([""])
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should match german umlauts" do
|
77
|
-
expect(subject["Umläüte"]).to(
|
78
|
-
eq(["Umlaute"])
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should match escaped values" do
|
83
|
-
expect(subject["You should escape '\\\\' as '\\\\\\\\'."]).to(
|
84
|
-
eq(["Du solltest '\\\\' als '\\\\\\\\' escapen."])
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should match multiline translations" do
|
89
|
-
expect(subject["this is a dynamic translation which was found!"]).to(
|
90
|
-
eq(["Dies ist eine dynamische Übersetzung, die gefunden wurde!"])
|
91
|
-
)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should match simple strings" do
|
95
|
-
expect(subject["Car was successfully created."]).to(
|
96
|
-
eq(["Auto wurde erfolgreich gespeichert"])
|
97
|
-
)
|
98
|
-
|
99
|
-
expect(subject["Car was successfully updated."]).to(
|
100
|
-
eq(["Auto wurde erfolgreich aktualisiert"])
|
101
|
-
)
|
102
|
-
|
103
|
-
expect(subject["Created"]).to(
|
104
|
-
eq(["Erstellt"])
|
105
|
-
)
|
106
|
-
|
107
|
-
expect(subject["Month"]).to(
|
108
|
-
eq(["Monat"])
|
109
|
-
)
|
110
|
-
|
111
|
-
expect(subject["car"]).to(
|
112
|
-
eq(["Auto"])
|
113
|
-
)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "generate jed compatible" do
|
118
|
-
describe "with minified output" do
|
119
|
-
subject do
|
120
|
-
po_to_json.generate_for_jed("de")
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should output the var definition" do
|
124
|
-
expect(
|
125
|
-
subject.include?("var locales = locales || {}; locales['de'] = ")
|
126
|
-
).to be_truthy
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should include domain string" do
|
130
|
-
expect(
|
131
|
-
subject.include?('"domain":"app"')
|
132
|
-
).to be_truthy
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should include lang string" do
|
136
|
-
expect(
|
137
|
-
subject.include?('"lang":"de"')
|
138
|
-
).to be_truthy
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should include pluralization" do
|
142
|
-
val = '"plural_forms":"nplurals=2; plural=(n != 1);"'
|
143
|
-
expect(
|
144
|
-
subject.include? val
|
145
|
-
).to be_truthy
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should include a single line break" do
|
149
|
-
expect(
|
150
|
-
subject.count("\n")
|
151
|
-
).to be < 1
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "with pretty output" do
|
156
|
-
subject do
|
157
|
-
po_to_json.generate_for_jed("de", pretty: true)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should output the var definition" do
|
161
|
-
expect(
|
162
|
-
subject.include?("var locales = locales || {}; locales['de'] = ")
|
163
|
-
).to be_truthy
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should include domain string" do
|
167
|
-
expect(
|
168
|
-
subject.include?('"domain": "app"')
|
169
|
-
).to be_truthy
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should include lang string" do
|
173
|
-
expect(
|
174
|
-
subject.include?('"lang": "de"')
|
175
|
-
).to be_truthy
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should include pluralization" do
|
179
|
-
val = '"plural_forms": "nplurals=2; plural=(n != 1);"'
|
180
|
-
expect(
|
181
|
-
subject.include? val
|
182
|
-
).to be_truthy
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should include multiple line breaks" do
|
186
|
-
expect(
|
187
|
-
subject.count("\n")
|
188
|
-
).to be > 0
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
# describe "generate simple hashes" do
|
194
|
-
# pending "have to be implemented"
|
195
|
-
# end
|
196
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
|
4
|
-
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
-
# a copy of this software and associated documentation files (the
|
8
|
-
# "Software"), to deal in the Software without restriction, including
|
9
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
-
# the following conditions:
|
13
|
-
#
|
14
|
-
# The above copyright notice and this permission notice shall be
|
15
|
-
# included in all copies or substantial portions of the Software.
|
16
|
-
#
|
17
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
-
#
|
25
|
-
|
26
|
-
require "simplecov"
|
27
|
-
|
28
|
-
if ENV["CODECLIMATE_REPO_TOKEN"]
|
29
|
-
require "coveralls"
|
30
|
-
require "codeclimate-test-reporter"
|
31
|
-
|
32
|
-
Coveralls.wear!
|
33
|
-
CodeClimate::TestReporter.start
|
34
|
-
|
35
|
-
SimpleCov.start do
|
36
|
-
add_filter "/spec"
|
37
|
-
|
38
|
-
formatter SimpleCov::Formatter::MultiFormatter[
|
39
|
-
SimpleCov::Formatter::HTMLFormatter,
|
40
|
-
CodeClimate::TestReporter::Formatter
|
41
|
-
]
|
42
|
-
end
|
43
|
-
else
|
44
|
-
SimpleCov.start do
|
45
|
-
add_filter "/spec"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
require "po_to_json"
|
50
|
-
require "rspec"
|
51
|
-
|
52
|
-
RSpec.configure do |config|
|
53
|
-
config.mock_with :rspec
|
54
|
-
end
|