r18n-core 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/ChangeLog +5 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.rdoc +25 -25
  4. data/Rakefile +0 -1
  5. data/lib/r18n-core.rb +5 -5
  6. data/lib/r18n-core/filters.rb +45 -45
  7. data/lib/r18n-core/helpers.rb +4 -4
  8. data/lib/r18n-core/i18n.rb +30 -30
  9. data/lib/r18n-core/locale.rb +26 -26
  10. data/lib/r18n-core/translated.rb +23 -23
  11. data/lib/r18n-core/translated_string.rb +4 -4
  12. data/lib/r18n-core/translation.rb +10 -10
  13. data/lib/r18n-core/unsupported_locale.rb +6 -6
  14. data/lib/r18n-core/untranslated.rb +13 -13
  15. data/lib/r18n-core/utils.rb +4 -4
  16. data/lib/r18n-core/version.rb +1 -1
  17. data/lib/r18n-core/yaml_loader.rb +13 -11
  18. data/locales/bg.rb +3 -3
  19. data/locales/ca.rb +6 -5
  20. data/locales/cs.rb +5 -5
  21. data/locales/da.rb +4 -4
  22. data/locales/de.rb +4 -4
  23. data/locales/en-us.rb +1 -1
  24. data/locales/en.rb +6 -6
  25. data/locales/eo.rb +4 -4
  26. data/locales/es.rb +4 -4
  27. data/locales/fi.rb +5 -5
  28. data/locales/fr.rb +6 -6
  29. data/locales/hu.rb +1 -1
  30. data/locales/it.rb +5 -5
  31. data/locales/ja.rb +5 -4
  32. data/locales/kk.rb +4 -4
  33. data/locales/lv.rb +5 -5
  34. data/locales/nl.rb +5 -5
  35. data/locales/pl.rb +5 -5
  36. data/locales/pt.rb +4 -4
  37. data/locales/ru.rb +5 -5
  38. data/locales/sk.rb +5 -5
  39. data/locales/sv-se.rb +4 -4
  40. data/locales/th.rb +7 -4
  41. data/locales/zh.rb +6 -5
  42. data/r18n-core.gemspec +0 -1
  43. data/spec/filters_spec.rb +48 -48
  44. data/spec/i18n_spec.rb +32 -32
  45. data/spec/locale_spec.rb +20 -20
  46. data/spec/locales/cs_spec.rb +2 -2
  47. data/spec/locales/hu_spec.rb +1 -1
  48. data/spec/locales/it_spec.rb +1 -1
  49. data/spec/locales/pl_spec.rb +2 -2
  50. data/spec/locales/ru_spec.rb +3 -3
  51. data/spec/locales/sk_spec.rb +2 -2
  52. data/spec/r18n_spec.rb +21 -21
  53. data/spec/spec_helper.rb +3 -3
  54. data/spec/translated_spec.rb +24 -24
  55. data/spec/translation_spec.rb +10 -10
  56. data/spec/yaml_loader_spec.rb +10 -10
  57. metadata +24 -26
data/spec/locale_spec.rb CHANGED
@@ -11,12 +11,12 @@ describe R18n::Locale do
11
11
  R18n::Locale.available.class.should == Array
12
12
  R18n::Locale.available.should_not be_empty
13
13
  end
14
-
14
+
15
15
  it "should check is locale exists" do
16
16
  R18n::Locale.exists?('ru').should be_true
17
17
  R18n::Locale.exists?('no-LC').should be_false
18
18
  end
19
-
19
+
20
20
  it "should set locale properties" do
21
21
  locale_class = Class.new(R18n::Locale) do
22
22
  set :one => 1
@@ -32,7 +32,7 @@ describe R18n::Locale do
32
32
  @ru.code.should == 'ru'
33
33
  @ru.title.should == 'Русский'
34
34
  end
35
-
35
+
36
36
  it "should load locale by Symbol" do
37
37
  R18n::Locale.load(:ru).should == R18n::Locale.load('ru')
38
38
  end
@@ -54,15 +54,15 @@ describe R18n::Locale do
54
54
 
55
55
  it "should use UnsupportedLocale if locale file isn't exists" do
56
56
  @en.should be_supported
57
-
57
+
58
58
  unsupported = R18n::Locale.load('no-LC')
59
59
  unsupported.should_not be_supported
60
60
  unsupported.should be_a(R18n::UnsupportedLocale)
61
-
61
+
62
62
  unsupported.code.downcase.should == 'no-lc'
