gettext_i18n_rails_js 1.0.4 → 1.3.1

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
- SHA1:
3
- metadata.gz: 51e1a1b94026798a925925c54bfb7d293f95565c
4
- data.tar.gz: aaef6c498343a5a99743c094dc0ddc214b587dee
2
+ SHA256:
3
+ metadata.gz: 3a64135b2b1246753cdc84b6ae55c6fd3300241f670fe5165ddb285c8fc6cdff
4
+ data.tar.gz: dd9907de4a4e8f45e25a2f92d4f5716843f9971fa08d26b005fc7ef6f8bceb02
5
5
  SHA512:
6
- metadata.gz: 534dd004d25c63d600c0cd8e2bb84f96ee7fe309a18bf7ac8bcb23389cb3ff7e94fce0c22b83f0bc14665163e56fd35976da58b01a8d81b352f5e0b0435a5e76
7
- data.tar.gz: 408a65e8ea88a8987049c0c409906a825d21d9e2d2ceb6fe79ade5ee5149e00f8da0bd3130e886cb373a4f016665a7919eaafe4e90011a25f5581bc461134c40
6
+ metadata.gz: 69484dec873a3c1e521bb32045e37ef8403a179a3464f63b5554663ff4a95bf832fbb3b40cb4bf1379102182f56646ea65dc61af1f5c265871988398220c53e1
7
+ data.tar.gz: a3b9f155f735ddc98e84e83b0739dab5c20342e5a42895bd9d6c62208705a462809c6f3e3ee71efa0067f12672295eb81b59bb4e0810329c660ac25ddd830438
data/CHANGELOG.md CHANGED
@@ -1,27 +1,48 @@
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
4
+
5
+ * Fixed multiline translation strings (@delxen)
6
+ * Switched to Codacy for coverage reports (@tboerger)
7
+ * Switched to GitHub actions for CI (@ezr-ondrej)
8
+
9
+ ## [1.3.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.3.0) - 2017-03-16
10
+
11
+ * Fixed Handlebars translations with options (@mikezaby)
12
+ * Fixed latest Rubocop offenses (@mikezaby)
13
+ * Dropped failing coveralls, fixed codeclimate (@tboerger)
14
+
15
+ ## [1.2.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.2.0) - 2016-06-02
16
+
17
+ * Support for JSX files (@artemv)
18
+ * Fixed test suite, reduced test matrix (@tboerger)
19
+
20
+ ## [1.1.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.1.0) - 2016-06-02
21
+
22
+ * Replace hyphens with underscores in locale var from DOM (@filib)
23
+
3
24
  ## [1.0.4](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.4) - 2016-05-31
4
25
 
5
- * Support ES2015 template strings (@bradbarrow)
26
+ * Support ES2015 template strings (@bradbarrow)
6
27
 
7
28
  ## [1.0.3](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.3) - 2015-11-03
8
29
 
9
- * Stop using bundler within the core lib (@domcleal)
30
+ * Stop using bundler within the core lib (@domcleal)
10
31
 
11
32
  ## [1.0.2](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.2) - 2015-03-30
12
33
 
13
- * Fixes exception when parsing empty js/coffee files (@tboerger)
14
- * Avoid methods defined in rake task exposing globally (@tboerger)
15
- * Added better configuration options (@tboerger)
34
+ * Fixes exception when parsing empty js/coffee files (@tboerger)
35
+ * Avoid methods defined in rake task exposing globally (@tboerger)
36
+ * Added better configuration options (@tboerger)
16
37
 
17
38
  ## [1.0.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.1) - 2015-02-24
18
39
 
19
- * Added missing javascripts to the gemspec (@tboerger)
40
+ * Added missing javascripts to the gemspec (@tboerger)
20
41
 
21
42
  ## [1.0.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.0) - 2015-02-24
22
43
 
