r18n-core 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/ChangeLog +11 -0
  2. data/README.rdoc +225 -53
  3. data/lib/r18n-core/filters.rb +34 -34
  4. data/lib/r18n-core/i18n.rb +110 -46
  5. data/lib/r18n-core/locale.rb +109 -103
  6. data/lib/r18n-core/translated.rb +9 -4
  7. data/lib/r18n-core/translated_string.rb +10 -0
  8. data/lib/r18n-core/translation.rb +55 -99
  9. data/lib/r18n-core/unsupported_locale.rb +1 -13
  10. data/lib/r18n-core/untranslated.rb +18 -16
  11. data/lib/r18n-core/utils.rb +0 -12
  12. data/lib/r18n-core/version.rb +1 -1
  13. data/lib/r18n-core/yaml_loader.rb +67 -0
  14. data/lib/r18n-core.rb +25 -3
  15. data/locales/cs.rb +30 -16
  16. data/locales/de.rb +21 -0
  17. data/locales/en-us.rb +9 -4
  18. data/locales/en.rb +35 -20
  19. data/locales/eo.rb +20 -0
  20. data/locales/es.rb +20 -0
  21. data/locales/fr.rb +24 -9
  22. data/locales/it.rb +21 -9
  23. data/locales/kk.rb +26 -0
  24. data/locales/pl.rb +30 -18
  25. data/locales/pt-br.rb +24 -0
  26. data/locales/ru.rb +30 -12
  27. data/locales/zh.rb +19 -0
  28. data/spec/filters_spec.rb +24 -7
  29. data/spec/i18n_spec.rb +137 -50
  30. data/spec/locale_spec.rb +91 -53
  31. data/spec/locales/cs_spec.rb +9 -7
  32. data/spec/locales/pl_spec.rb +8 -9
  33. data/spec/locales/ru_spec.rb +9 -9
  34. data/spec/r18n_spec.rb +32 -13
  35. data/spec/spec_helper.rb +28 -4
  36. data/spec/translated_spec.rb +1 -1
  37. data/spec/translation_spec.rb +33 -67
  38. data/spec/translations/two/en.yml +0 -1
  39. data/spec/yaml_loader_spec.rb +33 -0
  40. metadata +11 -16
  41. data/locales/cs.yml +0 -26
  42. data/locales/de.yml +0 -26
  43. data/locales/en-us.yml +0 -10
  44. data/locales/en.yml +0 -26
  45. data/locales/eo.yml +0 -26
  46. data/locales/es.yml +0 -26
  47. data/locales/fr.yml +0 -26
  48. data/locales/it.yml +0 -26
  49. data/locales/kk.yml +0 -26
  50. data/locales/pl.yml +0 -26
  51. data/locales/pt-br.yml +0 -26
  52. data/locales/ru.yml +0 -26
  53. data/locales/zh.yml +0 -26
data/spec/locale_spec.rb CHANGED
@@ -2,100 +2,138 @@
2
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
 
4
4
  describe R18n::Locale do
5
+ before :all do
6
+ @ru = R18n::Locale.load('ru')
7
+ @en = R18n::Locale.load('en')
8
+ end
5
9
 
10
+ it "should return all available locales" do
11
+ R18n::Locale.available.class.should == Array
12
+ R18n::Locale.available.should_not be_empty
13
+ end
14
+
6
15
  it "should check is locale exists" do
7
16
  R18n::Locale.exists?('ru').should be_true
8
17
  R18n::Locale.exists?('no-LC').should be_false
9
18
  end
19
+
20
+ it "should set locale properties" do
21
+ locale_class = Class.new(R18n::Locale) do
22
+ set :one => 1
23
+ set :two => 2
24
+ end
25
+ locale = locale_class.new
26
+ locale.one.should == 1
27
+ locale.two.should == 2
28
+ end
10
29
 
11
30
  it "should load locale" do
12
- locale = R18n::Locale.load('ru')
13
- locale.code.should == 'ru'
14
- locale.title.should == 'Русский'
15
- locale.ltr?.should be_true
31
+ @ru.class.should == R18n::Locales::Ru
32
+ @ru.code.should == 'ru'
33
+ @ru.title.should == 'Русский'
16
34
  end
17
35
 
18
36
  it "should load locale by Symbol" do
19
37
  R18n::Locale.load(:ru).should == R18n::Locale.load('ru')
