activemodel_translation 0.1.1 → 0.2.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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ebff53843af36ed15cd7e7f891e1028f0c2f72
|
4
|
+
data.tar.gz: 61f10c4225587742605f96a05a7cbc61ed020118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e371748e4bd36eaeeac59df2156118514d1929f279cde37a63895e5eabe62e84ade966f5fa6af724502ab376c5dd19e794b4e02e08e6ce464652e3d74a76f9b
|
7
|
+
data.tar.gz: bd0bab789284f5c28702dea45b9a4eb552caa62543f1b137502395d4619b8ef02539ce0954e93042d97085f91d145e400ea09170a89ed83d1a2594f14f05f0ea
|
data/README.md
CHANGED
@@ -37,22 +37,17 @@ Or install it yourself as:
|
|
37
37
|
class User < ActiveRecord::Base
|
38
38
|
# lazy translation
|
39
39
|
def title
|
40
|
-
super || self.class.t(
|
40
|
+
super || self.class.t('.default_title')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
# translated plural model name
|
45
|
-
User.model_name.
|
45
|
+
User.model_name.human_plural
|
46
46
|
|
47
47
|
# ru.yml
|
48
48
|
# activerecord:
|
49
|
-
#
|
50
|
-
# user:
|
51
|
-
# one: Пользователь
|
52
|
-
# few: Пользователя
|
53
|
-
# many: Пользователей
|
54
|
-
# other: Пользователя
|
55
|
-
# plural: Пользователи
|
49
|
+
# models_plural:
|
50
|
+
# user: Пользователи
|
56
51
|
```
|
57
52
|
|
58
53
|
## Contributing
|
@@ -2,21 +2,18 @@ require 'active_model'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Name
|
5
|
-
def
|
6
|
-
return @
|
7
|
-
|
8
|
-
|
9
|
-
need_plural = options[:plural]
|
5
|
+
def human_plural(options={})
|
6
|
+
return @plural unless @klass.respond_to?(:lookup_ancestors) &&
|
7
|
+
@klass.respond_to?(:i18n_scope)
|
10
8
|
|
11
9
|
defaults = @klass.lookup_ancestors.map do |klass|
|
12
10
|
klass.model_name.i18n_key
|
13
11
|
end
|
14
|
-
defaults = defaults.map { |key| :"#{key}.plural" } if need_plural
|
15
12
|
|
16
13
|
defaults << options[:default] if options[:default]
|
17
|
-
defaults <<
|
14
|
+
defaults << @plural
|
18
15
|
|
19
|
-
options = { scope: [@klass.i18n_scope, :
|
16
|
+
options = { scope: [@klass.i18n_scope, :models_plural], default: defaults }.merge!(options.except(:default))
|
20
17
|
I18n.translate(defaults.shift, options)
|
21
18
|
end
|
22
19
|
end
|
@@ -5,13 +5,11 @@ require 'models/person'
|
|
5
5
|
class ActiveModelHumanNameTests < ::Minitest::Test
|
6
6
|
def setup
|
7
7
|
I18n.backend = I18n::Backend::Simple.new
|
8
|
-
I18n.backend.store_translations 'ru', activemodel: {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
plural: 'Пользователи',
|
14
|
-
} } }
|
8
|
+
I18n.backend.store_translations 'ru', activemodel: {
|
9
|
+
models_plural: {
|
10
|
+
person: 'Пользователи',
|
11
|
+
},
|
12
|
+
}
|
15
13
|
I18n.locale = :ru
|
16
14
|
@person_name = ActiveModel::Name.new(Person)
|
17
15
|
@child_name = ActiveModel::Name.new(Child)
|
@@ -22,39 +20,15 @@ class ActiveModelHumanNameTests < ::Minitest::Test
|
|
22
20
|
I18n.locale = :en
|
23
21
|
end
|
24
22
|
|
25
|
-
def test_human_with_translation
|
26
|
-
assert_equal 'Пользователь', @person_name.human
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_human_with_fallback_translation
|
30
|
-
assert_equal 'Пользователь', @child_name.human
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_human_without_translation
|
34
|
-
assert_equal 'Gender', @gender_name.human
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_human_with_count_with_translation
|
38
|
-
assert_equal 'Пользователя', @person_name.human(count: 1.5)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_human_with_count_with_fallback_translation
|
42
|
-
assert_equal 'Пользователя', @child_name.human(count: 1.5)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_human_with_count_without_translation
|
46
|
-
assert_equal 'Gender', @gender_name.human(count: 1.5)
|
47
|
-
end
|
48
|
-
|
49
23
|
def test_plural_human_with_translation
|
50
|
-
assert_equal 'Пользователи', @person_name.
|
24
|
+
assert_equal 'Пользователи', @person_name.human_plural
|
51
25
|
end
|
52
26
|
|
53
27
|
def test_plural_human_with_fallback_translation
|
54
|
-
assert_equal 'Пользователи', @child_name.
|
28
|
+
assert_equal 'Пользователи', @child_name.human_plural
|
55
29
|
end
|
56
30
|
|
57
31
|
def test_plural_human_without_translation
|
58
|
-
assert_equal 'person_genders', @gender_name.
|
32
|
+
assert_equal 'person_genders', @gender_name.human_plural
|
59
33
|
end
|
60
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel_translation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|