gettext_i18n_rails_js 1.3.0 → 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
- SHA1:
3
- metadata.gz: b6c9be7f40d1ccdd5cde0c1bb93d85d4174957d1
4
- data.tar.gz: 6ed13ca56f91509c75416cea2c42942305ad0c0a
2
+ SHA256:
3
+ metadata.gz: daae36f91fe3d18ef004de9c310dfecd375cfcdc374324fd94955b0284b88d0c
4
+ data.tar.gz: 53fcf1bf4c8aeb76f669b71b71f61b816da23d011b62fb17bcf2e0b3cc73fa92
5
5
  SHA512:
6
- metadata.gz: da0f449e49c3cde558b8b0e8dc7214e715befb293573a4d8efb6045753839ff2a78b73972e790cc5f8423508f0cf14a7e2dd9126263942bc2292f12036a83953
7
- data.tar.gz: fc95857165d43b45bb9c4417bdce81531acc150c5a3bc10dd1b967dc5a271984821e041df1230ccd5db3b91bcd756c7f8c36ce5fa7f5bee2ffd5d4a1ec0e3ae1
6
+ metadata.gz: d8c598c772c463cb2330b8932ff9630165a8ce8913b7cfc2c64bae8b78403987cc5c1d0052d7f1beaaae05866db2a7d49bb1ec3b8d4c9f63fdbff4401e46b25b
7
+ data.tar.gz: 44a48ac7b393f1320c092c273d9f17dca2e1d7b9bfa8b0a38073150a1a7af64299e09dab295f5615a388c7110e849273f0392497706cf080c149bf360d446481
data/CHANGELOG.md CHANGED
@@ -1,42 +1,52 @@
1
1
  # Changelog
2
2
 
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
8
+
9
+ * Fixed multiline translation strings (@delxen)
10
+ * Switched to Codacy for coverage reports (@tboerger)
11
+ * Switched to GitHub actions for CI (@ezr-ondrej)
12
+
3
13
  ## [1.3.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.3.0) - 2017-03-16
4
14
 
5
- * Fixed Handlebars translations with options (@mikezaby)
6
- * Fixed latest Rubocop offenses (@mikezaby)
7
- * Dropped failing coveralls, fixed codeclimate (@tboerger)
15
+ * Fixed Handlebars translations with options (@mikezaby)
16
+ * Fixed latest Rubocop offenses (@mikezaby)
17
+ * Dropped failing coveralls, fixed codeclimate (@tboerger)
8
18
 
9
19
  ## [1.2.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.2.0) - 2016-06-02
10
20
 
11
- * Support for JSX files (@artemv)
12
- * Fixed test suite, reduced test matrix (@tboerger)
21
+ * Support for JSX files (@artemv)
22
+ * Fixed test suite, reduced test matrix (@tboerger)
13
23
 
14
24
  ## [1.1.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.1.0) - 2016-06-02
15
25
 
16
- * Replace hyphens with underscores in locale var from DOM (@filib)
26
+ * Replace hyphens with underscores in locale var from DOM (@filib)
17
27
 
18
28
  ## [1.0.4](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.4) - 2016-05-31
19
29
 
20
- * Support ES2015 template strings (@bradbarrow)
30
+ * Support ES2015 template strings (@bradbarrow)
21
31
 
22
32
  ## [1.0.3](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.3) - 2015-11-03
23
33
 
24
- * Stop using bundler within the core lib (@domcleal)
34
+ * Stop using bundler within the core lib (@domcleal)
25
35
 
26
36
  ## [1.0.2](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.2) - 2015-03-30
27
37
 
28
- * Fixes exception when parsing empty js/coffee files (@tboerger)
29
- * Avoid methods defined in rake task exposing globally (@tboerger)
30
- * Added better configuration options (@tboerger)
38
+ * Fixes exception when parsing empty js/coffee files (@tboerger)
39
+ * Avoid methods defined in rake task exposing globally (@tboerger)
40
+ * Added better configuration options (@tboerger)
31
41
 
32
42
  ## [1.0.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.1) - 2015-02-24
33
43
 