20
38
  end
21
-
22
- it "should use locale's class" do
23
- ru = R18n::Locale.load('ru')
24
- ru.class.should == R18n::Locales::Ru
25
-
26
- eo = R18n::Locale.load('eo')
27
- eo.class.should == R18n::Locale
28
- end
29
-
30
- it "should include locale by +include+ option" do
31
- enUS = R18n::Locale.load('en-US')
32
- en = R18n::Locale.load('en')
33
- enUS.title.should == 'English (US)'
34
- en.title.should == 'English'
35
- enUS['week'].should == en['week']
36
- end
37
39
 
38
40
  it "should be equal to another locale with same code" do
39
- ru = R18n::Locale.load('ru')
40
- en = R18n::Locale.load('en')
41
- another_en = R18n::Locale.load('en')
42
- en.should_not == ru
43
- en.should == another_en
41
+ @en.should_not == @ru
42
+ @en.should == R18n::Locale.load('en')
44
43
  end
45
44
 
46
45
  it "should print human readable representation" do
47
- R18n::Locale.load('ru').inspect.should == 'Locale ru (Русский)'
48
- end
49
-
50
- it "should return all available locales" do
51
- R18n::Locale.available.class.should == Array
52
- R18n::Locale.available.should_not be_empty
46
+ @ru.inspect.should == 'Locale ru (Русский)'
53
47
  end
54
48
 
55
49
  it "should return pluralization type by elements count" do
56
- locale = R18n::Locale.load('en')
57
- locale.pluralize(0).should == 0
58
- locale.pluralize(1).should == 1
59
- locale.pluralize(5).should == 'n'
50
+ @en.pluralize(0).should == 0
51
+ @en.pluralize(1).should == 1
52
+ @en.pluralize(5).should == 'n'
60
53
  end
61
54
 
62
55
  it "should use UnsupportedLocale if locale file isn't exists" do
63
- supported = R18n::Locale.load('en')
64
- supported.should be_supported
56
+ @en.should be_supported
65
57
 
66
58
  unsupported = R18n::Locale.load('no-LC')
67
59
  unsupported.should_not be_supported
68
60
  unsupported.should be_a(R18n::UnsupportedLocale)
69
61
 
70
- unsupported.code.should == 'no-LC'
71
- unsupported.title.should == 'no-LC'
62
+ unsupported.code.downcase.should == 'no-lc'
63
+ unsupported.title.downcase.should == 'no-lc'
72
64
  unsupported.ltr?.should be_true
73
65
 
74
- unsupported['code'].should == 'no-LC'
75
- unsupported['title'].should == 'no-LC'
76
- unsupported['direction'].should == 'ltr'
77
-
78
66
  unsupported.pluralize(5).should == 'n'
79
- unsupported.inspect.should == 'Unsupported locale no-LC'
67
+ unsupported.inspect.downcase.should == 'unsupported locale no-lc'
80
68
  end
81
69
 
82
70
  it "should format number in local traditions" do
83
- locale = R18n::Locale.load('en')
84
- locale.format_integer(-123456789).should == "−123,456,789"
71
+ @en.localize(-123456789).should == "−123,456,789"
85
72
  end
86
73
 
87
74
  it "should format float in local traditions" do
88
- locale = R18n::Locale.load('en')
89
- locale.format_float(-12345.67).should == "−12,345.67"
75
+ @en.localize(-12345.67).should == "−12,345.67"
90
76
  end
91
77
 
92
78
  it "should translate month, week days and am/pm names in strftime" do
93
- locale = R18n::Locale.load('ru')
79
+ i18n = R18n::I18n.new 'ru'
94
80
  time = Time.at(0).utc
95
81
 
