gettext_i18n_rails_js 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a64135b2b1246753cdc84b6ae55c6fd3300241f670fe5165ddb285c8fc6cdff
4
- data.tar.gz: dd9907de4a4e8f45e25a2f92d4f5716843f9971fa08d26b005fc7ef6f8bceb02
3
+ metadata.gz: 8ab326162602b66ba040e58caf4f70bb47ab86534a4b6af2c8db0b80ed8476e7
4
+ data.tar.gz: aeedf1ab2bf77d3714997cd245c20678ff2ac704597d9c166e5d92f20c8cdd49
5
5
  SHA512:
6
- metadata.gz: 69484dec873a3c1e521bb32045e37ef8403a179a3464f63b5554663ff4a95bf832fbb3b40cb4bf1379102182f56646ea65dc61af1f5c265871988398220c53e1
7
- data.tar.gz: a3b9f155f735ddc98e84e83b0739dab5c20342e5a42895bd9d6c62208705a462809c6f3e3ee71efa0067f12672295eb81b59bb4e0810329c660ac25ddd830438
6
+ metadata.gz: '0943368677d65bf340f39226d4b63772f7d34034727b47e2c61d185ad0eeb8108da68662029977a5c43bf4732fe277122cab99efc8f898f5fac7e1b9448edb7d'
7
+ data.tar.gz: 648ff70f6cc5366b2093775df8f4fc2dc6a922696f858f590b0abd4cff9e5d7e8ffb8380229aeeb17dfecae48bdc3ec95f709d0ddcdf045624cfd93aaf7744cf
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## [1.3.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.4.0) - 2021-12-08
3
+ ## [2.0.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v2.0.0) - 2023-07-20
4
+
5
+ * Upgrade to latest po_to_json which fixes double quotes within msgid (@tboerger)
6
+
7
+ ## [1.4.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.4.0) - 2023-05-01
8
+
9
+ * Added support for doing conversion for different domains and rails engines (@adamruzicka)
10
+
11
+ ## [1.3.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.3.1) - 2021-12-08
4
12
 
5
13
  * Fixed multiline translation strings (@delxen)
6
14
  * Switched to Codacy for coverage reports (@tboerger)
data/README.md CHANGED
@@ -1,9 +1,6 @@
1
1
  # gettext_i18n_rails_js
2
2
 