63
63
  unsupported.title.downcase.should == 'no-lc'
64
64
  unsupported.ltr?.should be_true
65
-
65
+
66
66
  unsupported.pluralize(5).should == 'n'
67
67
  unsupported.inspect.downcase.should == 'unsupported locale no-lc'
68
68
  end
@@ -78,33 +78,33 @@ describe R18n::Locale do
78
78
  it "should translate month, week days and am/pm names in strftime" do
79
79
  i18n = R18n::I18n.new 'ru'
80
80
  time = Time.at(0).utc
81
-
81
+
82
82
  @ru.localize(time, '%a %A').should == 'Чтв Четверг'
83
83
  @ru.localize(time, '%b %B').should == 'янв января'
84
84
  @ru.localize(time, '%H:%M%p').should == '00:00 утра'
85
85
  end
86
-
86
+
87
87
  it "should localize date for human" do
88
88
  i18n = R18n::I18n.new('en')
89
-
89
+
90
90
  @en.localize(Date.today + 2, :human, i18n).should == 'after 2 days'
91
91
  @en.localize(Date.today + 1, :human, i18n).should == 'tomorrow'
92
92
  @en.localize(Date.today, :human, i18n).should == 'today'
93
93
  @en.localize(Date.today - 1, :human, i18n).should == 'yesterday'
94
94
  @en.localize(Date.today - 3, :human, i18n).should == '3 days ago'
95
-
95
+
96
96
  y2k = Date.parse('2000-01-08')
97
97
  @en.localize(y2k, :human, i18n, y2k + 8 ).should == '8th of January'
98
98
  @en.localize(y2k, :human, i18n, y2k - 365).should == '8th of January, 2000'
99
99
  end
100
-
100
+
101
101
  it "should localize times for human" do
102
102
  minute = 60
103
103
  hour = 60 * minute
104
104
  day = 24 * hour
105
105
  zero = Time.at(0).utc
106
106
  p = [:human, R18n::I18n.new('en'), zero]
107
-
107
+
108
108
  @en.localize( zero + 7 * day, *p).should == '8th of January 00:00'
109
109
  @en.localize( zero + 50 * hour, *p).should == 'after 2 days 02:00'
110
110
  @en.localize( zero + 25 * hour, *p).should == 'tomorrow 01:00'
@@ -118,22 +118,22 @@ describe R18n::Locale do
118
118
  @en.localize( zero - 2 * hour, *p).should == '2 hours ago'
119
119
  @en.localize( zero - 13 * hour, *p).should == 'yesterday 11:00'
120
120
  @en.localize( zero - 50 * hour, *p).should == '3 days ago 22:00'
121
-
121
+
122
122
  @en.localize( zero - 9 * day, *p).should == '23rd of December, 1969 00:00'
123
123
  @en.localize( zero - 365 * day, *p).should == '1st of January, 1969 00:00'
124
124
  end
125
-
125
+
126
126
  it "should use standard formatter by default" do
127
127
  @ru.localize(Time.at(0).utc).should == '01.01.1970 00:00'
128
128
  end
129
-
129
+
130
130
  it "shouldn't localize time without i18n object" do
131
131
  @ru.localize(Time.at(0)).should_not == Time.at(0).to_s
132
132
  @ru.localize(Time.at(0), :full).should_not == Time.at(0).to_s
133
-
133
+
134
134
  @ru.localize(Time.at(0), :human).should == Time.at(0).to_s
135
135
  end
136
-
136
+
137
137
  it "should raise error on unknown formatter" do