96
- locale.strftime(time, '%a %A').should == 'Чтв Четверг'
97
- locale.strftime(time, '%b %B').should == 'янв января'
98
- locale.strftime(time, '%H:%M%p').should == '00:00 утра'
82
+ @ru.localize(time, '%a %A').should == 'Чтв Четверг'
83
+ @ru.localize(time, '%b %B').should == 'янв января'
84
+ @ru.localize(time, '%H:%M%p').should == '00:00 утра'
85
+ end
86
+
87
+ it "should localize date for human" do
88
+ i18n = R18n::I18n.new('ru')
89
+
90
+ @ru.localize(Date.today + 2, :human, i18n).should == 'через 2 дня'
91
+ @ru.localize(Date.today + 1, :human, i18n).should == 'завтра'
92
+ @ru.localize(Date.today, :human, i18n).should == 'сегодня'
93
+ @ru.localize(Date.today - 1, :human, i18n).should == 'вчера'
94
+ @ru.localize(Date.today - 3, :human, i18n).should == '3 дня назад'
95
+
96
+ y2000 = Date.parse('2000-01-08')
97
+ @ru.localize(y2000, :human, i18n, y2000 + 8 ).should == ' 8 января'
98
+ @ru.localize(y2000, :human, i18n, y2000 - 365).should == ' 8 января 2000'
99
+ end
100
+
101
+ it "should localize times for human" do
102
+ minute = 60
103
+ hour = 60 * minute
104
+ day = 24 * hour
105
+ zero = Time.at(0).utc
106
+ params = [:human, R18n::I18n.new('ru'), zero]
107
+
108
+ @ru.localize( zero + 7 * day, *params).should == ' 8 января 00:00'
109
+ @ru.localize( zero + 50 * hour, *params).should == 'через 2 дня 02:00'
110
+ @ru.localize( zero + 25 * hour, *params).should == 'завтра 01:00'
111
+ @ru.localize( zero + 70 * minute, *params).should == 'через 1 час'
112
+ @ru.localize( zero + 38 * minute, *params).should == 'через 38 минут'
113
+ @ru.localize( zero + 5, *params).should == 'сейчас'
114
+ @ru.localize( zero - 15, *params).should == 'сейчас'
115
+ @ru.localize( zero - minute, *params).should == '1 минуту назад'
116
+ @ru.localize( zero - 2 * hour, *params).should == '2 часа назад'
117
+ @ru.localize( zero - 13 * hour, *params).should == 'вчера 11:00'
118
+ @ru.localize( zero - 50 * hour, *params).should == '3 дня назад 22:00'
119
+ @ru.localize( zero - 9 * day, *params).should == '23 декабря 1969 00:00'
120
+ end
121
+
122
+ it "should use standard formatter by default" do
123
+ @ru.localize(Time.at(0).utc).should == '01.01.1970 00:00'
124
+ end
125
+
126
+ it "shouldn't localize time without i18n object" do
127
+ @ru.localize(Time.at(0)).should_not == Time.at(0).to_s
128
+ @ru.localize(Time.at(0), :full).should_not == Time.at(0).to_s
129
+
130
+ @ru.localize(Time.at(0), :human).should == Time.at(0).to_s
131
+ end
132
+
133
+ it "should raise error on unknown formatter" do
134
+ lambda {
135
+ @ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
136
+ }.should raise_error(ArgumentError, /formatter/)
99
137
  end
100
138
 
101
139
  it "should delete slashed from locale for security reasons" do
@@ -113,7 +151,7 @@ describe R18n::Locale do
113
151
  upcase = R18n::Locale.load('no-LC')
114
152
  downcase = R18n::Locale.load('no-lc')
115
153
  upcase.should == downcase
116
- upcase.code.should == 'no-LC'
154
+ upcase.code.should == 'no-lc'
117
155
  downcase.code.should == 'no-lc'
118
156
  end
119
157
 
@@ -3,18 +3,20 @@ require File.join(File.dirname(__FILE__), '..', '..', 'locales', 'cs')
3
3
 
4
4
  describe R18n::Locales::Cs do
5
5
  it "should use Czech pluralization" do
6
- ru = R18n::Locale.load 'cs'
6
+ ru = R18n::Locale.load('cs')
7
7
  ru.pluralize(0).should == 0
8
8
  ru.pluralize(1).should == 1
9
+
9
10
  ru.pluralize(2).should == 2
10
11
  ru.pluralize(3).should == 2
11
12
  ru.pluralize(4).should == 2
12
- ru.pluralize(5).should == 'n'
13
- ru.pluralize(21).should == 'n'
14
- ru.pluralize(11).should == 'n'
15
- ru.pluralize(12).should == 'n'
16
- ru.pluralize(22).should == 'n'
17
- ru.pluralize(57).should == 'n'
13
+
14
+ ru.pluralize(5).should == 'n'
15
+ ru.pluralize(21).should == 'n'
16
+ ru.pluralize(11).should == 'n'
17
+ ru.pluralize(12).should == 'n'
18
+ ru.pluralize(22).should == 'n'
19
+ ru.pluralize(57).should == 'n'
18
20
  ru.pluralize(101).should == 'n'
