gettext_i18n_rails_js 1.3.1 → 1.4.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: daae36f91fe3d18ef004de9c310dfecd375cfcdc374324fd94955b0284b88d0c
4
+ data.tar.gz: 53fcf1bf4c8aeb76f669b71b71f61b816da23d011b62fb17bcf2e0b3cc73fa92
5
5
  SHA512:
6
- metadata.gz: 69484dec873a3c1e521bb32045e37ef8403a179a3464f63b5554663ff4a95bf832fbb3b40cb4bf1379102182f56646ea65dc61af1f5c265871988398220c53e1
7
- data.tar.gz: a3b9f155f735ddc98e84e83b0739dab5c20342e5a42895bd9d6c62208705a462809c6f3e3ee71efa0067f12672295eb81b59bb4e0810329c660ac25ddd830438
6
+ metadata.gz: d8c598c772c463cb2330b8932ff9630165a8ce8913b7cfc2c64bae8b78403987cc5c1d0052d7f1beaaae05866db2a7d49bb1ec3b8d4c9f63fdbff4401e46b25b
7
+ data.tar.gz: 44a48ac7b393f1320c092c273d9f17dca2e1d7b9bfa8b0a38073150a1a7af64299e09dab295f5615a388c7110e849273f0392497706cf080c149bf360d446481
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
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
+ ## [1.4.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.4.0) - 2024-05-01
4
+
5
+ * Added support for doing conversion for different domains and rails engines (@adamruzicka)
6
+
7
+ ## [1.3.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.3.1) - 2021-12-08
4
8
 
5
9
  * Fixed multiline translation strings (@delxen)
6
10
  * 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
@@ -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."
@@ -27,8 +27,8 @@
27
27
  module GettextI18nRailsJs
28
28
  class Version
29
29
  MAJOR = 1
30
- MINOR = 3
31
- PATCH = 1
30
+ MINOR = 4
31
+ PATCH = 0
32
32
 
33
33
  PRE = nil
34
34
 
@@ -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: 1.4.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-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -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
189
+ - spec/support/with_file.rb
191
190
  - spec/spec_helper.rb
191
+ - spec/gettext_i18n_rails_js_spec.rb
192
192
  - spec/fixtures/example.js
193
- - spec/fixtures/example.coffee
194
193
  - spec/fixtures/example.vue
195
194
  - spec/fixtures/example.handlebars
195
+ - spec/fixtures/example.coffee