i18n-tasks 0.9.15 → 0.9.16
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0cac577152584d62e48767e77416aa559bed589
|
4
|
+
data.tar.gz: 5b981968e66f977fd24c8d2d16fc840614d88146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09b634136cd5a68aa0f37c5b272cf55bda9880181e68c173d1247acb5c629c825317b0aea9e64f5a09387e1ae4c87813d4988c930dfa07f0d088f616b6da165d'
|
7
|
+
data.tar.gz: 78d5153233fd8050e9394761010fb11344bdfc84f0d2f6786a2d016026e1027938a3b625a686e004f988bb6551aad3ae677ea8584c7356a09f01266807903e48
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
|
|
24
24
|
Add i18n-tasks to the Gemfile:
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
gem 'i18n-tasks', '~> 0.9.
|
27
|
+
gem 'i18n-tasks', '~> 0.9.16'
|
28
28
|
```
|
29
29
|
|
30
30
|
Copy the default [configuration file](#configuration):
|
@@ -224,6 +224,11 @@ all the dynamic parts of the key will be considered used, e.g. `cats.tenderlove.
|
|
224
224
|
Note that only one section of the key is treated as a wildcard for each string interpolation; i.e. in this example,
|
225
225
|
`cats.tenderlove.special.name` *will* be reported as unused.
|
226
226
|
|
227
|
+
#### I18n.localize
|
228
|
+
|
229
|
+
`I18n.localize` is not supported, use [i18n-tasks-use hints](#fine-tuning).
|
230
|
+
This is because the key generated by `I18n.localize` depends on the type of the object passed in and thus cannot be inferred statically.
|
231
|
+
|
227
232
|
## Configuration
|
228
233
|
|
229
234
|
Configuration is read from `config/i18n-tasks.yml` or `config/i18n-tasks.yml.erb`.
|
@@ -95,13 +95,17 @@ module I18n::Tasks
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
INTERPOLATION_KEY_RE = /%\{[^}]
|
98
|
+
INTERPOLATION_KEY_RE = /%\{[^}]+}/
|
99
99
|
UNTRANSLATABLE_STRING = 'zxzxzx'
|
100
100
|
|
101
101
|
# @param [String] value
|
102
102
|
# @return [String] 'hello, %{name}' => 'hello, <round-trippable string>'
|
103
103
|
def replace_interpolations(value)
|
104
|
-
|
104
|
+
i = -1
|
105
|
+
value.gsub INTERPOLATION_KEY_RE do
|
106
|
+
i += 1
|
107
|
+
"#{UNTRANSLATABLE_STRING}#{i}"
|
108
|
+
end
|
105
109
|
end
|
106
110
|
|
107
111
|
# @param [String] untranslated
|
@@ -109,8 +113,17 @@ module I18n::Tasks
|
|
109
113
|
# @return [String] 'hello, <round-trippable string>' => 'hello, %{name}'
|
110
114
|
def restore_interpolations(untranslated, translated)
|
111
115
|
return translated if untranslated !~ INTERPOLATION_KEY_RE
|
112
|
-
|
113
|
-
translated.gsub(Regexp.
|
116
|
+
values = untranslated.scan(INTERPOLATION_KEY_RE)
|
117
|
+
translated.gsub(/#{Regexp.escape(UNTRANSLATABLE_STRING)}\d+/i) do |m|
|
118
|
+
values[m[UNTRANSLATABLE_STRING.length..-1].to_i]
|
119
|
+
end
|
120
|
+
rescue StandardError => e
|
121
|
+
raise CommandError.new(e, <<-TEXT.strip)
|
122
|
+
Error when restoring interpolations:
|
123
|
+
original: "#{untranslated}"
|
124
|
+
response: "#{translated}"
|
125
|
+
error: #{e.message} (#{e.class.name})
|
126
|
+
TEXT
|
114
127
|
end
|
115
128
|
end
|
116
129
|
end
|
@@ -117,9 +117,9 @@ module I18n::Tasks::Scanners
|
|
117
117
|
node.children[0].to_s
|
118
118
|
elsif %i[true false].include?(node.type)
|
119
119
|
node.type.to_s
|
120
|
-
elsif
|
120
|
+
elsif node.type == :nil
|
121
121
|
''
|
122
|
-
elsif
|
122
|
+
elsif node.type == :array && array_join_with
|
123
123
|
extract_array_as_string(
|
124
124
|
node,
|
125
125
|
array_join_with: array_join_with,
|
@@ -154,7 +154,7 @@ module I18n::Tasks::Scanners
|
|
154
154
|
else
|
155
155
|
# ignore dynamic argument in strict mode
|
156
156
|
return nil if config[:strict]
|
157
|
-
if %i[dsym dstr].include?(child.type) || (
|
157
|
+
if %i[dsym dstr].include?(child.type) || (child.type == :array && array_flatten)
|
158
158
|
extract_string(child, array_join_with: array_join_with)
|
159
159
|
else
|
160
160
|
"\#{#{child.loc.expression.source}}"
|
@@ -15,8 +15,8 @@ module I18n::Tasks::Scanners
|
|
15
15
|
# @param literal [String] e.g: "key", 'key', or :key.
|
16
16
|
# @return [String] key
|
17
17
|
def strip_literal(literal)
|
18
|
-
literal = literal[1..-1] if
|
19
|
-
literal = literal[1..-2] if "'"
|
18
|
+
literal = literal[1..-1] if literal[0] == ':'
|
19
|
+
literal = literal[1..-2] if literal[0] == "'" || literal[0] == '"'
|
20
20
|
literal
|
21
21
|
end
|
22
22
|
|
data/lib/i18n/tasks/used_keys.rb
CHANGED
@@ -124,7 +124,7 @@ module I18n::Tasks
|
|
124
124
|
|
125
125
|
# @return [Boolean] whether the key is potentially used in a code expression such as `t("category.#{category_key}")`
|
126
126
|
def used_in_expr?(key)
|
127
|
-
!!(key =~ expr_key_re) # rubocop:disable Style/DoubleNegation
|
127
|
+
!!(key =~ expr_key_re) # rubocop:disable Style/DoubleNegation
|
128
128
|
end
|
129
129
|
|
130
130
|
private
|
data/lib/i18n/tasks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -354,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
354
354
|
version: '0'
|
355
355
|
requirements: []
|
356
356
|
rubyforge_project:
|
357
|
-
rubygems_version: 2.6.
|
357
|
+
rubygems_version: 2.6.12
|
358
358
|
signing_key:
|
359
359
|
specification_version: 4
|
360
360
|
summary: Manage localization and translation with the awesome power of static analysis
|