19
21
  ru.pluralize(102).should == 'n'
20
22
  ru.pluralize(111).should == 'n'
@@ -5,19 +5,18 @@ describe R18n::Locales::Pl do
5
5
  it "should use Polish pluralization" do
6
6
  pl = R18n::Locale.load 'pl'
7
7
  pl.pluralize(0).should == 0
8
-
9
8
  pl.pluralize(1).should == 1
10
9
 
11
- pl.pluralize(2).should == 2
12
- pl.pluralize(4).should == 2
13
- pl.pluralize(22).should == 2
10
+ pl.pluralize(2).should == 2
11
+ pl.pluralize(4).should == 2
12
+ pl.pluralize(22).should == 2
14
13
  pl.pluralize(102).should == 2
15
14
 
16
- pl.pluralize(5).should == 'n'
17
- pl.pluralize(11).should == 'n'
18
- pl.pluralize(12).should == 'n'
19
- pl.pluralize(21).should == 'n'
20
- pl.pluralize(57).should == 'n'
15
+ pl.pluralize(5).should == 'n'
16
+ pl.pluralize(11).should == 'n'
17
+ pl.pluralize(12).should == 'n'
18
+ pl.pluralize(21).should == 'n'
19
+ pl.pluralize(57).should == 'n'
21
20
  pl.pluralize(101).should == 'n'
22
21
  pl.pluralize(111).should == 'n'
23
22
  pl.pluralize(112).should == 'n'
@@ -6,19 +6,19 @@ describe R18n::Locales::Ru do
6
6
  ru = R18n::Locale.load 'ru'
7
7
  ru.pluralize(0).should == 0
8
8
 
9
- ru.pluralize(1).should == 1
10
- ru.pluralize(21).should == 1
9
+ ru.pluralize(1).should == 1
10
+ ru.pluralize(21).should == 1
11
11
  ru.pluralize(101).should == 1
12
12
 
13
- ru.pluralize(2).should == 2
14
- ru.pluralize(4).should == 2
15
- ru.pluralize(22).should == 2
13
+ ru.pluralize(2).should == 2
14
+ ru.pluralize(4).should == 2
15
+ ru.pluralize(22).should == 2
16
16
  ru.pluralize(102).should == 2
17
17
 
18
- ru.pluralize(5).should == 'n'
19
- ru.pluralize(11).should == 'n'
20
- ru.pluralize(12).should == 'n'
21
- ru.pluralize(57).should == 'n'
18
+ ru.pluralize(5).should == 'n'
19
+ ru.pluralize(11).should == 'n'
20
+ ru.pluralize(12).should == 'n'
21
+ ru.pluralize(57).should == 'n'
22
22
  ru.pluralize(111).should == 'n'
23
23
  end
24
24
  end
data/spec/r18n_spec.rb CHANGED
@@ -2,24 +2,43 @@
2
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
 
4
4
  describe R18n do
5
+ after do
6
+ R18n.default_loader = R18n::Loader::YAML
7
+ end
5
8
 
6
- it "should set I18n for current thread" do
7
- i18n = R18n::I18n.new('en', '')
9
+ it "should store I18n" do
10
+ i18n = R18n::I18n.new('en')
8
11
  R18n.set(i18n)
9
12
  R18n.get.should == i18n
13
+
14
+ R18n.set(nil)
15
+ R18n.get.should be_nil
10
16
  end
11
-
12
- it "should merge hash recursively" do
13
- a = { :a => 1,
14
- :b => {:ba => 1, :bb => 1},
15
- :c => 1 }
16
- b = { :b => {:bb => 2, :bc => 2},
17
- :c => 2 }
17
+
18
+ it "should set setter to I18n" do
19
+ i18n = R18n::I18n.new('en')
20
+ R18n.set(i18n)
21
+
22
+ i18n = R18n::I18n.new('ru')
23
+ R18n.set { i18n }
24
+
25
+ R18n.get.should == i18n
26
+ end
27
+
28
+ it "should store default loader class" do
29
+ R18n.default_loader.should == R18n::Loader::YAML
30
+ R18n.default_loader = Class
31
+ R18n.default_loader.should == Class
32
+ end
33
+
34
+ it "should store cache" do
35
+ R18n.cache.should be_a(Hash)
36
+
37
+ R18n.cache = { 1 => 2 }
38
+ R18n.cache.should == { 1 => 2 }
18
39
 
