r18n-core 0.2.3 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.rdoc +157 -35
  2. data/base/cs.yml +34 -0
  3. data/base/de.yml +24 -0
  4. data/base/en.yml +24 -0
  5. data/base/fr.yml +24 -0
  6. data/base/pl.yml +24 -0
  7. data/base/ru.yml +30 -0
  8. data/lib/r18n-core/filters.rb +245 -0
  9. data/lib/r18n-core/i18n.rb +57 -40
  10. data/lib/r18n-core/locale.rb +116 -19
  11. data/lib/r18n-core/translated.rb +186 -0
  12. data/lib/r18n-core/translation.rb +33 -73
  13. data/lib/r18n-core/unsupported_locale.rb +27 -9
  14. data/lib/r18n-core/utils.rb +49 -0
  15. data/lib/r18n-core/version.rb +1 -1
  16. data/lib/r18n-core.rb +3 -15
  17. data/locales/cs.rb +23 -0
  18. data/locales/cs.yml +26 -0
  19. data/locales/de.yml +3 -8
  20. data/locales/en-us.rb +8 -0
  21. data/locales/en-us.yml +9 -0
  22. data/locales/en.rb +26 -0
  23. data/locales/en.yml +3 -8
  24. data/locales/eo.yml +3 -8
  25. data/locales/fr.rb +14 -0
  26. data/locales/fr.yml +3 -8
  27. data/locales/kk.yml +3 -8
  28. data/locales/pl.yml +4 -11
  29. data/locales/ru.yml +3 -8
  30. data/spec/filters_spec.rb +167 -0
  31. data/spec/i18n_spec.rb +61 -16
  32. data/spec/locale_spec.rb +46 -19
  33. data/spec/locales/cs_spec.rb +22 -0
  34. data/spec/locales/en-us_spec.rb +14 -0
  35. data/spec/locales/en_spec.rb +14 -0
  36. data/spec/locales/fr_spec.rb +10 -0
  37. data/spec/locales/pl_spec.rb +17 -17
  38. data/spec/locales/ru_spec.rb +2 -2
  39. data/spec/r18n_spec.rb +7 -3
  40. data/spec/spec_helper.rb +2 -0
  41. data/spec/translated_spec.rb +108 -0
  42. data/spec/translation_spec.rb +24 -56
  43. data/spec/translations/extension/{no_TR.yml → no-tr.yml} +0 -0
  44. data/spec/translations/general/en.yml +15 -2
  45. data/spec/translations/general/{no_LC.yml → no-lc.yml} +0 -0
  46. metadata +46 -31
  47. data/locales/en_US.yml +0 -14
@@ -2,46 +2,44 @@
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
5
9
 
6
10
  it "should return all available translations" do
7
- R18n::Translation.available(DIR).sort.should == ['en', 'no_LC', 'ru']
8
- R18n::Translation.available([TWO, DIR]).sort.should == [
9
- 'en', 'fr', 'no_LC', 'ru']
11
+ R18n::Translation.available(DIR).should =~ ['en', 'no-lc', 'ru']
12
+ R18n::Translation.available([TWO, DIR]).should =~ [
13
+ 'en', 'fr', 'no-lc', 'ru']
10
14
  end
11
15
 
12
16
  it "should load translations" do
13
- translation = R18n::Translation.load('en', DIR)
17
+ translation = R18n::Translation.load([@en], DIR)
14
18
  translation.one.should == 'One'
15
19
  translation['one'].should == 'One'
16
20
  end
17
21
 
18
22
  it "should find in subtranslations" do
19
- translation = R18n::Translation.load(['ru', 'en'], DIR)
23
+ translation = R18n::Translation.load([@ru, @en], DIR)
20
24
  translation.one.should == 'Один'
21
25
  translation.two.should == 'Two'
22
26
  end
23
27
 
24
28
  it "should return nil if translation isn't found" do
25
- translation = R18n::Translation.load('en', DIR)
29
+ translation = R18n::Translation.load([@en], DIR)
26
30
  translation.not.exists.should be_nil
27
31
  translation['not']['exists'].should be_nil
28
32
  end
29
33
 
30
- it "should can use params in translation" do
31
- translation = R18n::Translation.load('en', DIR)
32
- translation.params(1, 2).should == 'Is 1 between 1 and 2?'
33
- translation['params', 1, 2].should == 'Is 1 between 1 and 2?'
34
- end
35
-
36
34
  it "should load use hierarchical translations" do
37
- translation = R18n::Translation.load(['ru', 'en'], DIR)
35
+ translation = R18n::Translation.load([@ru, @en], DIR)
38
36
  translation.in.another.level.should == 'Иерархический'
39
37
  translation['in']['another']['level'].should == 'Иерархический'
40
38
  translation.only.english.should == 'Only in English'
41
39
  end
42
40
 
43
41
  it "should save path for translation" do