23
- * Transfer from github.com/nubis/gettext_i18n_rails_js (@tboerger)
24
- * Added TravisCI, Rubocop and Coveralls (@tboerger)
25
- * Updated structure to my opinionated gem style (@tboerger)
26
- * Changed default handlebars function to ```__``` (@tboerger)
27
- * Added extended ```gettext_i18n_rails_js.yml``` (@tboerger)
44
+ * Transfer from github.com/nubis/gettext_i18n_rails_js (@tboerger)
45
+ * Added TravisCI, Rubocop and Coveralls (@tboerger)
46
+ * Updated structure to my opinionated gem style (@tboerger)
47
+ * Changed default handlebars function to ```__``` (@tboerger)
48
+ * Added extended ```gettext_i18n_rails_js.yml``` (@tboerger)
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
- # GettextI18nRailsJs
1
+ # gettext_i18n_rails_js
2
2
 
3
- [![Gem Version](http://img.shields.io/gem/v/gettext_i18n_rails_js.svg)](https://rubygems.org/gems/gettext_i18n_rails_js)
4
- [![Build Status](https://secure.travis-ci.org/webhippie/gettext_i18n_rails_js.svg)](https://travis-ci.org/webhippie/gettext_i18n_rails_js)
5
- [![Code Climate](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js.svg)](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js)
6
- [![Test Coverage](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js/badges/coverage.svg)](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js)
7
- [![Dependency Status](https://gemnasium.com/webhippie/gettext_i18n_rails_js.svg)](https://gemnasium.com/webhippie/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)
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)
8
7
 
9
8
  Extends [gettext_i18n_rails](https://github.com/grosser/gettext_i18n_rails),
10
9
  making your .PO files available to client side javascript as JSON. It will find
@@ -13,32 +12,37 @@ will create JSON versions of your .PO files so you can serve them with the rest
13
12
  of your assets, thus letting you access all your translations offline from
14
13
  client side javascript.
15
14
 
16
-
17
15
  ## Versions
18
16
 
19
- This gem is tested on the following versions:
20
-
21
- * Ruby
22
- * 1.9.3
23
- * 2.0.0
24
- * 2.1.0
25
- * Rails
26
- * 3.2.21
27
- * 4.0.13
28
- * 4.1.9
29
- * 4.2.0
30
-
17
+ For a list of the tested and supported Ruby and Rails versions please take a
18
+ look at the [wokflow][workflow].
31
19
 
32
20
  ## Installation
33
21
 
34
22
  ```ruby
35
- gem "gettext_i18n_rails_js", "~> 1.0.0"
23
+ gem "gettext_i18n_rails_js", "~> 1.2"
36
24
  ```
37
25
 
26
+ ## Versioning
27
+
28
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
29
+ of this scheme should be reported as bugs. Specifically, if a minor or patch
30
+ version is released that breaks backward compatibility, a new version should be
31
+ immediately released that restores compatibility. Breaking changes to the public
32
+ API will only be introduced with new major versions.
33
+
34
+ As a result of this policy, you can (and should) specify a dependency on this
35
+ gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
36
+
37
+ For example:
38
+
39
+ ```ruby
40
+ spec.add_dependency "gettext_i18n_rails_js", "~> 1.2"
41
+ ```
38
42
 
39
43
  ## Usage
40
44
 
41
- set up you rails application with gettext support as usual, afterwards just
45
+ Set up you rails application with gettext support as usual, afterwards just
42
46
  execute the following rake task to export your translations to JSON:
43
47
 
44
48
  ```bash
@@ -98,33 +102,32 @@ GettextI18nRailsJs.config do |config|
98
102
  end
99
103
  ```
100
104
 
101
-
102
105
  ## Todo
103
106
 
104
- * More deep testing against multiple Rails versions
105
- * Extend the current test suite, especially handlebars
106
-
107
+ * More deep testing against multiple Rails versions
108
+ * Extend the current test suite, especially handlebars
107
109
 
108
110
  ## Contributing
109
111
 
110
112
  Fork -> Patch -> Spec -> Push -> Pull Request
111
113
 
112
-
113
114
  ## Authors
114
115
 
115
- * [Thomas Boerger](https://github.com/tboerger)
116
- * [Nubis](https://github.com/nubis)
117
- * [Other contributors](https://github.com/webhippie/gettext_i18n_rails_js/graphs/contributors)
118
-
116
+ * [Thomas Boerger](https://github.com/tboerger)
117
+ * [Nubis](https://github.com/nubis)
118
+ * [Other contributors](https://github.com/webhippie/gettext_i18n_rails_js/graphs/contributors)
119
119
 
120
120
  ## License
121
121
 
122
122
  MIT
123
123
 
124
-
125
124
  ## Copyright
126
125
 
127
126
  ```
128
127
  Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
129
128
  Copyright (c) 2015 Webhippie <http://www.webhippie.de>
130
129
  ```
130
+
131
+ [workflow]: https://github.com/webhippie/gettext_i18n_rails_js/blob/master/.github/workflows/testing.yml
132
+ [semver]: http://semver.org
133
+ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
@@ -34,6 +34,8 @@
34
34
  return;
35
35
  }
36
36
 
37
+ locale = locale.replace(/-/g, "_");
38
+
37
39
  var i18n = new Jed(locales[locale] || {});
38
40
 
39
41
  window.__ = function() {
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -25,10 +26,10 @@
25
26
 
26
27
  module GettextI18nRailsJs
27
28
  class Config
28
- attr_accessor :output_path
29
- attr_accessor :handlebars_function
30
- attr_accessor :javascript_function
31
- attr_accessor :jed_options
29
+ attr_accessor :output_path,
30
+ :handlebars_function,
31
+ :javascript_function,
32
+ :jed_options
32
33
 
33
34
  def initialize(&block)
34
35
  @output_path = defaults[:output_path]
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -36,7 +37,7 @@ module GettextI18nRailsJs
36
37
  # conflicts with other javascript libraries. You only need to define
37
38
  # the base function name to replace "_" and all the other variants
38
39
  # (s_, n_, N_) will be deduced automatically.
39
- attr_accessor :gettext_function
40
+ attr_writer :gettext_function
40
41
 
41
42
  def gettext_function
42
43
  @gettext_function ||= "__"
@@ -79,12 +80,18 @@ module GettextI18nRailsJs
79
80
  end.join(separator_for(function))
80
81
 
81
82
  next if key == ""
83
+
82
84
  results_for(key, file, line)
83
85
  end
84
86
  end
85
87
 
86
88
  protected
87
89
 
90
+ def cleanup_multiline_line(value)
91
+ result = value.chomp
92
+ result.strip
93
+ end
94
+
88
95
  def cleanup_value(value)
89
96
  value
90
97
  .tr("\n", "\n")
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -62,18 +63,18 @@ module GettextI18nRailsJs
62
63
  # * Remaining arguments
63
64
  # * Function call closing parenthesis
64
65
  #
65
-
66
66
  /
67
67
  \B[{]{2}(
68
68
  ([snN]?#{gettext_function})
69
69
  \s+
70
70
  (
71
- ".*?"
72
- .*?
71
+ (["'])(?:\\?+.)*?\4
72
+ (?:\s+(["'])(?:\\?+.)*?\5)?
73
73
  )
74
+ .*?
74
75
  )
75
76
  [}]{2}
76
- /x
77
+ /xm
77
78
  end
78
79
  end
79
80
  end
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -36,6 +37,8 @@ module GettextI18nRailsJs
36
37
  def target?(file)
37
38
  [
38
39
  ".js",
40
+ ".jsx",
41
+ ".vue",
39
42
  ".coffee"
40
43
  ].include? ::File.extname(file)
41
44
  end
@@ -44,14 +47,46 @@ module GettextI18nRailsJs
44
47
 
45
48
  def collect_for(value)
46
49
  ::File.open(value) do |f|
50
+ multiline = false
51
+ line_no = 0
52
+ buffer = ""
47
53
  f.each_line.each_with_index.collect do |line, idx|
48
- line.scan(invoke_regex).collect do |function, arguments|
49
- yield(function, arguments, idx + 1)
54
+ if multiline
55
+ buffer << cleanup_multiline_line(line)
56
+ else
57
+ buffer = line
58
+ line_no = idx + 1
59
+ end
60
+
61
+ if invoke_regex =~ buffer
62
+ multiline = false
63
+ buffer.scan(invoke_regex).collect do |function, arguments|
64
+ yield(function, arguments, line_no)
65
+ end
66
+ elsif invoke_open_regex =~ buffer
67
+ buffer << cleanup_multiline_line(buffer) unless multiline
68
+ buffer << " "
69
+ multiline = true
70
+ []
71
+ else
72
+ []
50
73
  end
51
74
  end.inject([], :+).compact
52
75
  end
53
76
  end
54
77
 
78
+ def invoke_open_regex
79
+ #
80
+ # * Matches the function call grouping the method used (__, n__, N__)
81
+ # * A parenthesis to start the arguments to the function.
82
+ # * Used to identify translation start on a single line
83
+ #
84
+
85
+ /
86
+ (\b[snN]?#{gettext_function})\(
87
+ /x
88
+ end
89
+
55
90
  def invoke_regex
56
91
  #
57
92
  # * Matches the function call grouping the method used (__, n__, N__)
@@ -69,7 +104,7 @@ module GettextI18nRailsJs
69
104
  #{arg_regex}
70
105
  )?
71
106
  \)
72
- /x
107
+ /xm
73
108
  end
74
109
 
75
110
  def arg_regex
@@ -87,10 +122,10 @@ module GettextI18nRailsJs
87
122
  '(?:[^'\\]|\\.)*?'|
88
123
  "(?:[^"\\]|\\.)*?"|
89
124
  `(?:[^`\\]|\\.)*?`|
90
- [a-zA-Z0-9_\.()]*?
125
+ [a-zA-Z0-9_.()]*?
91
126
  )
92
127
  \s*
93
- /x
128
+ /xm
94
129
  end
95
130
  end
96
131
  end
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -26,8 +27,8 @@
26
27
  module GettextI18nRailsJs
27
28
  class Version
28
29
  MAJOR = 1
29
- MINOR = 0
30
- PATCH = 4
30
+ MINOR = 3
31
+ PATCH = 1
31
32
 
32
33
  PRE = nil
33
34
 
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -48,6 +49,8 @@ namespace :gettext do
48
49
  "slim",
49
50
  "rhtml",
50
51
  "js",
52
+ "jsx",
53
+ "vue",
51
54
  "coffee",
52
55
  "handlebars",
53
56
  "hbs",
@@ -0,0 +1,21 @@
1
+ <template>
2
+ <base-table-actions v-if="canInteract"
3
+ class="spec-banner-actions">
4
+
5
+ <div v-if="canCopy"
6
+ @click="handleCopy"
7
+ class="dropdown-item">{{ __("Hello\nBuddy") }}</div>
8
+
9
+ <div v-if="canArchive"
10
+ @click="handleArchive"
11
+ class="dropdown-item">{{ archivePlaceholder }}</div>
12
+ </base-table-actions>
13
+ </template>
14
+
15
+
16
+ <script>
17
+ function pepito() {
18
+ var string = "this" + __('json') + 'should be translated';
19
+ alert(n__('item', 'items', 3));
20
+ }
21
+ </script>
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -60,14 +61,14 @@ describe GettextI18nRailsJs::Parser::Handlebars do
60
61
  describe "#parse" do
61
62
  it "finds plural messages" do
62
63
  content = <<-EOF
63
- <div>{{n__ "xxxx" "yyyy\" "zzzz" some_count}}</div>
64
+ <div>{{n__ "xxxx" "yyyy" some_count}}</div>
64
65
  EOF
65
66
 
66
67
  with_file content do |path|
67
68
  expect(parser.parse(path, [])).to(
68
69
  eq(
69
70
  [
70
- ["xxxx\000yyyy\000zzzz", "#{path}:1"]
71
+ ["xxxx\000yyyy", "#{path}:1"]
71
72
  ]
72
73
  )
73
74
  )
@@ -76,7 +77,7 @@ describe GettextI18nRailsJs::Parser::Handlebars do
76
77
 
77
78
  it "finds namespaced messages" do
78
79
  content = <<-EOF
79
- <div>{{__ "xxxx", "yyyy"}}</div>
80
+ <div>{{__ "xxxx" "yyyy"}}</div>
80
81
  EOF
81
82
 
82
83
  with_file content do |path|
@@ -106,6 +107,22 @@ describe GettextI18nRailsJs::Parser::Handlebars do
106
107
  end
107
108
  end
108
109
 
110
+ it "finds single quote messages" do
111
+ content = <<-EOF
112
+ <div>{{__ 'blah'}}</div>
113
+ EOF
114
+
115
+ with_file content do |path|
116
+ expect(parser.parse(path, [])).to(
117
+ eq(
118
+ [
119
+ ["blah", "#{path}:1"]
120
+ ]
121
+ )
122
+ )
123
+ end
124
+ end
125
+
109
126
  # it "finds messages with newlines/tabs" do
110
127
  # content = <<-EOF
111
128
  # bla = __("xxxx\n\tfoo")
@@ -134,12 +151,24 @@ describe GettextI18nRailsJs::Parser::Handlebars do
134
151
  # end
135
152
  # end
136
153
 
137
- # it "finds interpolated multi-line messages" do
138
- # content = <<-EOF
139
- # """ Parser should grab
140
- # #{ __("This") } __("known bug")
141
- # """
142
- # EOF
154
+ # rubocop:disable Style/TrailingCommaInArrayLiteral
155
+ it "finds interpolated multi-line messages" do
156
+ content = <<-EOF
157
+ <div>{{{__ 'Hello, my name is <span class="name">John Doe</span>
158
+ and this is a very long string'}}}</div>
159
+ EOF
160
+ with_file content do |path|
161
+ expect(parser.parse(path, [])).to(
162
+ eq(
163
+ [
164
+ ["Hello, my name is <span class=\"name\">John Doe</span>
165
+ and this is a very long string", "#{path}:1"],
166
+ ]
167
+ )
168
+ )
169
+ end
170
+ end
171
+ # rubocop:enable Style/TrailingCommaInArrayLiteral
143
172
 
144
173
  # with_file content do |path|
145
174
  # expect(parser.parse(path, [])).to(
@@ -234,6 +263,26 @@ describe GettextI18nRailsJs::Parser::Handlebars do
234
263
  end
235
264
  end
236
265
 
266
+ # rubocop:disable Style/FormatStringToken
267
+ it "does not parse options" do
268
+ content = <<-EOF
269
+ <div>
270
+ {{__ "test with %{param}" param="something"}}
271
+ </div>
272
+ EOF
273
+
274
+ with_file content do |path|
275
+ expect(parser.parse(path, [])).to(
276
+ eq(
277
+ [
278
+ ["test with %{param}", "#{path}:1"]
279
+ ]
280
+ )
281
+ )
282
+ end
283
+ end
284
+ # rubocop:enable Style/FormatStringToken
285
+
237
286
  # it "does not parse internal functions" do
238
287
  # content = <<-EOF
239
288
  # bla = n__("items (single)", "i (more)", item.count()) + __('foobar')
@@ -251,8 +300,8 @@ describe GettextI18nRailsJs::Parser::Handlebars do
251
300
  describe "parses handlebars files" do
252
301
  let(:example) do
253
302
  File.expand_path(
254
- "../../../fixtures/example.handlebars",
255
- __FILE__
303
+ "../../fixtures/example.handlebars",
304
+ __dir__
256
305
  )
257
306
  end
258
307
 
@@ -279,7 +328,7 @@ describe GettextI18nRailsJs::Parser::Handlebars do
279
328
  <div>
280
329
  {{gettext \"Hello {yourname}\"}}
281
330
  <span>
282
- {{ngettext \"item\", \"items\", 44}}
331
+ {{ngettext \"item\" \"items\" 44}}
283
332
  </span>
284
333
  </div>
285
334
  EOF
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -37,6 +38,14 @@ describe GettextI18nRailsJs::Parser::Javascript do
37
38
  expect(parser.target?("foo/bar/xxx.coffee")).to be_truthy
38
39
  end
39
40
 
41
+ it "targets .vue" do
42
+ expect(parser.target?("foo/bar/xxx.vue")).to be_truthy
43
+ end
44
+
45
+ it "targets .jsx" do
46
+ expect(parser.target?("foo/bar/xxx.jsx")).to be_truthy
47
+ end
48
+
40
49
  it "does not target cows" do
41
50
  expect(parser.target?("foo/bar/xxx.cows")).to be_falsey
42
51
  end
@@ -191,6 +200,25 @@ describe GettextI18nRailsJs::Parser::Javascript do
191
200
  end
192
201
  end
193
202
 
203
+ it "finds multi-line translations" do
204
+ content = <<-'EOF'
205
+ """ Parser should grab
206
+ __(`Hello, my name is <span class="name">John Doe</span>
207
+ and this is a very long string`)
208
+ """
209
+ EOF
210
+
211
+ with_file content do |path|
212
+ expect(parser.parse(path, [])).to(
213
+ eq(
214
+ [
215
+ ["Hello, my name is <span class=\"name\">John Doe</span> and this is a very long string", "#{path}:2"]
216
+ ]
217
+ )
218
+ )
219
+ end
220
+ end
221
+
194
222
  it "does not capture a false positive" do
195
223
  content = <<-'EOF'
196
224
  bla = should_not_be_registered__("xxxx", "yyyy")
@@ -264,11 +292,56 @@ describe GettextI18nRailsJs::Parser::Javascript do
264
292
  end
265
293
  end
266
294
 
295
+ describe "parses vue files" do
296
+ let(:example) do
297
+ File.expand_path(
298
+ "../../fixtures/example.vue",
299
+ __dir__
300
+ )
301
+ end
302
+
303
+ let(:parsed_example) do
304
+ parser.parse(example, [])
305
+ end
306
+
307
+ it "parses all translations" do
308
+ expect(parsed_example).to(
309
+ eq(
310
+ [
311
+ ["Hello\\nBuddy", "#{example}:7"],
312
+ ["json", "#{example}:18"],
313
+ ["item\u0000items", "#{example}:19"]
314
+ ]
315
+ )
316
+ )
317
+ end
318
+
319
+ it "accepts changing the translate method" do
320
+ parser.gettext_function = "gettext"
321
+
322
+ content = <<-'EOF'
323
+ var string = \"this\" + gettext('json') + 'should be translated';
324
+ EOF
325
+
326
+ with_file content do |path|
327
+ expect(parser.parse(path, [])).to(
328
+ eq(
329
+ [
330
+ ["json", "#{path}:1"]
331
+ ]
332
+ )
333
+ )
334
+ end
335
+
336
+ parser.gettext_function = "__"
337
+ end
338
+ end
339
+
267
340
  describe "parses javascript files" do
268
341
  let(:example) do
269
342
  File.expand_path(
270
- "../../../fixtures/example.js",
271
- __FILE__
343
+ "../../fixtures/example.js",
344
+ __dir__
272
345
  )
273
346
  end
274
347
 
@@ -295,14 +368,16 @@ describe GettextI18nRailsJs::Parser::Javascript do
295
368
  parser.gettext_function = "gettext"
296
369
 
297
370
  content = <<-'EOF'
298
- var string = \"this\" + gettext('json') + 'should be translated';
371
+ <template><div>{{ gettext('name') }}</div></template>
372
+ <script>var string = \"this\" + gettext('json') + 'should be translated';</script>
299
373
  EOF
300
374
 
301
375
  with_file content do |path|
302
376
  expect(parser.parse(path, [])).to(
303
377
  eq(
304
378
  [
305
- ["json", "#{path}:1"]
379
+ ["name", "#{path}:1"],
380
+ ["json", "#{path}:2"]
306
381
  ]
307
382
  )
308
383
  )
@@ -315,8 +390,8 @@ describe GettextI18nRailsJs::Parser::Javascript do
315
390
  describe "parses coffee files" do
316
391
  let(:example) do
317
392
  File.expand_path(
318
- "../../../fixtures/example.coffee",
319
- __FILE__
393
+ "../../fixtures/example.coffee",
394
+ __dir__
320
395
  )
321
396
  end
322
397
 
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
@@ -23,33 +24,19 @@
23
24
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
  #
25
26
 
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"
27
+ if ENV.key? "CODACY_PROJECT_TOKEN"
28
+ begin
29
+ require "codacy-coverage"
30
+ Codacy::Reporter.start
31
+ rescue StandardError
32
+ puts "Failed to load codacy-coverage gem"
46
33
  end
47
34
  end
48
35
 
49
36
  require "gettext_i18n_rails_js"
50
37
  require "rspec"
51
38
 
52
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |file|
39
+ Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each do |file|
53
40
  require file
54
41
  end
55
42
 
@@ -1,4 +1,5 @@
1
- # -*- coding: UTF-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
4
5
  # Copyright (c) 2015 Webhippie <http://www.webhippie.de>
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.0.4
4
+ version: 1.3.1
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: 2016-05-31 00:00:00.000000000 Z
12
+ date: 2021-12-09 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: yard
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: rspec
57
+ name: yard
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -68,61 +68,61 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rails
71
+ name: gettext
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 3.2.0
76
+ version: 3.0.2
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 3.2.0
83
+ version: 3.0.2
84
84
  - !ruby/object:Gem::Dependency
85
- name: gettext
85
+ name: gettext_i18n_rails
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 3.0.2
90
+ version: 0.7.1
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: 3.0.2
97
+ version: 0.7.1
98
98
  - !ruby/object:Gem::Dependency
99
- name: gettext_i18n_rails
99
+ name: po_to_json
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: 0.7.1
104
+ version: 1.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: 0.7.1
111
+ version: 1.0.0
112
112
  - !ruby/object:Gem::Dependency
113
- name: po_to_json
113
+ name: rails
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: 1.0.0
118
+ version: 3.2.0
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
- version: 1.0.0
125
+ version: 3.2.0
126
126
  description: |2
127
127
  It will find translations inside your .js and .coffee files, then it will
128
128
  create JSON versions of your .PO files and will let you serve them with the
@@ -152,6 +152,7 @@ files:
152
152
  - spec/fixtures/example.coffee
153
153
  - spec/fixtures/example.handlebars
154
154
  - spec/fixtures/example.js
155
+ - spec/fixtures/example.vue
155
156
  - spec/gettext_i18n_rails_js/parser/handlebars_spec.rb
156
157
  - spec/gettext_i18n_rails_js/parser/javascript_spec.rb
157
158
  - spec/gettext_i18n_rails_js_spec.rb
@@ -177,19 +178,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.2.5
181
+ rubygems_version: 3.1.2
182
182
  signing_key:
183
183
  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/fixtures/example.js
188
- - spec/fixtures/example.handlebars
189
- - spec/fixtures/example.coffee
190
187
  - spec/support/with_file.rb
191
- - spec/gettext_i18n_rails_js/parser/javascript_spec.rb
192
- - spec/gettext_i18n_rails_js/parser/handlebars_spec.rb
193
188
  - spec/gettext_i18n_rails_js_spec.rb
189
+ - spec/gettext_i18n_rails_js/parser/handlebars_spec.rb
190
+ - spec/gettext_i18n_rails_js/parser/javascript_spec.rb
194
191
  - spec/spec_helper.rb
195
- has_rdoc:
192
+ - spec/fixtures/example.js
193
+ - spec/fixtures/example.coffee
194
+ - spec/fixtures/example.vue
195
+ - spec/fixtures/example.handlebars