19
- R18n::Utils.deep_merge! a, b
20
- a.should == { :a => 1,
21
- :b => { :ba => 1, :bb => 2, :bc => 2 },
22
- :c => 2 }
40
+ R18n.cache.clear
41
+ R18n.cache.should == {}
23
42
  end
24
43
 
25
44
  it "should convert Time to Date" do
data/spec/spec_helper.rb CHANGED
@@ -2,8 +2,32 @@
2
2
  require 'rubygems'
3
3
  require 'pp'
4
4
 
5
- require File.join(File.dirname(__FILE__), '../lib/r18n-core')
5
+ dir = Pathname(__FILE__).dirname
6
6
 
7
- DIR = Pathname(__FILE__).dirname + 'translations/general' unless defined? DIR
8
- TWO = Pathname(__FILE__).dirname + 'translations/two' unless defined? TWO
9
- EXT = Pathname(__FILE__).dirname + 'translations/extension' unless defined? EXT
7
+ require dir + '../lib/r18n-core'
8
+
9
+ DIR = dir + 'translations/general' unless defined? DIR
10
+ TWO = dir + 'translations/two' unless defined? TWO
11
+ EXT = R18n::Loader::YAML.new(dir + 'translations/extension') unless defined? EXT
12
+
13
+ gem 'maruku'
14
+ gem 'RedCloth'
15
+
16
+ class CounterLoader
17
+ attr_reader :available
18
+ attr_reader :loaded
19
+
20
+ def initialize(*available)
21
+ @available = available.map { |i| R18n::Locale.load(i) }
22
+ @loaded = 0
23
+ end
24
+
25
+ def load(locale)
26
+ @loaded += 1
27
+ {}
28
+ end
29
+
30
+ def hash
31
+ @available.hash
32
+ end
33
+ end
@@ -29,7 +29,7 @@ describe R18n::Translated do
29
29
  @user_class.translation :name
30
30
  user = @user_class.new
31
31
 
32
- user.name.should be_nil
32
+ user.name.should_not be_translated
33
33
  user.name = 'John'
34
34
  user.name.should == 'John'
35
35
 
@@ -2,88 +2,54 @@
2
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
 
4
4
  describe R18n::Translation do
5
- before :all do
6
- @en = R18n::Locale.load('en')
7
- @ru = R18n::Locale.load('ru')
8
- end
9
-
10
- it "should return all available translations" do
11
- R18n::Translation.available(DIR).should =~ ['en', 'no-lc', 'ru']
12
- R18n::Translation.available([TWO, DIR]).should =~ [
13
- 'en', 'fr', 'no-lc', 'ru']
14
- end
15
-
16
- it "should load translations" do
17
- translation = R18n::Translation.load([@en], DIR)
18
- translation.one.should == 'One'
19
- translation['one'].should == 'One'
20
- end
21
-
22
- it "should find in subtranslations" do
23
- translation = R18n::Translation.load([@ru, @en], DIR)
24
- translation.one.should == 'Один'
25
- translation.two.should == 'Two'
26
- end
27
-
28
- it "should return nil if translation isn't found" do
29
- translation = R18n::Translation.load([@en], DIR)
30
- translation.not.exists.should be_nil
31
- translation['not']['exists'].should be_nil
5
+
6
+ it "should return unstranslated string if translation isn't found" do
7
+ i18n = R18n::I18n.new('en', DIR)
8
+ i18n.not.exists.should be_a(R18n::Untranslated)
9
+ i18n.not.exists.should_not be_translated
10
+ (i18n.not.exists | 'default').should == 'default'
11
+
12
+ (i18n.in | 'default').should == 'default'
13
+
14
+ i18n.one.should be_translated
15
+ (i18n.one | 'default').should == 'One'
32
16
  end
33
17
 
34
18
  it "should load use hierarchical translations" do
