text_helpers 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +12 -4
- data/lib/text_helpers/contexts.rb +2 -6
- data/lib/text_helpers/translation.rb +6 -3
- data/lib/text_helpers/version.rb +1 -1
- data/test/lib/text_helpers/translation_test.rb +9 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 320e647924e409f4729c273ce71c68c2042c3748
|
4
|
+
data.tar.gz: f5a7f39ee0319697a1f6569666b28083043b892d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a12a9414e716c6cc7c7d7a7a4265cb20222bced8ea6d607d0e2cfed59f08f0b8fcc3f9159f6013befd721b217a8040080a25406e09f0dac04fe85775bdeeff37
|
7
|
+
data.tar.gz: c81f7a27c1467d3d3c924f11176e7058d5dbf744e2326f4c48da33a6c126f36cf26443b33c539f2e76d02b14a0fef8b7242884481e3b69e7396753a1deee3cab
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,11 +18,19 @@ structure mirroring the app directory structure. The text for
|
|
18
18
|
requirement, but will go a long way toward keeping your locales easily
|
19
19
|
maintainable.
|
20
20
|
|
21
|
+
If you're using this within a Rails project, you'll probably want to add the
|
22
|
+
following line to your application.rb to ensure that Rails loads any locale
|
23
|
+
files organized this way:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
|
27
|
+
```
|
28
|
+
|
21
29
|
In any locale file entry, you can reference another key in the locale file by
|
22
|
-
using the syntax `!scope.to.key!`. For the sake of maintainability,
|
23
|
-
|
24
|
-
static
|
25
|
-
variable text.
|
30
|
+
using the syntax `!scope.to.key!`. For the sake of maintainability, I
|
31
|
+
recommend restricting the use of this feature to small, highly-recycled
|
32
|
+
fragments of static text. `I18n`'s built-in `%{value}` interpolation can be
|
33
|
+
used for variable text.
|
26
34
|
|
27
35
|
### In Views
|
28
36
|
|
@@ -22,12 +22,8 @@ shared_context "a view spec", view: true do
|
|
22
22
|
def translation_scope
|
23
23
|
matcher = /(?<path>.*)\/_?(?<view>[^\/.]+)(?<extension>\.html\.haml)?/
|
24
24
|
info = matcher.match(example.metadata[:full_description])
|
25
|
+
path = info[:path].gsub('/', '.')
|
25
26
|
|
26
|
-
|
27
|
-
path = info[:path].gsub('/', '.')
|
28
|
-
"views.#{path}.#{info[:view]}"
|
29
|
-
else
|
30
|
-
"views.#{params[:controller]}.#{params[:action]}"
|
31
|
-
end
|
27
|
+
"views.#{path}.#{info[:view]}"
|
32
28
|
end
|
33
29
|
end
|
@@ -21,11 +21,14 @@ module TextHelpers
|
|
21
21
|
text = I18n.t(key, {
|
22
22
|
scope: self.translation_scope,
|
23
23
|
default: "!#{key}!"
|
24
|
-
}.merge(options))
|
24
|
+
}.merge(options)).strip
|
25
25
|
|
26
26
|
# Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
|
27
|
-
|
28
|
-
|
27
|
+
while text =~ /!([\w._\/]+)!/ do
|
28
|
+
text = text.gsub(/!([\w._\/]+)!/) { |match| I18n.t($1) }
|
29
|
+
end
|
30
|
+
|
31
|
+
text.html_safe
|
29
32
|
end
|
30
33
|
|
31
34
|
# Public: Get an HTML representation of the rendered markdown for the passed I18n key.
|
data/lib/text_helpers/version.rb
CHANGED
@@ -21,10 +21,11 @@ describe TextHelpers::Translation do
|
|
21
21
|
test_key: @global_text,
|
22
22
|
multiline_key: @multiline_text,
|
23
23
|
test: {
|
24
|
-
email_key:
|
25
|
-
test_key:
|
26
|
-
list_key:
|
27
|
-
interpolated_key: "Global? (!test_key!)"
|
24
|
+
email_key: "<#{@email_address}>",
|
25
|
+
test_key: "*#{@scoped_text}*",
|
26
|
+
list_key: "* #{@scoped_text}",
|
27
|
+
interpolated_key: "Global? (!test_key!)",
|
28
|
+
recursive_key: "Recursively !test.interpolated_key!"
|
28
29
|
}
|
29
30
|
}
|
30
31
|
end
|
@@ -83,6 +84,10 @@ describe TextHelpers::Translation do
|
|
83
84
|
it "interpolates values wrapped in !!" do
|
84
85
|
assert_equal "Global? (#{@global_text})", @helper.text(:interpolated_key)
|
85
86
|
end
|
87
|
+
|
88
|
+
it "handles recursive interpolation" do
|
89
|
+
assert_equal "Recursively Global? (#{@global_text})", @helper.text(:recursive_key)
|
90
|
+
end
|
86
91
|
end
|
87
92
|
|
88
93
|
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.2.
|
4
|
+
version: 0.2.2
|
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: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.2.2
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: TextHelpers is a gem which supplies some basic utilities for text localization
|