exvo_globalize 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -0
- data/app/views/layouts/exvo_globalize.html.haml +23 -0
- data/config/locales/plurals.rb +113 -0
- data/exvo_globalize.gemspec +1 -1
- data/lib/exvo_globalize/backend/chain.rb +0 -12
- data/lib/exvo_globalize/backend/fallback.rb +22 -0
- data/lib/exvo_globalize/engine.rb +11 -3
- data/lib/exvo_globalize/globalize_app.rb +2 -0
- data/lib/exvo_globalize/version.rb +1 -1
- data/lib/exvo_globalize.rb +2 -1
- data/spec/app.rb +1 -0
- data/spec/controllers/globalize_translations_controller_spec.rb +9 -12
- data/spec/exvo_globalize/caching_spec.rb +18 -0
- data/spec/{integration/locale_fallback_spec.rb → exvo_globalize/fallback_spec.rb} +2 -4
- data/spec/{integration/exvo_globalize_spec.rb → exvo_globalize/globalize_store_spec.rb} +4 -6
- data/spec/exvo_globalize/pluralizations_spec.rb +22 -0
- data/spec/factories.rb +8 -6
- data/spec/fixtures/locales/en.yml +4 -0
- data/spec/fixtures/locales/pl.yml +5 -0
- data/spec/spec_helper.rb +3 -1
- metadata +12 -8
- data/spec/integration/caching_spec.rb +0 -18
data/README.md
CHANGED
@@ -3,5 +3,28 @@
|
|
3
3
|
%head
|
4
4
|
%title= "Exvo Globalize translations"
|
5
5
|
%meta{ :name => "robots", :content => "noindex, nofollow" }
|
6
|
+
:css
|
7
|
+
p.request_host {
|
8
|
+
background: #f9fdf1;
|
9
|
+
border: 1px solid #d2e1b8;
|
10
|
+
font: 12px Verdana, Helvetica, Arial, sans-serif;
|
11
|
+
margin: 0;
|
12
|
+
padding: 0.6em 1em;
|
13
|
+
position: absolute;
|
14
|
+
right: 1em;
|
15
|
+
text-align: center;
|
16
|
+
top: 1em;
|
17
|
+
}
|
18
|
+
|
19
|
+
p.request_host span {
|
20
|
+
display: block;
|
21
|
+
font-weight: bold;
|
22
|
+
margin: 0.2em auto;
|
23
|
+
}
|
24
|
+
|
6
25
|
%body
|
26
|
+
%p.request_host
|
27
|
+
Request host:
|
28
|
+
%span= @globalize_app.request_host
|
29
|
+
|
7
30
|
= yield
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
{
|
4
|
+
:af => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
5
|
+
:am => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
6
|
+
:ar => { :i18n => { :plural => { :keys => [:zero, :one, :two, :few, :many, :other], :rule => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : [3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99].include?(n % 100) ? :many : :other } } } },
|
7
|
+
:az => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
8
|
+
:be => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
9
|
+
:bg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
10
|
+
:bh => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
11
|
+
:bn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
12
|
+
:bo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
13
|
+
:bs => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
14
|
+
:ca => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
15
|
+
:cs => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
|
16
|
+
:cy => { :i18n => { :plural => { :keys => [:one, :two, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } },
|
17
|
+
:da => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
18
|
+
:de => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
19
|
+
:dz => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
20
|
+
:el => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
21
|
+
:en => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
22
|
+
:eo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
23
|
+
:es => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
24
|
+
:et => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
25
|
+
:eu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
26
|
+
:fa => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
27
|
+
:fi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
28
|
+
:fil => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
29
|
+
:fo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
30
|
+
:fr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n && n != 2 ? :one : :other } } } },
|
31
|
+
:fur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
32
|
+
:fy => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
33
|
+
:ga => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
34
|
+
:gl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
35
|
+
:gu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
36
|
+
:guw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
37
|
+
:ha => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
38
|
+
:he => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
39
|
+
:hi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
40
|
+
:hr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
41
|
+
:hu => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
42
|
+
:id => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
43
|
+
:is => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
44
|
+
:it => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
45
|
+
:iw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
46
|
+
:ja => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
47
|
+
:jv => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
48
|
+
:ka => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
49
|
+
:km => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
50
|
+
:kn => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
51
|
+
:ko => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
52
|
+
:ku => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
53
|
+
:lb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
54
|
+
:ln => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
55
|
+
:lt => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n % 10 == 1 && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :one : [2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :few : :other } } } },
|
56
|
+
:lv => { :i18n => { :plural => { :keys => [:zero, :one, :other], :rule => lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } } },
|
57
|
+
:mg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
58
|
+
:mk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n % 10 == 1 ? :one : :other } } } },
|
59
|
+
:ml => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
60
|
+
:mn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
61
|
+
:mo => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
|
62
|
+
:mr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
63
|
+
:ms => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
64
|
+
:mt => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 || [2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :many : :other } } } },
|
65
|
+
:my => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
66
|
+
:nah => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
67
|
+
:nb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
68
|
+
:ne => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
69
|
+
:nl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
70
|
+
:nn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
71
|
+
:no => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
72
|
+
:nso => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
73
|
+
:om => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
74
|
+
:or => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
75
|
+
:pa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
76
|
+
:pap => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
77
|
+
:pl => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other } } } },
|
78
|
+
:ps => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
79
|
+
:pt => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
80
|
+
:"pt-PT" => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
81
|
+
:ro => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
|
82
|
+
:ru => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
83
|
+
:se => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
84
|
+
:sh => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
85
|
+
:sk => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
|
86
|
+
:sl => { :i18n => { :plural => { :keys => [:one, :two, :few, :other], :rule => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } },
|
87
|
+
:sma => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
88
|
+
:smi => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
89
|
+
:smj => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
90
|
+
:smn => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
91
|
+
:sms => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
|
92
|
+
:so => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
93
|
+
:sq => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
94
|
+
:sr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
95
|
+
:sv => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
96
|
+
:sw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
97
|
+
:ta => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
98
|
+
:te => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
99
|
+
:th => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
100
|
+
:ti => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
101
|
+
:tk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
102
|
+
:tl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
103
|
+
:to => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
104
|
+
:tr => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
105
|
+
:uk => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
|
106
|
+
:ur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
|
107
|
+
:vi => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
108
|
+
:wa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
|
109
|
+
:yo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
110
|
+
:zh => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
|
111
|
+
:zu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }
|
112
|
+
}
|
113
|
+
|
data/exvo_globalize.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.licenses = ['MIT']
|
21
21
|
|
22
22
|
s.add_dependency 'rails', ['>= 3.0.0']
|
23
|
-
s.add_dependency 'i18n', ['
|
23
|
+
s.add_dependency 'i18n', ['~> 0.5.0']
|
24
24
|
s.add_dependency 'haml', ['>= 3.0.0']
|
25
25
|
s.add_dependency 'httparty', ['>= 0.6.1']
|
26
26
|
s.add_development_dependency 'guard', ['>= 0.5.0']
|
@@ -10,18 +10,6 @@ module I18n
|
|
10
10
|
backends.map { |backend| backend.available_translations }.reverse.inject(&:merge)
|
11
11
|
end
|
12
12
|
|
13
|
-
# add the simplest possible fallback to the I18n.default_locale for missing translations
|
14
|
-
def translate_with_fallback(locale, key, default_options = {})
|
15
|
-
begin
|
16
|
-
# will look for a translation in all backends (using requested locale)
|
17
|
-
translate_without_fallback(locale, key, default_options)
|
18
|
-
rescue I18n::MissingTranslationData
|
19
|
-
# if it does not find a translation it will look again in all backends, but using I18n.default_locale as a locale
|
20
|
-
translate_without_fallback(I18n.default_locale, key, default_options)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
alias_method_chain :translate, :fallback
|
24
|
-
|
25
13
|
# stores a whole Hash of flattened translations
|
26
14
|
def store_flatten_translations(translations_hash)
|
27
15
|
return false if translations_hash.blank?
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module I18n
|
2
|
+
module Backend
|
3
|
+
module Fallback
|
4
|
+
module Implementation
|
5
|
+
|
6
|
+
# add the simplest possible fallback to the I18n.default_locale for missing translations
|
7
|
+
def translate(locale, key, default_options = {})
|
8
|
+
begin
|
9
|
+
# will look for a translation in all backends (using requested locale)
|
10
|
+
super(locale, key, default_options)
|
11
|
+
rescue I18n::MissingTranslationData
|
12
|
+
# if not found it will look again in all backends, but using I18n.default_locale as a locale
|
13
|
+
super(I18n.default_locale, key, default_options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
include Implementation
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,16 +1,24 @@
|
|
1
|
-
require "exvo_globalize"
|
2
1
|
require "rails"
|
3
2
|
require "i18n"
|
3
|
+
require "exvo_globalize"
|
4
4
|
|
5
5
|
module ExvoGlobalize
|
6
6
|
class Engine < Rails::Engine
|
7
7
|
initializer "exvo_globalize.configure_i18n" do |app|
|
8
|
-
#
|
9
|
-
I18n
|
8
|
+
# make pluralization rules available for both backends
|
9
|
+
I18n::Backend::GlobalizeStore.send(:include, I18n::Backend::Pluralization)
|
10
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
11
|
+
|
12
|
+
# fallback for missing translations (will search for translations using I18n.default_locale if not found in requested locale)
|
13
|
+
I18n::Backend::Chain.send(:include, I18n::Backend::Fallback)
|
10
14
|
|
11
15
|
# caching layer
|
12
16
|
I18n::Backend::GlobalizeStore.send(:include, I18n::Backend::Cache)
|
13
17
|
I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
|
18
|
+
|
19
|
+
# chained backends (fall back from first backend to the second if translation is not found in the first)
|
20
|
+
# GlobalizeStore first (database backed), YAML files second (Simple backend, the default one)
|
21
|
+
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::GlobalizeStore.new, I18n.backend)
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
data/lib/exvo_globalize.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "exvo_globalize/version"
|
2
2
|
require "exvo_globalize/backend/chain"
|
3
|
+
require "exvo_globalize/backend/fallback"
|
3
4
|
require "exvo_globalize/backend/globalize_store"
|
4
5
|
require "exvo_globalize/backend/simple"
|
5
6
|
require 'exvo_globalize/globalize_app'
|
@@ -8,5 +9,5 @@ require 'httparty'
|
|
8
9
|
|
9
10
|
# Make it a Rails engine
|
10
11
|
module ExvoGlobalize
|
11
|
-
require 'exvo_globalize/engine' if defined?(Rails)
|
12
|
+
require 'exvo_globalize/engine' if defined?(Rails)
|
12
13
|
end
|
data/spec/app.rb
CHANGED
@@ -12,6 +12,7 @@ app.config.secret_token = "aoijg543oi2u88923j4fnvfjt529hg92"
|
|
12
12
|
app.config.session_store :cookie_store, :key => "_exvo_globalize_session"
|
13
13
|
app.config.active_support.deprecation = :log
|
14
14
|
app.config.i18n.default_locale = :en
|
15
|
+
app.config.i18n.locale = :en
|
15
16
|
app.initialize!
|
16
17
|
|
17
18
|
# application controller
|
@@ -3,12 +3,13 @@ require 'json'
|
|
3
3
|
|
4
4
|
describe GlobalizeTranslationsController do
|
5
5
|
|
6
|
+
render_views
|
7
|
+
let(:page) { Capybara::Node::Simple.new(@response.body) }
|
6
8
|
let(:i18n_title) { Factory(:i18n_title) }
|
7
9
|
|
8
10
|
context "JSON" do
|
9
11
|
|
10
12
|
describe "GET :show" do
|
11
|
-
|
12
13
|
let(:translations) do
|
13
14
|
i18n_title # needed so there is some data in the database before a call to get :show
|
14
15
|
get :show, :format => :json
|
@@ -26,7 +27,6 @@ describe GlobalizeTranslationsController do
|
|
26
27
|
it "returns a JSON with translations" do
|
27
28
|
i18n_title.value.should eq(translations["en"]["title"])
|
28
29
|
end
|
29
|
-
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -34,10 +34,9 @@ describe GlobalizeTranslationsController do
|
|
34
34
|
context "HTML" do
|
35
35
|
|
36
36
|
describe "GET :show" do
|
37
|
-
|
38
37
|
context "without being logged in" do
|
39
38
|
before do
|
40
|
-
get :show
|
39
|
+
get :show
|
41
40
|
end
|
42
41
|
|
43
42
|
it { should respond_with(:forbidden) }
|
@@ -46,26 +45,25 @@ describe GlobalizeTranslationsController do
|
|
46
45
|
context "when being logged in as admin" do
|
47
46
|
before do
|
48
47
|
controller.stub!(:require_admin).and_return(true)
|
49
|
-
get :show
|
48
|
+
get :show
|
50
49
|
end
|
51
50
|
|
52
51
|
it { should respond_with(:success) }
|
53
|
-
end
|
54
52
|
|
53
|
+
it "displays Globalize request host" do
|
54
|
+
page.should have_selector('p.request_host')
|
55
|
+
end
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
59
|
describe "PUT :update" do
|
58
|
-
|
59
60
|
let(:intro) { "Introduction" }
|
60
61
|
let(:translations) { { :en => { :intro => intro } } }
|
61
62
|
|
62
|
-
render_views
|
63
|
-
let(:page) { Capybara::Node::Simple.new(@response.body) }
|
64
|
-
|
65
63
|
before do
|
66
64
|
controller.stub!(:require_admin).and_return(true)
|
67
65
|
GlobalizeApp.any_instance.stub(:fetch_translations) { translations }
|
68
|
-
put :update
|
66
|
+
put :update
|
69
67
|
end
|
70
68
|
|
71
69
|
it "updates the translations" do
|
@@ -79,7 +77,6 @@ describe GlobalizeTranslationsController do
|
|
79
77
|
it "displays a flash notice" do
|
80
78
|
page.should have_selector('p.notice')
|
81
79
|
end
|
82
|
-
|
83
80
|
end
|
84
81
|
|
85
82
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ExvoGlobalize do
|
4
|
+
|
5
|
+
it "caches translations in memory" do
|
6
|
+
i18n_header = Factory(:i18n_header)
|
7
|
+
|
8
|
+
old = I18n.translate(:header)
|
9
|
+
new = 'New header'
|
10
|
+
|
11
|
+
i18n_header.update_attributes(:value => new)
|
12
|
+
i18n_header.reload
|
13
|
+
i18n_header.value.should eq(new)
|
14
|
+
|
15
|
+
I18n.translate(:header).should eq(old)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -2,9 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ExvoGlobalize do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
let(:i18n_example) { Factory(:i18n_example) }
|
5
|
+
let(:i18n_header) { Factory(:i18n_header) }
|
8
6
|
|
9
7
|
context "locale fallbacks" do
|
10
8
|
|
@@ -15,7 +13,7 @@ describe ExvoGlobalize do
|
|
15
13
|
end
|
16
14
|
|
17
15
|
it "uses translation from the GlobalizeStore backend" do
|
18
|
-
|
16
|
+
i18n_header.value.should eql(I18n.translate(:header))
|
19
17
|
end
|
20
18
|
|
21
19
|
it "uses translation from the Simple backend if it is not found in the GlobalizeTranslation backend" do
|
@@ -2,10 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ExvoGlobalize do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
let(:i18n_example) { Factory(:i18n_example) }
|
8
|
-
let(:i18n_nested_example) { Factory(:i18n_nested_example) }
|
5
|
+
let(:i18n_header) { Factory(:i18n_header) }
|
6
|
+
let(:i18n_nested_header) { Factory(:i18n_nested_header) }
|
9
7
|
let(:i18n_title) { Factory(:i18n_title) }
|
10
8
|
|
11
9
|
it "respects the default_locale setting" do
|
@@ -13,11 +11,11 @@ describe ExvoGlobalize do
|
|
13
11
|
end
|
14
12
|
|
15
13
|
it "provides a valid translation for a given key" do
|
16
|
-
|
14
|
+
i18n_header.value.should eq(I18n.t(:header))
|
17
15
|
end
|
18
16
|
|
19
17
|
it "provides a valid translation for a scoped key" do
|
20
|
-
|
18
|
+
i18n_nested_header.value.should eq(I18n.t(:header, :scope => [:nested]))
|
21
19
|
end
|
22
20
|
|
23
21
|
context "translation storage" do
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ExvoGlobalize do
|
6
|
+
|
7
|
+
context "Polish pluralization rules" do
|
8
|
+
|
9
|
+
before { I18n.locale = :pl }
|
10
|
+
|
11
|
+
specify { I18n.t(:mail, :count => 0).should match(/listów$/) }
|
12
|
+
specify { I18n.t(:mail, :count => 1).should match(/list$/) }
|
13
|
+
specify { I18n.t(:mail, :count => 3).should match(/listy$/) }
|
14
|
+
specify { I18n.t(:mail, :count => 5).should match(/listów$/) }
|
15
|
+
specify { I18n.t(:mail, :count => 12).should match(/listów$/) }
|
16
|
+
specify { I18n.t(:mail, :count => 22).should match(/listy$/) }
|
17
|
+
|
18
|
+
after { I18n.locale = I18n.default_locale }
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/factories.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Factory.define :i18n_header, :class => GlobalizeTranslation do |u|
|
2
4
|
u.locale 'en'
|
3
|
-
u.key '
|
4
|
-
u.value 'This is
|
5
|
+
u.key 'header'
|
6
|
+
u.value 'This is a header'
|
5
7
|
end
|
6
8
|
|
7
|
-
Factory.define :
|
9
|
+
Factory.define :i18n_nested_header, :class => GlobalizeTranslation do |u|
|
8
10
|
u.locale 'en'
|
9
|
-
u.key 'nested.
|
10
|
-
u.value 'This is a nested
|
11
|
+
u.key 'nested.header'
|
12
|
+
u.value 'This is a nested header'
|
11
13
|
end
|
12
14
|
|
13
15
|
Factory.define :i18n_title, :class => GlobalizeTranslation do |u|
|
data/spec/spec_helper.rb
CHANGED
@@ -3,13 +3,15 @@ $:.unshift(File.dirname(__FILE__))
|
|
3
3
|
|
4
4
|
require 'rails'
|
5
5
|
require 'exvo_globalize'
|
6
|
-
|
7
6
|
require File.join(File.dirname(__FILE__), 'app')
|
8
7
|
|
9
8
|
require 'rspec/rails'
|
10
9
|
require 'factory_girl_rails'
|
11
10
|
require 'shoulda-matchers'
|
12
11
|
|
12
|
+
I18n.load_path << "spec/fixtures/locales/en.yml"
|
13
|
+
I18n.load_path << "spec/fixtures/locales/pl.yml"
|
14
|
+
|
13
15
|
# Requires supporting ruby files with custom matchers and macros, etc.
|
14
16
|
# in spec/support/ and its subdirectories.
|
15
17
|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exvo_globalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Pawe\xC5\x82 Go\xC5\x9Bcicki"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-17 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
hash: 11
|
46
46
|
segments:
|
@@ -246,10 +246,12 @@ files:
|
|
246
246
|
- app/views/globalize_translations/_flash_messages.html.haml
|
247
247
|
- app/views/globalize_translations/show.html.haml
|
248
248
|
- app/views/layouts/exvo_globalize.html.haml
|
249
|
+
- config/locales/plurals.rb
|
249
250
|
- config/routes.rb
|
250
251
|
- exvo_globalize.gemspec
|
251
252
|
- lib/exvo_globalize.rb
|
252
253
|
- lib/exvo_globalize/backend/chain.rb
|
254
|
+
- lib/exvo_globalize/backend/fallback.rb
|
253
255
|
- lib/exvo_globalize/backend/globalize_store.rb
|
254
256
|
- lib/exvo_globalize/backend/simple.rb
|
255
257
|
- lib/exvo_globalize/engine.rb
|
@@ -259,11 +261,13 @@ files:
|
|
259
261
|
- lib/generators/exvo_globalize/templates/migration.rb
|
260
262
|
- spec/app.rb
|
261
263
|
- spec/controllers/globalize_translations_controller_spec.rb
|
264
|
+
- spec/exvo_globalize/caching_spec.rb
|
265
|
+
- spec/exvo_globalize/fallback_spec.rb
|
266
|
+
- spec/exvo_globalize/globalize_store_spec.rb
|
267
|
+
- spec/exvo_globalize/pluralizations_spec.rb
|
262
268
|
- spec/factories.rb
|
263
269
|
- spec/fixtures/locales/en.yml
|
264
|
-
- spec/
|
265
|
-
- spec/integration/exvo_globalize_spec.rb
|
266
|
-
- spec/integration/locale_fallback_spec.rb
|
270
|
+
- spec/fixtures/locales/pl.yml
|
267
271
|
- spec/models/globalize_translation_spec.rb
|
268
272
|
- spec/spec_helper.rb
|
269
273
|
has_rdoc: true
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ExvoGlobalize do
|
4
|
-
|
5
|
-
let(:i18n_example) { Factory(:i18n_example) }
|
6
|
-
|
7
|
-
it "caches translations in memory" do
|
8
|
-
old = I18n.translate(:example)
|
9
|
-
new = 'New example'
|
10
|
-
|
11
|
-
i18n_example.update_attributes(:value => new)
|
12
|
-
i18n_example.reload
|
13
|
-
i18n_example.value.should eq(new)
|
14
|
-
|
15
|
-
I18n.translate(:example).should eq(old)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|