44
- translation = R18n::Translation.load('en', DIR)
42
+ translation = R18n::Translation.load([@en], DIR)
45
43
 
46
44
  translation.in.another.level.path.should == 'in.another.level'
47
45
 
@@ -54,21 +52,21 @@ describe R18n::Translation do
54
52
  end
55
53
 
56
54
  it "should return string with locale info" do
57
- translation = R18n::Translation.load(['no_LC', 'en'], DIR)
58
- translation.one.locale.should == R18n::UnsupportedLocale.new('no_LC')
55
+ translation = R18n::Translation.load([R18n::Locale.load('no-LC'), @en], DIR)
56
+ translation.one.locale.should == R18n::UnsupportedLocale.new('no-LC')
59
57
  translation.two.locale.should == R18n::Locale.load('en')
60
58
  end
61
59
 
62
60
  it "should load translations from several dirs" do
63
- translation = R18n::Translation.load(['no_LC', 'en'], [TWO, DIR])
64
- translation.in.two.should == 'Two'
65
- translation.in.another.level.should == 'Hierarchical'
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'
66
64
  end
67
65
 
68
66
  it "should use extension translations" do
69
67
  R18n::Translation.extension_translations << EXT
70
68
 
71
- translation = R18n::Translation.load('en', DIR)
69
+ translation = R18n::Translation.load([@en], DIR)
72
70
  translation.ext.should == 'Extension'
73
71
  translation.one.should == 'One'
74
72
  end
@@ -76,46 +74,16 @@ describe R18n::Translation do
76
74
  it "shouldn't use extension without app translations with same locale" do
77
75
  R18n::Translation.extension_translations << EXT
78
76
 
79
- translation = R18n::Translation.load(['no_TR', 'en'], DIR)
77
+ translation = R18n::Translation.load([R18n::Locale.load('no-TR'), @en], DIR)
80
78
  translation.ext.should == 'Extension'
81
79
  end
82
-
83
- it "should call proc in translation" do
84
- translation = R18n::Translation.load('en', DIR)
85
- translation.sum(2, 3).should == 5
86
- end
87
80
 
88
- it "shouldn't call proc if it isn't secure" do
89
- translation = R18n::Translation.load('en', DIR)
90
- R18n::Translation.call_proc = false
91
- R18n::Translation.call_proc.should be_false
92
- translation.sum(2, 3).should == '|x, y| x + y'
93
- R18n::Translation.call_proc = true
94
- end
95
-
96
- it "should pluralize translation" do
97
- translation = R18n::Translation.load('en', DIR)
98
- translation.comments(0, 'article').should == 'no comments for article'
99
- translation.comments(1, 'article').should == 'one comment for article'
100
- translation.comments(5, 'article').should == '5 comments for article'
101
-
102
- translation.files(0).should == '0 files'
103
- translation.files(-5.5).should == '−5.5 files'
104
- translation.files(5000).should == '5,000 files'
105
- end
106
-
107
- it "should return unknown YAML type" do
108
- translation = R18n::Translation.load('en', DIR)
81
+ it "should ignore case on loading" do
82
+ translation = R18n::Translation.load([R18n::Locale.load('no-lc')], [DIR])
83
+ translation.one.should == 'ONE'
109
84
 
110
- translation.my_type.class.should == YAML::PrivateType
111
- translation.my_type.type_id.should == 'special_type'
112
- translation.my_type.value.should == {'attr' => 'value'}
113
- end
114
-
115
- it "should pluralize translation without locale" do
116
- translation = R18n::Translation.load('no_LC', DIR)
117
- translation.entries(1).should == 'ONE'
118
- translation.entries(5).should == 'N'
85
+ translation = R18n::Translation.load([R18n::Locale.load('no-LC')], [DIR])
86
+ translation.one.should == 'ONE'
119
87
  end
120
88
 
121
89
  end
@@ -21,5 +21,18 @@ files: !!pl
21
21
  1: 1 file
22
22
  n: %1 files
23
23
 
24
- my_type: !!special_type
25
- attr: value
24
+ my_filter: !!my value
25
+ my_tree_filter: !!my
26
+ name: value
27
+
28
+ unknown_filter: !!unknown value
29
+
30
+ html: !!escape
31
+ <script>true && false</script>
32
+ greater: 1 < 2 is true
33
+ no_escape: !!html
34
+ <b>Warning</b>
35
+
36
+ markdown: !!markdown **Hi!**
37
+
38
+ textile: !!textile _Hi!_
File without changes
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.2.3
4
+ version: "0.3"
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-07-22 00:00:00 +08:00
12
+ date: 2009-09-26 00:00:00 +04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: R18n is a i18n tool to translate your Ruby application. It can format numbers and time to the rules of the user locale, has translation for common words, storage translation in YAML format with pluralization and procedures and has special support for countries with two official languages.
16
+ description: R18n is a i18n tool to translate your Ruby application. It can format numbers and time to the rules of the user locale, has translation for common words, storage translation in YAML format with pluralization, procedures and user filters and has special support for countries with two official languages.
17
17
  email: andrey@sitnik.ru