34
- * Added missing javascripts to the gemspec (@tboerger)
44
+ * Added missing javascripts to the gemspec (@tboerger)
35
45
 
36
46
  ## [1.0.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.0) - 2015-02-24
37
47
 
38
- * Transfer from github.com/nubis/gettext_i18n_rails_js (@tboerger)
39
- * Added TravisCI, Rubocop and Coveralls (@tboerger)
40
- * Updated structure to my opinionated gem style (@tboerger)
41
- * Changed default handlebars function to ```__``` (@tboerger)
42
- * Added extended ```gettext_i18n_rails_js.yml``` (@tboerger)
48
+ * Transfer from github.com/nubis/gettext_i18n_rails_js (@tboerger)
49
+ * Added TravisCI, Rubocop and Coveralls (@tboerger)
50
+ * Updated structure to my opinionated gem style (@tboerger)
51
+ * Changed default handlebars function to ```__``` (@tboerger)
52
+ * Added extended ```gettext_i18n_rails_js.yml``` (@tboerger)
data/README.md CHANGED
@@ -1,10 +1,6 @@
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) [![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)
8
4
 
9
5
  Extends [gettext_i18n_rails](https://github.com/grosser/gettext_i18n_rails),
10
6
  making your .PO files available to client side javascript as JSON. It will find
@@ -13,33 +9,37 @@ will create JSON versions of your .PO files so you can serve them with the rest
13
9
  of your assets, thus letting you access all your translations offline from
14
10
  client side javascript.
15
11
 
16
-
17
12
  ## Versions
18
13
 
19
- This gem is tested on the following versions, it's also possible that it works
20
- with older versions, but because of version bumps at `gettext_i18n_rails` and
21
- `fast_gettext` we have dropped the older versions from the testing matrix:
22
-
23
- * Ruby
24
- * 2.1.0
25
- * 2.2.0
26
- * Rails
27
- * 3.2.21
28
- * 4.0.13
29
- * 4.1.16
30
- * 4.2.7
31
-
14
+ For a list of the tested and supported Ruby and Rails versions please take a
15
+ look at the [wokflow][workflow].
32
16
 
33
17
  ## Installation
34
18
 
35
19
  ```ruby
36
- gem "gettext_i18n_rails_js", "~> 1.2.0"
20
+ gem "gettext_i18n_rails_js", "~> 1.2"
37
21
  ```
38
22
 
23
+ ## Versioning
24
+
25
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
26
+ of this scheme should be reported as bugs. Specifically, if a minor or patch
27
+ version is released that breaks backward compatibility, a new version should be
28
+ immediately released that restores compatibility. Breaking changes to the public
29
+ API will only be introduced with new major versions.
30
+
31
+ As a result of this policy, you can (and should) specify a dependency on this
32
+ gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
33
+
34
+ For example:
35
+
36
+ ```ruby
37
+ spec.add_dependency "gettext_i18n_rails_js", "~> 1.2"
38
+ ```
39
39
 
40
40
  ## Usage
41
41
 
42
- set up you rails application with gettext support as usual, afterwards just
42
+ Set up you rails application with gettext support as usual, afterwards just
43
43
  execute the following rake task to export your translations to JSON:
44
44
 
45
45
  ```bash
@@ -99,33 +99,27 @@ GettextI18nRailsJs.config do |config|
99
99
  end
100
100
  ```
101
101
 
102
-
103
- ## Todo
104
-
105
- * More deep testing against multiple Rails versions
106
- * Extend the current test suite, especially handlebars
107
-
108
-
109
102
  ## Contributing
110
103
 
111
104
  Fork -> Patch -> Spec -> Push -> Pull Request
112
105
 
113
-
114
106
  ## Authors
115
107
 
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
-
108
+ * [Thomas Boerger](https://github.com/tboerger)
109
+ * [Nubis](https://github.com/nubis)
110
+ * [Other contributors](https://github.com/webhippie/gettext_i18n_rails_js/graphs/contributors)
120
111
 
121
112
  ## License
122
113
 
123
114
  MIT
124
115
 
125
-
126
116
  ## Copyright
127
117
 
128
118
  ```
129
119
  Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
130
120
  Copyright (c) 2015 Webhippie <http://www.webhippie.de>
131
121
  ```
122
+
123
+ [workflow]: https://github.com/webhippie/gettext_i18n_rails_js/blob/master/.github/workflows/testing.yml
124
+ [semver]: http://semver.org
125
+ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
@@ -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,16 +26,20 @@
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,
33
+ :rails_engine,
34
+ :domain
32
35
 
33
36
  def initialize(&block)
34
37
  @output_path = defaults[:output_path]
35
38
  @handlebars_function = defaults[:handlebars_function]
36
39
  @javascript_function = defaults[:javascript_function]
37
40
  @jed_options = defaults[:jed_options].symbolize_keys
41
+ @rails_engine = defaults[:rails_engine]
42
+ @domain = defaults[:domain]
38
43
 
39
44
  instance_eval(&block) if block_given?
40
45
  end
@@ -58,7 +63,9 @@ module GettextI18nRailsJs
58
63
  javascript_function: "__",
59
64
  jed_options: {
60
65
  pretty: false
61
- }
66
+ },
67
+ rails_engine: ::Rails,
68
+ domain: "app"
62
69
  }
63
70
 
64
71
  if file.exist?
@@ -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 ||= "__"
@@ -70,21 +71,32 @@ module GettextI18nRailsJs
70
71
  # [0]: __('foo', 'foos', 3)
71
72
  # [1]: __
72
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)
73
78
  def parse(file, _msgids = [])
74
79
  collect_for(file) do |function, arguments, line|
75
80
  key = arguments.scan(
76
81
  /('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`)/
77
82
  ).collect do |match|
78
- match.first[1..-2]
83
+ contents = match.first[1..-2]
84
+ contents.gsub(/\\'/, "'").gsub(/(?<=[^\\])"/, "\\\"")
79
85
  end.join(separator_for(function))
80
86
 
81
87
  next if key == ""
88
+
82
89
  results_for(key, file, line)
83
90
  end
84
91
  end
85
92
 
86
93
  protected
87
94
 
95
+ def cleanup_multiline_line(value)
96
+ result = value.chomp
97
+ result.strip
98
+ end
99
+
88
100
  def cleanup_value(value)
89
101
  value
90
102
  .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>
@@ -73,7 +74,7 @@ module GettextI18nRailsJs
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>
@@ -37,6 +38,7 @@ module GettextI18nRailsJs
37
38
  [
38
39
  ".js",
39
40
  ".jsx",
41
+ ".vue",
40
42
  ".coffee"
41
43
  ].include? ::File.extname(file)
42
44
  end
@@ -45,14 +47,46 @@ module GettextI18nRailsJs
45
47
 
46
48
  def collect_for(value)
47
49
  ::File.open(value) do |f|
50
+ multiline = false
51
+ line_no = 0
52
+ buffer = ""
48
53
  f.each_line.each_with_index.collect do |line, idx|
49
- line.scan(invoke_regex).collect do |function, arguments|
50
- 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
+ []
51
73
  end
52
74
  end.inject([], :+).compact
53
75
  end
54
76
  end
55
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
+
56
90
  def invoke_regex
57
91
  #
58
92
  # * Matches the function call grouping the method used (__, n__, N__)
@@ -70,7 +104,7 @@ module GettextI18nRailsJs
70
104
  #{arg_regex}
71
105
  )?
72
106
  \)
73
- /x
107
+ /xm
74
108
  end
75
109
 
76
110
  def arg_regex
@@ -88,10 +122,10 @@ module GettextI18nRailsJs
88
122
  '(?:[^'\\]|\\.)*?'|