3
- [![Test Status](https://github.com/webhippie/gettext_i18n_rails_js/actions/workflows/testing.yml/badge.svg)](https://github.com/webhippie/gettext_i18n_rails_js/actions/workflows/testing.yaml)
4
- [![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)
5
- [![Codacy Badge](https://app.codacy.com/project/badge/Grade/51f241a0f0d7490cae0bdc04387f9d13)](https://www.codacy.com/gh/webhippie/gettext_i18n_rails_js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=webhippie/gettext_i18n_rails_js&utm_campaign=Badge_Grade)
6
- [![Gem Version](https://badge.fury.io/rb/gettext_i18n_rails_js.svg)](https://badge.fury.io/rb/gettext_i18n_rails_js)
3
+ [![Test Status](https://github.com/webhippie/gettext_i18n_rails_js/actions/workflows/testing.yml/badge.svg)](https://github.com/webhippie/gettext_i18n_rails_js/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/51f241a0f0d7490cae0bdc04387f9d13)](https://app.codacy.com/gh/webhippie/gettext_i18n_rails_js/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Gem Version](https://badge.fury.io/rb/gettext_i18n_rails_js.svg)](https://badge.fury.io/rb/gettext_i18n_rails_js)
7
4
 
8
5
  Extends [gettext_i18n_rails](https://github.com/grosser/gettext_i18n_rails),
9
6
  making your .PO files available to client side javascript as JSON. It will find
@@ -20,7 +17,7 @@ look at the [wokflow][workflow].
20
17
  ## Installation
21
18
 
22
19
  ```ruby
23
- gem "gettext_i18n_rails_js", "~> 1.2"
20
+ gem "gettext_i18n_rails_js", "~> 2.0"
24
21
  ```
25
22
 
26
23
  ## Versioning
@@ -37,7 +34,7 @@ gem using the [Pessimistic Version Constraint][pvc] with two digits of precision
37
34
  For example:
38
35
 
39
36
  ```ruby
40
- spec.add_dependency "gettext_i18n_rails_js", "~> 1.2"
37
+ spec.add_dependency "gettext_i18n_rails_js", "~> 2.0"
41
38
  ```
42
39
 
43
40
  ## Usage
@@ -102,11 +99,6 @@ GettextI18nRailsJs.config do |config|
102
99
  end
103
100
  ```
104
101
 
105
- ## Todo
106
-
107
- * More deep testing against multiple Rails versions
108
- * Extend the current test suite, especially handlebars
109
-
110
102
  ## Contributing
111
103
 
112
104
  Fork -> Patch -> Spec -> Push -> Pull Request
@@ -29,13 +29,17 @@ module GettextI18nRailsJs
29
29
  attr_accessor :output_path,
30
30
  :handlebars_function,
31
31
  :javascript_function,
32
- :jed_options
32
+ :jed_options,
33
+ :rails_engine,
34
+ :domain
33
35
 
34
36
  def initialize(&block)
35
37
  @output_path = defaults[:output_path]
36
38
  @handlebars_function = defaults[:handlebars_function]
37
39
  @javascript_function = defaults[:javascript_function]
38
40
  @jed_options = defaults[:jed_options].symbolize_keys
41
+ @rails_engine = defaults[:rails_engine]
42
+ @domain = defaults[:domain]
39
43
 
40
44
  instance_eval(&block) if block_given?
41
45
  end
@@ -59,7 +63,9 @@ module GettextI18nRailsJs
59
63
  javascript_function: "__",
60
64
  jed_options: {
61
65
  pretty: false
62
- }
66
+ },
67
+ rails_engine: ::Rails,
68
+ domain: "app"
63
69
  }
64
70
 
65
71
  if file.exist?
@@ -71,12 +71,17 @@ module GettextI18nRailsJs
71
71
  # [0]: __('foo', 'foos', 3)
72
72
  # [1]: __
73
73
  # [2]: 'foo', 'foos', 3
74
+ #
75
+ # The PO file outputs to a "" string.
76
+ # single quotes are unescped (if they are escaped)
77
+ # double quotes are escaped (if they are not already escaped)
74
78
  def parse(file, _msgids = [])
75
79
  collect_for(file) do |function, arguments, line|
76
80
  key = arguments.scan(
77
81
  /('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`)/
78
82
  ).collect do |match|
79
- match.first[1..-2]
83
+ contents = match.first[1..-2]
84
+ contents.gsub(/\\'/, "'").gsub(/(?<=[^\\])"/, "\\\"")
80
85
  end.join(separator_for(function))
81
86
 
82
87
  next if key == ""
@@ -45,12 +45,12 @@ module GettextI18nRailsJs
45
45
  path = output_path.join(lang)
46
46
  path.mkpath
47
47
 
48
- path.join("app.js").open("w") do |f|
48
+ path.join("#{domain}.js").open("w") do |f|
49
49
  f.rewind
50
50
  f.write yield
51
51
  end
52
52
 
53
- puts "Created app.js in #{path}"
53
+ puts "Created #{domain}.js in #{path}"
54
54
  end
55
55
 
56
56
  def lang_for(file)
@@ -103,11 +103,19 @@ module GettextI18nRailsJs
103
103
  end
104
104
 
105
105
  def output_path
106
- ::Rails.root.join(
106
+ engine_root.join(
107
107
  GettextI18nRailsJs.config.output_path
108
108
  )
109
109
  end
110
110
 
111
+ def engine_root
112
+ GettextI18nRailsJs.config.rails_engine.root
113
+ end
114
+
115
+ def domain
116
+ GettextI18nRailsJs.config.domain
117
+ end
118
+
111
119
  def print_footer
112
120
  puts
113
121
  puts "All files created, make sure they are being added to your assets."
@@ -26,9 +26,9 @@
26
26
 
27
27
  module GettextI18nRailsJs
28
28
  class Version
29
- MAJOR = 1
30
- MINOR = 3
31
- PATCH = 1
29
+ MAJOR = 2
30
+ MINOR = 0
31
+ PATCH = 0
32
32
 
33
33
  PRE = nil
34
34
 
@@ -27,7 +27,7 @@
27
27
  gem "rails", version: ">= 3.2.0"
28
28
  gem "gettext", version: ">= 3.0.2"
29
29
  gem "gettext_i18n_rails", version: ">= 0.7.1"
30
- gem "po_to_json", version: ">= 0.1.0"
30
+ gem "po_to_json", version: ">= 2.0.0"
31
31
 
32
32
  require "rails"
33
33
  require "gettext"
@@ -161,7 +161,7 @@ describe GettextI18nRailsJs::Parser::Handlebars do
161
161
  expect(parser.parse(path, [])).to(
162
162
  eq(
163
163
  [
164
- ["Hello, my name is <span class=\"name\">John Doe</span>
164
+ ["Hello, my name is <span class=\\\"name\\\">John Doe</span>
165
165
  and this is a very long string", "#{path}:1"],
166
166
  ]
167
167
  )
@@ -263,7 +263,6 @@ describe GettextI18nRailsJs::Parser::Handlebars do
263
263
  end
264
264
  end
265
265
 
266
- # rubocop:disable Style/FormatStringToken
267
266
  it "does not parse options" do
268
267
  content = <<-EOF
269
268
  <div>
@@ -281,7 +280,6 @@ describe GettextI18nRailsJs::Parser::Handlebars do
281
280
  )
282
281
  end
283
282
  end
284
- # rubocop:enable Style/FormatStringToken
285
283
 
286
284
  # it "does not parse internal functions" do
287
285
  # content = <<-EOF
@@ -185,7 +185,8 @@ describe GettextI18nRailsJs::Parser::Javascript do
185
185
 
186
186
  it "finds strings that use escaped strings" do
187
187
  content = <<-'EOF'
188
- __("hello \"dude\"") + __('how is it \'going\' ')
188
+ __("hello \"dude\"") + __('how is it \'going\' ') +
189
+ __('stellar "dude"') + __("it's 'going' good")
189
190
  EOF
190
191
 
191
192
  with_file content do |path|
@@ -193,7 +194,9 @@ describe GettextI18nRailsJs::Parser::Javascript do
193
194
  eq(
194
195
  [
195
196
  ["hello \\\"dude\\\"", "#{path}:1"],
196
- ["how is it \\'going\\' ", "#{path}:1"]
197
+ ["how is it 'going' ", "#{path}:1"],
198
+ ["stellar \\\"dude\\\"", "#{path}:2"],
199
+ ["it's 'going' good", "#{path}:2"]
197
200
  ]
198
201
  )
199
202
  )
@@ -212,7 +215,7 @@ describe GettextI18nRailsJs::Parser::Javascript do
212
215
  expect(parser.parse(path, [])).to(
213
216
  eq(
214
217
  [
215
- ["Hello, my name is <span class=\"name\">John Doe</span> and this is a very long string", "#{path}:2"]
218
+ ["Hello, my name is <span class=\\\"name\\\">John Doe</span> and this is a very long string", "#{path}:2"]
216
219
  ]
217
220
  )
218
221
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext_i18n_rails_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
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: 2021-12-09 00:00:00.000000000 Z
12
+ date: 2023-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -101,14 +101,14 @@ dependencies:
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: 1.0.0
104
+ version: 2.0.0
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: 1.0.0
111
+ version: 2.0.0
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: rails
114
114
  requirement: !ruby/object:Gem::Requirement
@@ -184,12 +184,12 @@ specification_version: 4
184
184
  summary: Extends gettext_i18n_rails making your .po files available to client side
185
185
  javascript as JSON
186
186
  test_files:
187
- - spec/support/with_file.rb
188
- - spec/gettext_i18n_rails_js_spec.rb
189
187
  - spec/gettext_i18n_rails_js/parser/handlebars_spec.rb
190
188
  - spec/gettext_i18n_rails_js/parser/javascript_spec.rb
191
- - spec/spec_helper.rb
192
- - spec/fixtures/example.js
189
+ - spec/support/with_file.rb
190
+ - spec/gettext_i18n_rails_js_spec.rb
193
191
  - spec/fixtures/example.coffee
194
192
  - spec/fixtures/example.vue
193
+ - spec/fixtures/example.js
195
194
  - spec/fixtures/example.handlebars
195
+ - spec/spec_helper.rb