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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd673fcea44270d6cdcfeb8b87938e7224c2a111520ef859e35ce1df4ba785b1
4
- data.tar.gz: fb7470beacfab30cfadd994023ae33f00753ddb7714854b642d8257561550491
3
+ metadata.gz: 821b971353a180079293995889c2ac37c578e4afbeb2fb4ab4f2b23d885121fa
4
+ data.tar.gz: 90b1c2814b154bd44b5c862c4cb65b3874eb4def96a8e3f87e7c39d28e9373da
5
5
  SHA512:
6
- metadata.gz: 63302f4838675fd77e69186b58fb6a91948c1d4d34f2f55779af8c2a615f07d9568a4a7c0771155036851ce2f74fc5f6b1d8f90ea81150ee294e1eb0ff90f281
7
- data.tar.gz: 38288b327cc615cd9a63c37e581b0ac707e9568087189e38ac5bfd2f64c988124b1b359b4e63bc63b3c8f9a3e5ea2c93c639239f94a4fc32f9d63838c15e9341
6
+ metadata.gz: ab19b219ea2f6b4877e1da8d103395836c7666154711591a255e093750059f72415fb283d6f427086ad96782375fa92cce9dfff4645b98fe38af203401b1a46f
7
+ data.tar.gz: 07b98f9af2b8258d696b3cb067ad54a25bf8e68e4d51f490e5f449dca418ef055cd562ae91ead997eb4be4c62a9587f83bc52bc97b52fd3f811bc176003eccac
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.6.2
4
+ - 2.7.0
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module TextHelpers
2
- VERSION = "0.7.2"
2
+ VERSION = "1.0.0"
3
3
  end
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
- # http://edgeguides.rubyonrails.org/i18n.html#customize-your-i18n-setup.
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 non-string params" do
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
@@ -3,6 +3,6 @@ require_relative "../../test_helper"
3
3
  describe TextHelpers do
4
4
 
5
5
  it "defines a version" do
6
- TextHelpers::VERSION.wont_be_nil
6
+ assert TextHelpers::VERSION
7
7
  end
8
8
  end
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.7.2
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: 2019-07-06 00:00:00.000000000 Z
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
- rubyforge_project:
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