35
- translation = R18n::Translation.load([@ru, @en], DIR)
36
- translation.in.another.level.should == 'Иерархический'
37
- translation['in']['another']['level'].should == 'Иерархический'
38
- translation.only.english.should == 'Only in English'
19
+ i18n = R18n::I18n.new(['ru', 'en'], DIR)
20
+ i18n.in.another.level.should == 'Иерархический'
21
+ i18n[:in][:another][:level].should == 'Иерархический'
22
+ i18n['in']['another']['level'].should == 'Иерархический'
23
+ i18n.only.english.should == 'Only in English'
39
24
  end
40
25
 
41
26
  it "should save path for translation" do
42
- translation = R18n::Translation.load([@en], DIR)
27
+ i18n = R18n::I18n.new('en', DIR)
43
28
 
44
- translation.in.another.level.path.should == 'in.another.level'
29
+ i18n.in.another.level.path.should == 'in.another.level'
45
30
 
46
- translation.in.another.not.exists.path.should == 'in.another.not.exists'
47
- translation.in.another.not.exists.untranslated_path.should == 'not.exists'
48
- translation.in.another.not.exists.translated_path.should == 'in.another.'
31
+ i18n.in.another.not.exists.path.should == 'in.another.not.exists'
32
+ i18n.in.another.not.exists.untranslated_path.should == 'not.exists'
33
+ i18n.in.another.not.exists.translated_path.should == 'in.another.'
49
34
 
50
- translation.not.untranslated_path.should == 'not'
51
- translation.not.translated_path.should == ''
35
+ i18n.not.untranslated_path.should == 'not'
36
+ i18n.not.translated_path.should == ''
52
37
  end
53
38
 
54
39
  it "should return string with locale info" do
55
- translation = R18n::Translation.load([R18n::Locale.load('no-LC'), @en], DIR)
56
- translation.one.locale.should == R18n::UnsupportedLocale.new('no-LC')
57
- translation.two.locale.should == R18n::Locale.load('en')
58
- end
59
-
60
- it "should load translations from several dirs" do
61
- tr = R18n::Translation.load([R18n::Locale.load('no-LC'), @en], [TWO, DIR])
62
- tr.in.two.should == 'Two'
63
- tr.in.another.level.should == 'Hierarchical'
64
- end
65
-
66
- it "should use extension translations" do
67
- R18n::Translation.extension_translations << EXT
68
-
69
- translation = R18n::Translation.load([@en], DIR)
70
- translation.ext.should == 'Extension'
71
- translation.one.should == 'One'
72
- end
73
-
74
- it "shouldn't use extension without app translations with same locale" do
75
- R18n::Translation.extension_translations << EXT
76
-
77
- translation = R18n::Translation.load([R18n::Locale.load('no-TR'), @en], DIR)
78
- translation.ext.should == 'Extension'
40
+ i18n = R18n::I18n.new(['no-LC', 'en'], DIR)
41
+ i18n.one.locale.should == R18n::UnsupportedLocale.new('no-LC')
42
+ i18n.two.locale.should == R18n::Locale.load('en')
79
43
  end
80
44
 
81
- it "should ignore case on loading" do
82
- translation = R18n::Translation.load([R18n::Locale.load('no-lc')], [DIR])
83
- translation.one.should == 'ONE'
45
+ it "should filter typed data" do
46
+ en = R18n::Locale.load('en')
47
+ translation = R18n::Translation.new(en, '', en, {
48
+ 'count' => R18n::Typed.new('pl', { 1 => 'one', 'n' => 'many' })
49
+ })
84
50
 
85
- translation = R18n::Translation.load([R18n::Locale.load('no-LC')], [DIR])
86
- translation.one.should == 'ONE'
51
+ translation.count(1).should == 'one'
52
+ translation.count(5).should == 'many'
87
53
  end
88
54
 
89
55
  end
@@ -1,3 +1,2 @@
1
1
  in:
2
- another: Wrong
3
2
  two: Two
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'spec_helper')
3
+
4
+ describe R18n::Loader::YAML do
5
+ before do
6
+ @loader = R18n::Loader::YAML.new(DIR)
7
+ end
8
+
9
+ it "should return dir with translations" do
10
+ @loader.dir.should == DIR.expand_path.to_s
11
+ end
12
+
13
+ it "should be equal to another YAML loader with same dir" do
14
+ @loader.should == R18n::Loader::YAML.new(DIR)
15
+ @loader.should_not == Class.new(R18n::Loader::YAML).new(DIR)
16
+ end
17
+
18
+ it "should return all available translations" do
19
+ @loader.available.should =~ [R18n::Locale.load('ru'),
20
+ R18n::Locale.load('en'),
21
+ R18n::Locale.load('no-lc')]
22
+ end
23
+
24
+ it "should load translation" do
25
+ @loader.load(R18n::Locale.load('ru')).should == {
26
+ 'one' => 'Один', 'in' => {'another' => {'level' => 'Иерархический'}} }
27
+ end
28
+
29
+ it "should return hash by dir" do
30
+ @loader.hash.should == R18n::Loader::YAML.new(DIR).hash
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r18n-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "A.I." Sitnik
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-29 00:00:00 +03:00
12
+ date: 2010-01-03 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: " R18n is a i18n tool to translate your Ruby application.\n It can format numbers and time to the rules of the user locale,\n has translation for common words, storage translation in YAML format with\n pluralization, procedures and user filters and has special support for\n countries with two official languages.\n"
16
+ description: " R18n is a i18n tool to translate your Ruby application.\n It has nice Ruby-style syntax, filters, flexible locales, custom loaders,\n translation support for any classes, time and number localization, several\n user language support, agnostic core package with out-of-box support for\n Rails, Sinatra, Merb and desktop applications.\n"
17
17
  email: andrey@sitnik.ru
18
18
  executables: []
19
19
 
@@ -39,6 +39,7 @@ files:
39
39
  - lib/r18n-core.rb
40
40
  - lib/r18n-core/filters.rb
41
41
  - lib/r18n-core/untranslated.rb
42
+ - lib/r18n-core/yaml_loader.rb
42
43
  - lib/r18n-core/version.rb
43
44
  - lib/r18n-core/utils.rb
44
45
  - lib/r18n-core/translated_string.rb
@@ -49,24 +50,17 @@ files:
49
50
  - lib/r18n-core/i18n.rb
50
51
  - locales/it.rb
51
52
  - locales/pl.rb
52
- - locales/kk.yml
53
- - locales/it.yml
54
53
  - locales/en.rb
55
- - locales/ru.yml
56
- - locales/pl.yml
57
54
  - locales/cs.rb
58
- - locales/de.yml
59
- - locales/eo.yml
55
+ - locales/es.rb
56
+ - locales/kk.rb
60
57
  - locales/en-us.rb
61
- - locales/en-us.yml
62
- - locales/pt-br.yml
63
- - locales/cs.yml
64
- - locales/es.yml
65
- - locales/fr.yml
58
+ - locales/zh.rb
66
59
  - locales/fr.rb
67
60
  - locales/ru.rb
68
- - locales/en.yml
69
- - locales/zh.yml
61
+ - locales/pt-br.rb
62
+ - locales/de.rb
63
+ - locales/eo.rb
70
64
  - LICENSE
71
65
  - ChangeLog
72
66
  - README.rdoc
@@ -109,6 +103,7 @@ test_files:
109
103
  - spec/locales/en-us_spec.rb
110
104
  - spec/spec_helper.rb
111
105
  - spec/r18n_spec.rb
106
+ - spec/yaml_loader_spec.rb
112
107
  - spec/translation_spec.rb
113
108
  - spec/translations/general/ru.yml
114
109
  - spec/translations/general/en.yml
data/locales/cs.yml DELETED
@@ -1,26 +0,0 @@
1
- title: Český
2
- code: cs
3
- sublocales: [cz, sk]
4
- direction: ltr
5
-
6
- week:
7
- start: monday
8
- days: [Neděle, Pondělí, Úterý, Středa, Čtvrtek, Pátek, Sobota]
9
- abbrs: [Ne, Po, Út, St, Čt, Pá, So]
10
-
11
- months:
12
- names: [Ledna, Února, Března, Dubna, Května, Června, Července, Srpna, Září, Října, Listopadu, Prosince]
13
- abbrs: [Led, Úno, Bře, Dub, Kvě, Čer, Čvc, Srp, Zář, Říj, Lis, Pro]
14
- standalone: [Leden, Únor, Březen, Duben, Květen, Červen, Červenec, Srpen, Září, Říjen, Listopad, Prosinec]
15
-
16
- time:
17
- am: dop.
18
- pm: odp.
19
- time: " %H:%M"
20
- date: "%d.%m.%Y"
21
- full: "%e %B"
22
- year: "_ %Y"
23
-
24
- numbers:
25
- decimal_separator: ","
26
- group_delimiter: " "