gettext_i18n_rails_js 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +23 -17
- data/README.md +34 -32
- data/lib/gettext_i18n_rails_js/config.rb +6 -5
- data/lib/gettext_i18n_rails_js/engine.rb +2 -1
- data/lib/gettext_i18n_rails_js/parser/base.rb +9 -2
- data/lib/gettext_i18n_rails_js/parser/handlebars.rb +3 -2
- data/lib/gettext_i18n_rails_js/parser/javascript.rb +40 -6
- data/lib/gettext_i18n_rails_js/parser.rb +2 -1
- data/lib/gettext_i18n_rails_js/task.rb +2 -1
- data/lib/gettext_i18n_rails_js/version.rb +3 -2
- data/lib/gettext_i18n_rails_js.rb +2 -1
- data/lib/tasks/gettext_i18n_rails_js_tasks.rake +3 -1
- data/spec/fixtures/example.vue +21 -0
- data/spec/gettext_i18n_rails_js/parser/handlebars_spec.rb +24 -9
- data/spec/gettext_i18n_rails_js/parser/javascript_spec.rb +82 -7
- data/spec/gettext_i18n_rails_js_spec.rb +2 -1
- data/spec/spec_helper.rb +10 -7
- data/spec/support/with_file.rb +2 -1
- metadata +24 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3a64135b2b1246753cdc84b6ae55c6fd3300241f670fe5165ddb285c8fc6cdff
|
4
|
+
data.tar.gz: dd9907de4a4e8f45e25a2f92d4f5716843f9971fa08d26b005fc7ef6f8bceb02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69484dec873a3c1e521bb32045e37ef8403a179a3464f63b5554663ff4a95bf832fbb3b40cb4bf1379102182f56646ea65dc61af1f5c265871988398220c53e1
|
7
|
+
data.tar.gz: a3b9f155f735ddc98e84e83b0739dab5c20342e5a42895bd9d6c62208705a462809c6f3e3ee71efa0067f12672295eb81b59bb4e0810329c660ac25ddd830438
|
data/CHANGELOG.md
CHANGED
@@ -1,42 +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
|
+
|
3
9
|
## [1.3.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.3.0) - 2017-03-16
|
4
10
|
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
11
|
+
* Fixed Handlebars translations with options (@mikezaby)
|
12
|
+
* Fixed latest Rubocop offenses (@mikezaby)
|
13
|
+
* Dropped failing coveralls, fixed codeclimate (@tboerger)
|
8
14
|
|
9
15
|
## [1.2.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.2.0) - 2016-06-02
|
10
16
|
|
11
|
-
*
|
12
|
-
*
|
17
|
+
* Support for JSX files (@artemv)
|
18
|
+
* Fixed test suite, reduced test matrix (@tboerger)
|
13
19
|
|
14
20
|
## [1.1.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.1.0) - 2016-06-02
|
15
21
|
|
16
|
-
*
|
22
|
+
* Replace hyphens with underscores in locale var from DOM (@filib)
|
17
23
|
|
18
24
|
## [1.0.4](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.4) - 2016-05-31
|
19
25
|
|
20
|
-
*
|
26
|
+
* Support ES2015 template strings (@bradbarrow)
|
21
27
|
|
22
28
|
## [1.0.3](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.3) - 2015-11-03
|
23
29
|
|
24
|
-
*
|
30
|
+
* Stop using bundler within the core lib (@domcleal)
|
25
31
|
|
26
32
|
## [1.0.2](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.2) - 2015-03-30
|
27
33
|
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
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)
|
31
37
|
|
32
38
|
## [1.0.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.1) - 2015-02-24
|
33
39
|
|
34
|
-
*
|
40
|
+
* Added missing javascripts to the gemspec (@tboerger)
|
35
41
|
|
36
42
|
## [1.0.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.0) - 2015-02-24
|
37
43
|
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
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
|
-
#
|
1
|
+
# gettext_i18n_rails_js
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
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,33 +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
|
-
|
20
|
-
|
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
|
-
|
17
|
+
For a list of the tested and supported Ruby and Rails versions please take a
|
18
|
+
look at the [wokflow][workflow].
|
32
19
|
|
33
20
|
## Installation
|
34
21
|
|
35
22
|
```ruby
|
36
|
-
gem "gettext_i18n_rails_js", "~> 1.2
|
23
|
+
gem "gettext_i18n_rails_js", "~> 1.2"
|
37
24
|
```
|
38
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
|
+
```
|
39
42
|
|
40
43
|
## Usage
|
41
44
|
|
42
|
-
|
45
|
+
Set up you rails application with gettext support as usual, afterwards just
|
43
46
|
execute the following rake task to export your translations to JSON:
|
44
47
|
|
45
48
|
```bash
|
@@ -99,33 +102,32 @@ GettextI18nRailsJs.config do |config|
|
|
99
102
|
end
|
100
103
|
```
|
101
104
|
|
102
|
-
|
103
105
|
## Todo
|
104
106
|
|
105
|
-
*
|
106
|
-
*
|
107
|
-
|
107
|
+
* More deep testing against multiple Rails versions
|
108
|
+
* Extend the current test suite, especially handlebars
|
108
109
|
|
109
110
|
## Contributing
|
110
111
|
|
111
112
|
Fork -> Patch -> Spec -> Push -> Pull Request
|
112
113
|
|
113
|
-
|
114
114
|
## Authors
|
115
115
|
|
116
|
-
*
|
117
|
-
*
|
118
|
-
*
|
119
|
-
|
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)
|
120
119
|
|
121
120
|
## License
|
122
121
|
|
123
122
|
MIT
|
124
123
|
|
125
|
-
|
126
124
|
## Copyright
|
127
125
|
|
128
126
|
```
|
129
127
|
Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
|
130
128
|
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
|
131
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
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
|
30
|
-
|
31
|
-
|
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
|
-
#
|
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
|
-
|
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
|
-
#
|
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
|
-
/
|
77
|
+
/xm
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
|
50
|
-
|
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
|
-
/
|
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
|
-
/
|
128
|
+
/xm
|
95
129
|
end
|
96
130
|
end
|
97
131
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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>
|
@@ -27,7 +28,7 @@ module GettextI18nRailsJs
|
|
27
28
|
class Version
|
28
29
|
MAJOR = 1
|
29
30
|
MINOR = 3
|
30
|
-
PATCH =
|
31
|
+
PATCH = 1
|
31
32
|
|
32
33
|
PRE = nil
|
33
34
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
#
|
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
|
-
#
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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(
|
@@ -250,6 +263,7 @@ describe GettextI18nRailsJs::Parser::Handlebars do
|
|
250
263
|
end
|
251
264
|
end
|
252
265
|
|
266
|
+
# rubocop:disable Style/FormatStringToken
|
253
267
|
it "does not parse options" do
|
254
268
|
content = <<-EOF
|
255
269
|
<div>
|
@@ -267,6 +281,7 @@ describe GettextI18nRailsJs::Parser::Handlebars do
|
|
267
281
|
)
|
268
282
|
end
|
269
283
|
end
|
284
|
+
# rubocop:enable Style/FormatStringToken
|
270
285
|
|
271
286
|
# it "does not parse internal functions" do
|
272
287
|
# content = <<-EOF
|
@@ -285,8 +300,8 @@ describe GettextI18nRailsJs::Parser::Handlebars do
|
|
285
300
|
describe "parses handlebars files" do
|
286
301
|
let(:example) do
|
287
302
|
File.expand_path(
|
288
|
-
"
|
289
|
-
|
303
|
+
"../../fixtures/example.handlebars",
|
304
|
+
__dir__
|
290
305
|
)
|
291
306
|
end
|
292
307
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
"
|
271
|
-
|
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
|
-
|
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
|
-
["
|
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
|
-
"
|
319
|
-
|
393
|
+
"../../fixtures/example.coffee",
|
394
|
+
__dir__
|
320
395
|
)
|
321
396
|
end
|
322
397
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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("
|
39
|
+
Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each do |file|
|
37
40
|
require file
|
38
41
|
end
|
39
42
|
|
data/spec/support/with_file.rb
CHANGED
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.
|
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:
|
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:
|
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
|
- - ">="
|
@@ -68,61 +68,61 @@ dependencies:
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
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
|
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
|
83
|
+
version: 3.0.2
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
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:
|
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:
|
97
|
+
version: 0.7.1
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
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.
|
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.
|
111
|
+
version: 1.0.0
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: rails
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
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:
|
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
|
-
|
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/
|
188
|
-
- spec/
|
189
|
-
- spec/fixtures/example.js
|
187
|
+
- spec/support/with_file.rb
|
188
|
+
- spec/gettext_i18n_rails_js_spec.rb
|
190
189
|
- spec/gettext_i18n_rails_js/parser/handlebars_spec.rb
|
191
190
|
- spec/gettext_i18n_rails_js/parser/javascript_spec.rb
|
192
|
-
- spec/gettext_i18n_rails_js_spec.rb
|
193
191
|
- spec/spec_helper.rb
|
194
|
-
- spec/
|
192
|
+
- spec/fixtures/example.js
|
193
|
+
- spec/fixtures/example.coffee
|
194
|
+
- spec/fixtures/example.vue
|
195
|
+
- spec/fixtures/example.handlebars
|