i18n_utils 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/i18n_utils.rb +2 -1
- data/lib/i18n_utils/version.rb +1 -1
- data/spec/helpers_spec.rb +18 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03248d6ed1fb29c72f2cfd65d4bf718aad8320db
|
4
|
+
data.tar.gz: 88d735905f1d484c40e0d3aa196f10dd0d3f93ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3997d1a6bc1290ec833b399d8389c74112f19a308f2dd5790becb78d7637a2b6916c1426f24c9497d3582a5eea9d3c203e5e2243cba351e998d64dde641ca10
|
7
|
+
data.tar.gz: bf81784eb243848fa02b9b6cadd0143cb9886c02ed9b4cdfa553b26950f7121a24afd1edda617576317d7c3de35bbab182e47f6534128c37cdf8cfc8ec937d99
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Get this part with `include I18nUtils::Model` in e.g. your `ApplicationHelper`.
|
|
16
16
|
|
17
17
|
I think the Rails way to translate attributes and models is ugly and on the wrong object.
|
18
18
|
|
19
|
-
With this, your views can do `t_model(User)` instead of `User.model_name.human`.
|
19
|
+
With this, your views can do `t_model(User)` instead of `User.model_name.human`. Or pass an instance: `t_model(some_user)`
|
20
20
|
|
21
21
|
Also `t_attribute(User, :email)` instead of `User.human_attribute_name(:email)`.
|
22
22
|
|
@@ -32,16 +32,16 @@ Get this part with `include I18nUtils::Scope` in e.g. your `ApplicationHelper`.
|
|
32
32
|
Links or other markup in the middle of a translation is tricky. Either you put the HTML straight in the translation and risk the translator messing it up, or it becomes a mess:
|
33
33
|
|
34
34
|
``` slim
|
35
|
-
= t(
|
36
|
-
sign_in: link_to(t(
|
35
|
+
= t("welcome.sign_in_now.text",
|
36
|
+
sign_in: link_to(t("welcome.sign_in_now.sign_in"), sign_in_url))
|
37
37
|
```
|
38
38
|
|
39
39
|
The `t_scope` helper lets you use blocks for interpolated values, in your regular template:
|
40
40
|
|
41
41
|
``` slim
|
42
|
-
= t_scope(
|
43
|
-
scope.sign_in do
|
44
|
-
= link_to(scope.t(:sign_in), sign_in_url)
|
42
|
+
= t_scope("welcome.sign_in_now.text") do |scope|
|
43
|
+
- scope.sign_in do
|
44
|
+
= link_to(scope.t(:sign_in), sign_in_url)
|
45
45
|
```
|
46
46
|
|
47
47
|
|
data/lib/i18n_utils.rb
CHANGED
@@ -9,7 +9,8 @@ module I18nUtils
|
|
9
9
|
klass.human_attribute_name(attribute)
|
10
10
|
end
|
11
11
|
|
12
|
-
def t_model(
|
12
|
+
def t_model(class_or_instance)
|
13
|
+
klass = class_or_instance.respond_to?(:model_name) ? class_or_instance : class_or_instance.class
|
13
14
|
klass.model_name.human
|
14
15
|
end
|
15
16
|
end
|
data/lib/i18n_utils/version.rb
CHANGED
data/spec/helpers_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "i18n_utils"
|
2
2
|
|
3
|
+
class FakeModel; end
|
4
|
+
|
3
5
|
describe I18nUtils do
|
4
6
|
include I18nUtils::Helper
|
5
7
|
|
@@ -13,11 +15,22 @@ describe I18nUtils do
|
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "t_model" do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
before do
|
19
|
+
FakeModel.stub_chain(:model_name, :human).and_return("Clase")
|
20
|
+
end
|
21
|
+
|
22
|
+
context "given a class" do
|
23
|
+
it "uses model_name.human" do
|
24
|
+
t_model(FakeModel).should == "Clase"
|
25
|
+
I18nUtils.t_model(FakeModel).should == "Clase"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "given an instance" do
|
30
|
+
it "looks it up on the class" do
|
31
|
+
t_model(FakeModel.new).should == "Clase"
|
32
|
+
I18nUtils.t_model(FakeModel.new).should == "Clase"
|
33
|
+
end
|
21
34
|
end
|
22
35
|
end
|
23
36
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|