i18n_utils 0.1 → 0.2

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: 4da6a42abbc86c4b8f9d821cccc8284ce8295a45
4
- data.tar.gz: ffea043fc721acb35b6bf61073652d746d01a49e
3
+ metadata.gz: 03248d6ed1fb29c72f2cfd65d4bf718aad8320db
4
+ data.tar.gz: 88d735905f1d484c40e0d3aa196f10dd0d3f93ca
5
5
  SHA512:
6
- metadata.gz: 3616c7d557c11704221468da7236c391a024e599b6483252d32cd8da2e90a4820be373832737c4122474cd123fd6a1f20cee5c252c3fd322e384f25da6c42083
7
- data.tar.gz: 70436c219a3718896497f3ce211babb50034eed2ee9405422b584c652d11a4300a1b7662d91c47e9065a175c3efce9647474583c42557e193971c56f0bf867d5
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(:"welcome.sign_in_now.text",
36
- sign_in: link_to(t(:"welcome.sign_in_now.sign_in"), sign_in_url))
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(:"welcome.sign_in_now.text") do |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
 
@@ -9,7 +9,8 @@ module I18nUtils
9
9
  klass.human_attribute_name(attribute)
10
10
  end
11
11
 
12
- def t_model(klass)
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
@@ -1,3 +1,3 @@
1
1
  module I18nUtils
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
@@ -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
- it "uses model_name.human" do
17
- klass = double
18
- klass.stub_chain(:model_name, :human).and_return("Clase")
19
- t_model(klass).should == "Clase"
20
- I18nUtils.t_model(klass).should == "Clase"
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.1'
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-09-11 00:00:00.000000000 Z
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n