89
123
  "(?:[^"\\]|\\.)*?"|
90
124
  `(?:[^`\\]|\\.)*?`|
91
- [a-zA-Z0-9_\.()]*?
125
+ [a-zA-Z0-9_.()]*?
92
126
  )
93
127
  \s*
94
- /x
128
+ /xm
95
129
  end
96
130
  end
97
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>
@@ -44,12 +45,12 @@ module GettextI18nRailsJs
44
45
  path = output_path.join(lang)
45
46
  path.mkpath
46
47
 
47
- path.join("app.js").open("w") do |f|
48
+ path.join("#{domain}.js").open("w") do |f|
48
49
  f.rewind
49
50
  f.write yield
50
51
  end
51
52
 
52
- puts "Created app.js in #{path}"
53
+ puts "Created #{domain}.js in #{path}"
53
54
  end
54
55
 
55
56
  def lang_for(file)
@@ -102,11 +103,19 @@ module GettextI18nRailsJs
102
103
  end
103
104
 
104
105
  def output_path
105
- ::Rails.root.join(
106
+ engine_root.join(
106
107
  GettextI18nRailsJs.config.output_path
107
108
  )
108
109
  end
109
110
 
111
+ def engine_root
112
+ GettextI18nRailsJs.config.rails_engine.root
113
+ end
114
+
115
+ def domain
116
+ GettextI18nRailsJs.config.domain
117
+ end
118
+
110
119
  def print_footer
111
120
  puts
112
121
  puts "All files created, make sure they are being added to your assets."
@@ -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,7 +27,7 @@
26
27
  module GettextI18nRailsJs
27
28
  class Version
28
29
  MAJOR = 1
29
- MINOR = 3
30
+ MINOR = 4
30
31
  PATCH = 0
31
32
 
32
33
  PRE = nil
@@ -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>
@@ -49,6 +50,7 @@ namespace :gettext do
49
50
  "rhtml",
50
51
  "js",
51
52
  "jsx",
53
+ "vue",
52
54
  "coffee",
53
55
  "handlebars",
54
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>
@@ -150,12 +151,24 @@ describe GettextI18nRailsJs::Parser::Handlebars do
150
151
  # end
151
152
  # end
152
153
 
153
- # it "finds interpolated multi-line messages" do
154
- # content = <<-EOF
155
- # """ Parser should grab
156
- # #{ __("This") } __("known bug")
157
- # """
158
- # 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
159
172
 
160
173
  # with_file content do |path|
161
174
  # expect(parser.parse(path, [])).to(
@@ -285,8 +298,8 @@ describe GettextI18nRailsJs::Parser::Handlebars do
285
298
  describe "parses handlebars files" do
286
299
  let(:example) do
287
300
  File.expand_path(
288
- "../../../fixtures/example.handlebars",
289
- __FILE__
301
+ "../../fixtures/example.handlebars",
302
+ __dir__
290
303
  )
291
304
  end
292
305
 
@@ -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
@@ -176,7 +185,8 @@ describe GettextI18nRailsJs::Parser::Javascript do
176
185
 
177
186
  it "finds strings that use escaped strings" do
178
187
  content = <<-'EOF'
179
- __("hello \"dude\"") + __('how is it \'going\' ')
188
+ __("hello \"dude\"") + __('how is it \'going\' ') +
189
+ __('stellar "dude"') + __("it's 'going' good")
180
190
  EOF
181
191
 
182
192
  with_file content do |path|
@@ -184,7 +194,28 @@ describe GettextI18nRailsJs::Parser::Javascript do
184
194
  eq(
185
195
  [
186
196
  ["hello \\\"dude\\\"", "#{path}:1"],
187
- ["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"]
200
+ ]
201
+ )
202
+ )
203
+ end
204
+ end
205
+
206
+ it "finds multi-line translations" do
207
+ content = <<-'EOF'
208
+ """ Parser should grab
209
+ __(`Hello, my name is <span class="name">John Doe</span>
210
+ and this is a very long string`)
211
+ """
212
+ EOF
213
+
214
+ with_file content do |path|
215
+ expect(parser.parse(path, [])).to(
216
+ eq(
217
+ [
218
+ ["Hello, my name is <span class=\\\"name\\\">John Doe</span> and this is a very long string", "#{path}:2"]
188
219
  ]
189
220
  )
190
221
  )
@@ -264,11 +295,56 @@ describe GettextI18nRailsJs::Parser::Javascript do
264
295
  end
265
296
  end
266
297
 
298
+ describe "parses vue files" do
299
+ let(:example) do
300
+ File.expand_path(
301
+ "../../fixtures/example.vue",
302
+ __dir__
303
+ )
304
+ end
305
+
306
+ let(:parsed_example) do
307
+ parser.parse(example, [])
308
+ end
309
+
310
+ it "parses all translations" do
311
+ expect(parsed_example).to(
312
+ eq(
313
+ [
314
+ ["Hello\\nBuddy", "#{example}:7"],
315
+ ["json", "#{example}:18"],
316
+ ["item\u0000items", "#{example}:19"]
317
+ ]
318
+ )
319
+ )
320
+ end
321
+
322
+ it "accepts changing the translate method" do
323
+ parser.gettext_function = "gettext"
324
+
325
+ content = <<-'EOF'
326
+ var string = \"this\" + gettext('json') + 'should be translated';
327
+ EOF
328
+
329
+ with_file content do |path|
330
+ expect(parser.parse(path, [])).to(
331
+ eq(
332
+ [
333
+ ["json", "#{path}:1"]
334
+ ]
335
+ )
336
+ )
337
+ end
338
+
339
+ parser.gettext_function = "__"
340
+ end
341
+ end
342
+
267
343
  describe "parses javascript files" do
268
344
  let(:example) do
269
345
  File.expand_path(
270
- "../../../fixtures/example.js",
271
- __FILE__
346
+ "../../fixtures/example.js",
347
+ __dir__
272
348
  )
273
349
  end
274
350
 
@@ -295,14 +371,16 @@ describe GettextI18nRailsJs::Parser::Javascript do
295
371
  parser.gettext_function = "gettext"
296
372
 
297
373
  content = <<-'EOF'
298
- var string = \"this\" + gettext('json') + 'should be translated';
374
+ <template><div>{{ gettext('name') }}</div></template>
375
+ <script>var string = \"this\" + gettext('json') + 'should be translated';</script>
299
376
  EOF
300
377
 
301
378
  with_file content do |path|
302
379
  expect(parser.parse(path, [])).to(
303
380
  eq(
304
381
  [
305
- ["json", "#{path}:1"]
382
+ ["name", "#{path}:1"],
383
+ ["json", "#{path}:2"]
306
384
  ]
307
385
  )
308
386
  )
@@ -315,8 +393,8 @@ describe GettextI18nRailsJs::Parser::Javascript do
315
393
  describe "parses coffee files" do
316
394
  let(:example) do
317
395
  File.expand_path(
318
- "../../../fixtures/example.coffee",
319
- __FILE__
396
+ "../../fixtures/example.coffee",
397
+ __dir__
320
398
  )
321
399
  end
322
400
 
@@ -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,17 +24,19 @@
23
24
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
  #
25
26
 
26
- require "simplecov"
27
- require "codeclimate-test-reporter" if ENV["CODECLIMATE_REPO_TOKEN"]
28
-
29
- SimpleCov.start do
30
- 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"
33
+ end
31
34
  end
32
35
 
33
36
  require "gettext_i18n_rails_js"
34
37
  require "rspec"
35
38
 
36
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |file|
39
+ Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each do |file|
37
40
  require file
38
41
  end
39
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.3.0
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: 2017-03-16 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
@@ -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,18 +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.5.1
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.coffee
188
- - spec/fixtures/example.handlebars
189
- - spec/fixtures/example.js
190
187
  - spec/gettext_i18n_rails_js/parser/handlebars_spec.rb
191
188
  - spec/gettext_i18n_rails_js/parser/javascript_spec.rb
192
- - spec/gettext_i18n_rails_js_spec.rb
193
- - spec/spec_helper.rb
194
189
  - spec/support/with_file.rb
190
+ - spec/spec_helper.rb
191
+ - spec/gettext_i18n_rails_js_spec.rb
192
+ - spec/fixtures/example.js
193
+ - spec/fixtures/example.vue
194
+ - spec/fixtures/example.handlebars
195
+ - spec/fixtures/example.coffee