text_helpers 0.7.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/lib/text_helpers/translation.rb +2 -2
- data/lib/text_helpers/version.rb +1 -1
- data/lib/text_helpers.rb +2 -2
- data/test/lib/text_helpers/translation_test.rb +23 -1
- data/test/lib/text_helpers/version_test.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821b971353a180079293995889c2ac37c578e4afbeb2fb4ab4f2b23d885121fa
|
4
|
+
data.tar.gz: 90b1c2814b154bd44b5c862c4cb65b3874eb4def96a8e3f87e7c39d28e9373da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab19b219ea2f6b4877e1da8d103395836c7666154711591a255e093750059f72415fb283d6f427086ad96782375fa92cce9dfff4645b98fe38af203401b1a46f
|
7
|
+
data.tar.gz: 07b98f9af2b8258d696b3cb067ad54a25bf8e68e4d51f490e5f449dca418ef055cd562ae91ead997eb4be4c62a9587f83bc52bc97b52fd3f811bc176003eccac
|
data/.travis.yml
CHANGED
@@ -35,7 +35,7 @@ module TextHelpers
|
|
35
35
|
# Returns a String resulting from the I18n lookup.
|
36
36
|
def text(key, options = {})
|
37
37
|
options = html_safe_options(options)
|
38
|
-
text = I18n.t(key, {
|
38
|
+
text = I18n.t(key, **{
|
39
39
|
scope: self.translation_scope,
|
40
40
|
default: "!#{key}!"
|
41
41
|
}.merge(options)).strip
|
@@ -45,7 +45,7 @@ module TextHelpers
|
|
45
45
|
|
46
46
|
# Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
|
47
47
|
while text =~ KEYPATH_MATCHER do
|
48
|
-
text = text.gsub(KEYPATH_MATCHER) { |match| I18n.t($1, interpolation_options) }
|
48
|
+
text = text.gsub(KEYPATH_MATCHER) { |match| I18n.t($1, **interpolation_options) }
|
49
49
|
end
|
50
50
|
|
51
51
|
text = smartify(text) if options.fetch(:smart, true)
|
data/lib/text_helpers/version.rb
CHANGED
data/lib/text_helpers.rb
CHANGED
@@ -5,10 +5,10 @@ require "text_helpers/railtie" if defined?(Rails)
|
|
5
5
|
module TextHelpers
|
6
6
|
# RaiseExceptionHandler just raises all exceptions, rather than swallowing
|
7
7
|
# MissingTranslation ones. It's cribbed almost verbatim from
|
8
|
-
#
|
8
|
+
# https://guides.rubyonrails.org/i18n.html#using-different-exception-handlers.
|
9
9
|
class RaiseExceptionHandler < I18n::ExceptionHandler
|
10
10
|
def call(exception, locale, key, options)
|
11
|
-
if exception.is_a?(I18n::MissingTranslation)
|
11
|
+
if exception.is_a?(I18n::MissingTranslation) && key.to_s != "i18n.plural.rule"
|
12
12
|
raise exception.to_exception
|
13
13
|
else
|
14
14
|
super
|
@@ -171,10 +171,32 @@ describe TextHelpers::Translation do
|
|
171
171
|
assert_equal "This is what <b>Han</b> Solo said", @helper.text(:argument_key, user: "<b>Han</b> Solo".html_safe)
|
172
172
|
end
|
173
173
|
|
174
|
-
it "correctly handles
|
174
|
+
it "correctly handles pluralized keys" do
|
175
175
|
assert_equal "A single piece of text", @helper.text(:pluralized_key, count: 1)
|
176
176
|
assert_equal "2 pieces of text", @helper.text(:pluralized_key, count: 2)
|
177
177
|
end
|
178
|
+
|
179
|
+
describe "when the pluralization backend is configured and the exception handler is enabled" do
|
180
|
+
before do
|
181
|
+
@original_backend = I18n.backend
|
182
|
+
new_backend = @original_backend.dup
|
183
|
+
new_backend.extend(I18n::Backend::Pluralization)
|
184
|
+
I18n.backend = new_backend
|
185
|
+
|
186
|
+
@original_exception_handler = I18n.exception_handler
|
187
|
+
I18n.exception_handler = TextHelpers::RaiseExceptionHandler.new
|
188
|
+
end
|
189
|
+
|
190
|
+
after do
|
191
|
+
I18n.backend = @original_backend
|
192
|
+
I18n.exception_handler = @original_exception_handler
|
193
|
+
end
|
194
|
+
|
195
|
+
it "correctly handles pluralized keys" do
|
196
|
+
assert_equal "A single piece of text", @helper.text(:pluralized_key, count: 1)
|
197
|
+
assert_equal "2 pieces of text", @helper.text(:pluralized_key, count: 2)
|
198
|
+
end
|
199
|
+
end
|
178
200
|
end
|
179
201
|
|
180
202
|
describe "when no valid scope is provided" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.7.6
|
126
|
+
rubygems_version: 3.1.2
|
128
127
|
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: TextHelpers is a gem which supplies some basic utilities for text localization
|