138
138
  lambda {
139
139
  @ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
@@ -144,21 +144,21 @@ describe R18n::Locale do
144
144
  locale = R18n::Locale.load('../spec/translations/general/en')
145
145
  locale.should be_a(R18n::UnsupportedLocale)
146
146
  end
147
-
147
+
148
148
  it "should ignore code case in locales" do
149
149
  upcase = R18n::Locale.load('RU')
150
150
  downcase = R18n::Locale.load('ru')
151
151
  upcase.should == downcase
152
152
  upcase.code.should == 'ru'
153
153
  downcase.code.should == 'ru'
154
-
154
+
155
155
  upcase = R18n::Locale.load('no-LC')
156
156
  downcase = R18n::Locale.load('no-lc')
157
157
  upcase.should == downcase
158
158
  upcase.code.should == 'no-lc'
159
159
  downcase.code.should == 'no-lc'
160
160
  end
161
-
161
+
162
162
  it "should load locale with underscore" do
163
163
  R18n::Locale.load('no_LC').code.should == 'no-lc'
164
164
  end
@@ -5,11 +5,11 @@ describe R18n::Locales::Cs do
5
5
  cs = R18n::Locale.load('cs')
6
6
  cs.pluralize(0).should == 0
7
7
  cs.pluralize(1).should == 1
8
-
8
+
9
9
  cs.pluralize(2).should == 2
10
10
  cs.pluralize(3).should == 2
11
11
  cs.pluralize(4).should == 2
12
-
12
+
13
13
  cs.pluralize(5).should == 'n'
14
14
  cs.pluralize(21).should == 'n'
15
15
  cs.pluralize(11).should == 'n'
@@ -9,7 +9,7 @@ describe R18n::Locales::Hu do
9
9
  hu.l(-10000).should == '−10 000'
10
10
  hu.l(100000).should == '100 000'
11
11
  end
12
-
12
+
13
13
  it "should use Hungarian time format" do
14
14
  hu = R18n::I18n.new('hu')
15
15
  hu.l(Time.at(0).utc).should == '1970. 01. 01., 00:00'
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require File.expand_path('../../spec_helper', __FILE__)
3
-
3
+
4
4
  describe R18n::Locales::It do
5
5
  it "should format Italian date" do
6
6
  italian = R18n::I18n.new('it')
@@ -5,12 +5,12 @@ describe R18n::Locales::Pl do
5
5
  pl = R18n::Locale.load 'pl'
6
6
  pl.pluralize(0).should == 0
7
7
  pl.pluralize(1).should == 1
8
-
8
+
9
9
  pl.pluralize(2).should == 2
10
10
  pl.pluralize(4).should == 2
11
11
  pl.pluralize(22).should == 2
12
12
  pl.pluralize(102).should == 2
13
-
13
+
14
14
  pl.pluralize(5).should == 'n'
15
15
  pl.pluralize(11).should == 'n'
16
16
  pl.pluralize(12).should == 'n'
@@ -4,16 +4,16 @@ describe R18n::Locales::Ru do
4
4
  it "should use Russian pluralization" do
5
5
  ru = R18n::Locale.load 'ru'
6
6
  ru.pluralize(0).should == 0
7
-
7
+
8
8
  ru.pluralize(1).should == 1
9
9
  ru.pluralize(21).should == 1
10
10
  ru.pluralize(101).should == 1
11
-
11
+
12
12
  ru.pluralize(2).should == 2
13
13
  ru.pluralize(4).should == 2
14
14
  ru.pluralize(22).should == 2
15
15
  ru.pluralize(102).should == 2
16
-
16
+
17
17
  ru.pluralize(5).should == 'n'
18
18
  ru.pluralize(11).should == 'n'
19
19
  ru.pluralize(12).should == 'n'
@@ -5,11 +5,11 @@ describe R18n::Locales::Sk do
5
5
  sk = R18n::Locale.load('Sk')
6
6
  sk.pluralize(0).should == 0
7
7
  sk.pluralize(1).should == 1
8
-
8
+
9
9
  sk.pluralize(2).should == 2
10
10
  sk.pluralize(3).should == 2
11
11
  sk.pluralize(4).should == 2
12
-
12
+
13
13
  sk.pluralize(5).should == 'n'
14
14
  sk.pluralize(21).should == 'n'
15
15
  sk.pluralize(11).should == 'n'
data/spec/r18n_spec.rb CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../spec_helper', __FILE__)
3
3
 
4
4
  describe R18n do
5
5
  include R18n::Helpers
6
-
6
+
7
7
  after do
8
8
  R18n.default_loader = R18n::Loader::YAML
9
9
  R18n.reset
@@ -13,21 +13,21 @@ describe R18n do
13
13
  i18n = R18n::I18n.new('en')
14
14
  R18n.set(i18n)
15
15
  R18n.get.should == i18n
16
-
16
+
17
17
  R18n.reset
18
18
  R18n.get.should be_nil
19
19
  end
20
-
20
+
21
21
  it "should set setter to I18n" do
22
22
  i18n = R18n::I18n.new('en')
23
23
  R18n.set(i18n)
24
-
24
+
25
25
  i18n = R18n::I18n.new('ru')
26
26
  R18n.set { i18n }
27
-
27
+
28
28
  R18n.get.should == i18n
29
29
  end
30
-
30
+
31
31
  it "shuld create I18n object by shortcut" do
32
32
  R18n.set('en', DIR)
33
33
  R18n.get.should be_a(R18n::I18n)
@@ -39,15 +39,15 @@ describe R18n do
39
39
  i18n = R18n::I18n.new('en')
40
40
  R18n.thread_set(i18n)
41
41
  R18n.get.should == i18n
42
-
42
+
43
43
  R18n.reset
44
44
  R18n.get.should be_nil
45
45
  end
46
-
46
+
47
47
  it "should reset I18n objects and cache" do
48
48
  R18n.cache[:a] = 1
49
49
  R18n.thread_set(R18n::I18n.new('en'))
50
-
50
+
51
51
  R18n.reset
52
52
  R18n.get.should be_nil
53
53
  R18n.cache.should be_empty
@@ -56,10 +56,10 @@ describe R18n do
56
56
  it "should thread_set setter to I18n" do
57
57
  i18n = R18n::I18n.new('en')
58
58
  R18n.thread_set(i18n)
59
-
59
+
60
60
  i18n = R18n::I18n.new('ru')
61
61
  R18n.thread_set { i18n }
62
-
62
+
63
63
  R18n.get.should == i18n
64
64
  end
65
65
 
@@ -68,49 +68,49 @@ describe R18n do
68
68
  R18n.default_loader = Class
69
69
  R18n.default_loader.should == Class
70
70
  end
71
-
71
+
72
72
  it "should store cache" do
73
73
  R18n.cache.should be_a(Hash)
74
-
74
+
75
75
  R18n.cache = { 1 => 2 }
76
76
  R18n.cache.should == { 1 => 2 }
77
-
77
+
78
78
  R18n.cache.clear
79
79
  R18n.cache.should == {}
80
80
  end
81
-
81
+
82
82
  it "should convert Time to Date" do
83
83
  R18n::Utils.to_date(Time.now).should == Date.today
84
84
  end
85
-
85
+
86
86
  it "should map hash" do
87
87
  R18n::Utils.hash_map({'a' => 1, 'b' => 2}) { |k, v| [k + 'a', v + 1] }.
88
88
  should == { 'aa' => 2, 'ba' => 3 }
89
89
  end
90
-
90
+
91
91
  it "should merge hash recursively" do
92
92
  a = { :a => 1,
93
93
  :b => {:ba => 1, :bb => 1},
94
94
  :c => 1 }
95
95
  b = { :b => {:bb => 2, :bc => 2},
96
96
  :c => 2 }
97
-
97
+
98
98
  R18n::Utils.deep_merge!(a, b)
99
99
  a.should == { :a => 1,
100
100
  :b => { :ba => 1, :bb => 2, :bc => 2 },
101
101
  :c => 2 }
102
102
  end
103
-
103
+
104
104
  it "should have l and t methods" do
105
105
  R18n.set('en')
106
106
  t.yes.should == 'Yes'
107
107
  l(Time.at(0).utc).should == '01/01/1970 00:00'
108
108
  end
109
-
109
+
110
110
  it "should have helpers mixin" do
111
111
  obj = R18n::I18n.new 'en'
112
112
  R18n.set(obj)
113
-
113
+
114
114
  r18n.should == obj
115
115
  i18n.should == obj
116
116
  t.yes.should == 'Yes'
data/spec/spec_helper.rb CHANGED
@@ -22,17 +22,17 @@ gem 'RedCloth'
22
22
  class CounterLoader
23
23
  attr_reader :available
24
24
  attr_reader :loaded
25
-
25
+
26
26
  def initialize(*available)
27
27
  @available = available.map { |i| R18n::Locale.load(i) }
28
28
  @loaded = 0
29
29
  end
30
-
30
+
31
31
  def load(locale)
32
32
  @loaded += 1
33
33
  {}
34
34
  end
35
-
35
+
36
36
  def hash
37
37
  @available.hash
38
38
  end
@@ -7,19 +7,19 @@ describe R18n::Translated do
7
7
  @user_class = Class.new do
8
8
  include R18n::Translated
9
9
  attr_accessor :name_ru, :name_en
10
-
10
+
11
11
  def name_ru?; end
12
12
  def name_ru!; end
13
13
  end
14
14
  R18n.set('en')
15
15
  end
16
-
16
+
17
17
  it "should save methods map" do
18
18
  @user_class.translation :name, :methods => { :ru => :name_ru }
19
19
  @user_class.unlocalized_getters(:name).should == { 'ru' => 'name_ru' }
20
20
  @user_class.unlocalized_setters(:name).should == { 'ru' => 'name_ru=' }
21
21
  end
22
-
22
+
23
23
  it "should autodetect methods map" do
24
24
  @user_class.translation :name
25
25
  @user_class.unlocalized_getters(:name).should == {
@@ -27,21 +27,21 @@ describe R18n::Translated do
27
27
  @user_class.unlocalized_setters(:name).should == {
28
28
  'en' => 'name_en=', 'ru' => 'name_ru=' }
29
29
  end
30
-
30
+
31
31
  it "should translate methods" do
32
32
  @user_class.translation :name
33
33
  user = @user_class.new
34
-
34
+
35
35
  user.name.should_not be_translated
36
36
  user.name = 'John'
37
37
  user.name.should == 'John'
38
-
38
+
39
39
  R18n.set('ru')
40
40
  user.name.should == 'John'
41
41
  user.name = 'Джон'
42
42
  user.name.should == 'Джон'
43
43
  end
44
-
44
+
45
45
  it "should return TranslatedString" do
46
46
  class ::SomeTranslatedClass
47
47
  include R18n::Translated
@@ -49,40 +49,40 @@ describe R18n::Translated do
49
49
  translation :name
50
50
  end
51
51
  obj = ::SomeTranslatedClass.new
52
-
52
+
53
53
  obj.name.should be_a(R18n::TranslatedString)
54
54
  obj.name.locale.should == R18n::Locale.load('en')
55
55
  obj.name.path.should == 'SomeTranslatedClass#name'
56
56
  end
57
-
57
+
58
58
  it "should search translation by locales priority" do
59
59
  @user_class.translation :name
60
60
  user = @user_class.new
61
-
61
+
62
62
  R18n.set(['no-LC', 'ru', 'en'])
63
63
  user.name_ru = 'Иван'
64
64
  user.name.locale.should == R18n::Locale.load('ru')
65
65
  end
66
-
66
+
67
67
  it "should use default locale" do
68
68
  @user_class.translation :name
69
69
  user = @user_class.new
70
-
70
+
71
71
  R18n.set('no-LC')
72
72
  user.name_en = 'John'
73
73
  user.name.locale.should == R18n::Locale.load('en')
74
74
  end
75
-
75
+
76
76
  it "should use filters" do
77
77
  @user_class.class_eval do
78
78
  def age_en; {1 => '%1 year', 'n' => '%1 years'} end
79
79
  translation :age, :type => 'pl', :no_params => true
80
80
  end
81
81
  user = @user_class.new
82
-
82
+
83
83
  user.age(20).should == '20 years'
84
84
  end
85
-
85
+
86
86
  it "should send params to method if user want it" do
87
87
  @user_class.class_eval do
88
88
  def no_params_en(*params) params.join(' '); end
@@ -90,24 +90,24 @@ describe R18n::Translated do
90
90
  translations [:no_params, {:no_params => true}], :params
91
91
  end
92
92
  user = @user_class.new
93
-
93
+
94
94
  user.no_params(1, 2).should == ''
95
95
  user.params(1, 2).should == '1 2'
96
96
  end
97
-
97
+
98
98
  it "should return Untranslated when can't find translation" do
99
99
  class ::SomeUntranslatedClass
100
100
  include R18n::Translated
101
-
101
+
102
102
  translation :no
103
103
  end
104
104
  obj = ::SomeUntranslatedClass.new
105
-
105
+
106
106
  obj.no.should be_a(R18n::Untranslated)
107
107
  obj.no.translated_path.should == 'SomeUntranslatedClass#'
108
108
  obj.no.untranslated_path.should == 'no'
109
109
  end
110
-
110
+
111
111
  it "should translate virtual methods" do
112
112
  @virtual_class = Class.new do
113
113
  include R18n::Translated
@@ -117,10 +117,10 @@ describe R18n::Translated do
117
117
  end
118
118
  end
119
119
  virtual = @virtual_class.new
120
-
120
+
121
121
  virtual.no_method.should == 'no_method_en'
122
122
  end
123
-
123
+
124
124
  it "should return original type of result" do
125
125
  @user_class.class_eval do
126
126
  translation :name
@@ -129,8 +129,8 @@ describe R18n::Translated do
129
129
  end
130
130
  end
131
131
  user = @user_class.new
132
-
132
+
133
133
  user.name.should == :ivan
134
134
  end
135
-
135
+
136
136
  end