18
18
  executables: []
19
19
 
@@ -23,32 +23,41 @@ extra_rdoc_files:
23
23
  - README.rdoc
24
24
  - LICENSE
25
25
  files:
26
- - base/de.yml
27
- - base/en.yml
26
+ - base/ru.yml
27
+ - base/kk.yml
28
28
  - base/fr.yml
29
+ - base/en.yml
29
30
  - base/pl.yml
30
- - base/ru.yml
31
+ - base/de.yml
32
+ - base/cs.yml
31
33
  - base/eo.yml
32
- - base/kk.yml
33
- - lib/r18n-core.rb
34
34
  - lib/r18n-core
35
- - lib/r18n-core/unsupported_locale.rb
36
- - lib/r18n-core/translation.rb
37
35
  - lib/r18n-core/untranslated.rb
36
+ - lib/r18n-core/translated.rb
38
37
  - lib/r18n-core/i18n.rb
39
- - lib/r18n-core/translated_string.rb
40
38
  - lib/r18n-core/locale.rb
39
+ - lib/r18n-core/utils.rb
41
40
  - lib/r18n-core/version.rb
42
- - locales/de.yml
43
- - locales/en.yml
41
+ - lib/r18n-core/translation.rb
42
+ - lib/r18n-core/translated_string.rb
43
+ - lib/r18n-core/filters.rb
44
+ - lib/r18n-core/unsupported_locale.rb
45
+ - lib/r18n-core.rb
44
46
  - locales/ru.rb
45
- - locales/pl.rb
47
+ - locales/ru.yml
48
+ - locales/en.rb
49
+ - locales/kk.yml
46
50
  - locales/fr.yml
51
+ - locales/en.yml
47
52
  - locales/pl.yml
48
- - locales/ru.yml
49
- - locales/en_US.yml
53
+ - locales/de.yml
54
+ - locales/cs.yml
55
+ - locales/fr.rb
56
+ - locales/cs.rb
50
57
  - locales/eo.yml
51
- - locales/kk.yml
58
+ - locales/en-us.rb
59
+ - locales/en-us.yml
60
+ - locales/pl.rb
52
61
  - LICENSE
53
62
  - README.rdoc
54
63
  has_rdoc: true
@@ -78,22 +87,28 @@ signing_key:
78
87
  specification_version: 2
79
88
  summary: I18n tool to translate your Ruby application.
80
89
  test_files:
81
- - spec/translations
82
- - spec/translations/extension
83
- - spec/translations/extension/no_TR.yml
84
- - spec/translations/extension/en.yml
85
- - spec/translations/general
86
- - spec/translations/general/en.yml
87
- - spec/translations/general/no_LC.yml
88
- - spec/translations/general/ru.yml
89
- - spec/translations/two
90
- - spec/translations/two/en.yml
91
- - spec/translations/two/fr.yml
92
90
  - spec/locales
91
+ - spec/locales/en_spec.rb
93
92
  - spec/locales/pl_spec.rb
93
+ - spec/locales/cs_spec.rb
94
+ - spec/locales/en-us_spec.rb
95
+ - spec/locales/fr_spec.rb
94
96
  - spec/locales/ru_spec.rb
95
- - spec/locale_spec.rb
96
- - spec/i18n_spec.rb
97
- - spec/r18n_spec.rb
98
97
  - spec/spec_helper.rb
98
+ - spec/translations
99
+ - spec/translations/two
100
+ - spec/translations/two/fr.yml
101
+ - spec/translations/two/en.yml
102
+ - spec/translations/general
103
+ - spec/translations/general/ru.yml
104
+ - spec/translations/general/en.yml
105
+ - spec/translations/general/no-lc.yml
106
+ - spec/translations/extension
107
+ - spec/translations/extension/no-tr.yml
108
+ - spec/translations/extension/en.yml
99
109
  - spec/translation_spec.rb
110
+ - spec/r18n_spec.rb
111
+ - spec/filters_spec.rb
112
+ - spec/locale_spec.rb
113
+ - spec/i18n_spec.rb
114
+ - spec/translated_spec.rb
data/locales/en_US.yml DELETED
@@ -1,14 +0,0 @@
1
- include: en
2
-
3
- code: en_US
4
- title: English (US)
5
- sublocales: [en]
6
-
7
- formats:
8
- time: "%H:%M"
9
- date: "%m/%d/%Y"
10
- short_date: "%b %d"
11
- long_date: "%B %d, %Y"
12
- datetime: "%a %b %d %H:%M:%S %Z %Y"
13
- short_datetime: "%b %d %H:%M"
14
- long_datetime: "%B %d, %Y %H:%M"