r18n-core 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/locales/en.yml ADDED
@@ -0,0 +1,34 @@
1
+ title: English
2
+ code: en
3
+ sublocales: []
4
+ direction: ltr
5
+
6
+ pluralization: "n == 0 ? 0 : n == 1 ? 1 : 'n'"
7
+
8
+ week:
9
+ start: sunday
10
+ days: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
11
+ abbrs: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
12
+
13
+ months:
14
+ names: [January, February, March, April, May, June, July, August, September, October, November, December]
15
+ abbrs: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
16
+ standalone: [January, February, March, April, May, June, July, August, September, October, November, December]
17
+
18
+ time:
19
+ am: AM
20
+ pm: PM
21
+
22
+ formats:
23
+ time: "%H:%M"
24
+ date: "%m/%d/%Y"
25
+ short_date: "%b %d"
26
+ long_date: "%B %d, %Y"
27
+ datetime: "%a %b %d %H:%M:%S %Z %Y"
28
+ short_datetime: "%d %b %H:%M"
29
+ long_datetime: "%B %d, %Y %H:%M"
30
+
31
+ numbers:
32
+ separation: classic
33
+ decimal_separator: "."
34
+ group_delimiter: ","
data/locales/en_US.yml ADDED
@@ -0,0 +1,5 @@
1
+ include: en
2
+
3
+ code: en_US
4
+ title: English (US)
5
+ sublocales: [en]
data/locales/ru.yml ADDED
@@ -0,0 +1,34 @@
1
+ title: Русский
2
+ code: ru
3
+ sublocales: [en]
4
+ direction: ltr
5
+
6
+ pluralization: "n==0 ? 0 : n%10==1 && n%100!=11 ? 1 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 'n'"
7
+
8
+ week:
9
+ start: monday
10
+ days: [Воскресенье, Понедельник, Вторник, Среда, Четверг, Пятница, Суббота]
11
+ abbrs: [Вск, Пнд, Втр, Срд, Чтв, Птн, Сбт]
12
+
13
+ months:
14
+ names: [января, февраля, марта, апреля, мая, июня, июля, августа, сентября, октября, ноября, декабря]
15
+ abbrs: [янв, фев, мар, апр, май, июн, июл, авг, сен, окт, ноя, дек]
16
+ standalone: [Январь, Февраль, Март, Апрель, Май, Июнь, Июль, Август, Сентябрь, Октябрь, Ноябрь, Декабрь]
17
+
18
+ time:
19
+ am: " утра"
20
+ pm: " вечера"
21
+
22
+ formats:
23
+ time: "%H:%M"
24
+ date: "%d.%m.%Y"
25
+ short_date: "%d %b"
26
+ long_date: "%d %B %Y"
27
+ datetime: "%a, %d %b %Y, %H:%M:%S %Z"
28
+ short_datetime: "%d %b, %H:%M"
29
+ long_datetime: "%d %B %Y, %H:%M"
30
+
31
+ numbers:
32
+ separation: classic
33
+ decimal_separator: ","
34
+ group_delimiter: " "
data/spec/i18n_spec.rb ADDED
@@ -0,0 +1,78 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe R18n::I18n do
4
+ DIR = Pathname(__FILE__).dirname + 'translations/general'
5
+
6
+ it "should parse HTTP_ACCEPT_LANGUAGE" do
7
+ R18n::I18n.parse_http(nil).should == []
8
+ R18n::I18n.parse_http('').should == []
9
+ R18n::I18n.parse_http('ru,en;q=0.9').should == ['ru', 'en']
10
+ R18n::I18n.parse_http('ru;q=0.8,en;q=0.9').should == ['en', 'ru']
11
+ end
12
+
13
+ it "should has default locale" do
14
+ R18n::I18n.default = 'ru'
15
+ R18n::I18n.default.should == 'ru'
16
+ end
17
+
18
+ it "should load locales" do
19
+ i18n = R18n::I18n.new('en', DIR)
20
+ i18n.locales.should == [R18n::Locale.new('en')]
21
+
22
+ i18n = R18n::I18n.new(['ru', 'no_LC'], DIR)
23
+ i18n.locales.should == [R18n::Locale.new('ru'), 'no_LC']
24
+ end
25
+
26
+ it "should return translations dir" do
27
+ i18n = R18n::I18n.new('en', DIR)
28
+ i18n.translations_dir.should == DIR.expand_path.to_s
29
+ end
30
+
31
+ it "should load translations" do
32
+ i18n = R18n::I18n.new(['ru', 'en'], DIR)
33
+ i18n.one.should == 'Один'
34
+ i18n.only.english.should == 'Only in English'
35
+ end
36
+
37
+ it "should load default translation" do
38
+ R18n::I18n.default = 'en'
39
+
40
+ i18n = R18n::I18n.new('no_LC', DIR)
41
+ i18n.one.should == 'ONE'
42
+ i18n.two.should == 'Two'
43
+ end
44
+
45
+ it "should load sublocales for first locale" do
46
+ R18n::I18n.default = 'no_TR'
47
+
48
+ i18n = R18n::I18n.new('ru', DIR)
49
+ i18n.one.should == 'Один'
50
+ i18n.two.should == 'Two'
51
+ end
52
+
53
+ it "should return available translations" do
54
+ i18n = R18n::I18n.new('en', DIR)
55
+ i18n.translations.should == {
56
+ 'no_LC' => 'no_LC', 'ru' => 'Русский', 'en' => 'English'}
57
+ end
58
+
59
+ it "should return first locale with locale file" do
60
+ i18n = R18n::I18n.new(['no_LC', 'ru', 'en'], DIR)
61
+ i18n.locale.should == R18n::Locale.new('ru')
62
+ end
63
+
64
+ it "should localize objects" do
65
+ i18n = R18n::I18n.new('ru', DIR)
66
+
67
+ i18n.l(-123456789).should == '−123 456 789'
68
+ i18n.l(-12345.67).should == '−12 345,67'
69
+
70
+ time = Time.at(0).utc
71
+ i18n.l(time).should == 'Чтв, 01 янв 1970, 00:00:00 GMT'
72
+ i18n.l(time, :time).should == '00:00'
73
+ i18n.l(time, '%A').should == 'Четверг'
74
+
75
+ i18n.l(Date.new(0)).should == '01.01.0000'
76
+ end
77
+
78
+ end
@@ -0,0 +1,89 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe R18n::Locale do
4
+
5
+ it "should check is locale exists" do
6
+ R18n::Locale.exists?('ru').should be_true
7
+ R18n::Locale.exists?('no_LC').should be_false
8
+ end
9
+
10
+ it "should load locale" do
11
+ locale = R18n::Locale.new 'ru'
12
+ locale['code'].should == 'ru'
13
+ locale['title'].should == 'Русский'
14
+ end
15
+
16
+ it "should include locale by +include+ option" do
17
+ en_US = R18n::Locale.new 'en_US'
18
+ en = R18n::Locale.new 'en'
19
+ en_US['title'].should == 'English (US)'
20
+ en['title'].should == 'English'
21
+ en_US['week'].should == en['week']
22
+ end
23
+
24
+ it "should raise error if locale isn't exists" do
25
+ lambda {
26
+ R18n::Locale.new 'no_LC'
27
+ }.should raise_error
28
+ end
29
+
30
+ it "should be equal to another locale with same code" do
31
+ ru = R18n::Locale.new 'ru'
32
+ en = R18n::Locale.new 'en'
33
+ another_en = R18n::Locale.new 'en'
34
+ en.should_not == ru
35
+ en.should == another_en
36
+ end
37
+
38
+ it "should print human readable representation" do
39
+ R18n::Locale.new('ru').inspect.should == 'Locale ru (Русский)'
40
+ end
41
+
42
+ it "should return all available locales" do
43
+ R18n::Locale.available.sort.should == ['en', 'en_US', 'ru']
44
+ end
45
+
46
+ it "should return pluralization type by elements count" do
47
+ locale = R18n::Locale.new 'en'
48
+ locale.pluralize(0).should == 0
49
+ locale.pluralize(1).should == 1
50
+ locale.pluralize(5).should == 'n'
51
+ end
52
+
53
+ it "should has default pluralization to translation without locale file" do
54
+ R18n::Locale.default_pluralize(0).should == 0
55
+ R18n::Locale.default_pluralize(1).should == 1
56
+ R18n::Locale.default_pluralize(5).should == 'n'
57
+ end
58
+
59
+ it "should format number in local traditions" do
60
+ locale = R18n::Locale.new 'en'
61
+ locale.format_number(-123456789).should == "−123,456,789"
62
+
63
+ locale = FakeIndianLocale.new # While indian locale isn’t exists
64
+ locale.format_number(-123456789).should == "−12,34,56,789"
65
+ end
66
+
67
+ it "should format float in local traditions" do
68
+ locale = R18n::Locale.new 'en'
69
+ locale.format_float(-12345.67).should == "−12,345.67"
70
+ end
71
+
72
+ it "should translate month, week days and am/pm names in strftime" do
73
+ locale = R18n::Locale.new('ru')
74
+ time = Time.at(0).utc
75
+
76
+ locale.strftime(time, '%a %A').should == 'Чтв Четверг'
77
+ locale.strftime(time, '%b %B').should == 'янв января'
78
+ locale.strftime(time, '%H:%M%p').should == '00:00 утра'
79
+
80
+ locale.strftime(time, :datetime).should == 'Чтв, 01 янв 1970, 00:00:00 GMT'
81
+ end
82
+
83
+ it "should delete slashed from locale for security reasons" do
84
+ lambda {
85
+ R18n::Locale.new('../spec/translations/general/en')
86
+ }.should raise_error
87
+ end
88
+
89
+ end
data/spec/r18n_spec.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe R18n do
4
+
5
+ it "should set I18n for current thread" do
6
+ i18n = R18n::I18n.new('en', '')
7
+ R18n.set(i18n)
8
+ R18n.get.should == i18n
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), '../lib/r18n-core')
2
+
3
+ class FakeIndianLocale < R18n::Locale
4
+ def initialize
5
+ super('en')
6
+ @locale['numbers'] = {
7
+ 'separation' => 'indian',
8
+ 'decimal_separator' => '.',
9
+ 'group_delimiter' => ','
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe R18n::Translation do
4
+ DIR = Pathname(__FILE__).dirname + 'translations/general'
5
+ EXT = Pathname(__FILE__).dirname + 'translations/extension'
6
+
7
+ it "should return all available translations" do
8
+ R18n::Translation.available(DIR).sort.should == ['en', 'no_LC', 'ru']
9
+ end
10
+
11
+ it "should load translations" do
12
+ translation = R18n::Translation.load('en', DIR)
13
+ translation.one.should == 'One'
14
+ translation['one'].should == 'One'
15
+ end
16
+
17
+ it "should find in subtranslations" do
18
+ translation = R18n::Translation.load(['ru', 'en'], DIR)
19
+ translation.one.should == 'Один'
20
+ translation.two.should == 'Two'
21
+ end
22
+
23
+ it "should return nil if translation isn't found" do
24
+ translation = R18n::Translation.load('en', DIR)
25
+ translation.without_translation.should be_nil
26
+ end
27
+
28
+ it "should can use params in translation" do
29
+ translation = R18n::Translation.load('en', DIR)
30
+ translation.params(1, 2).should == 'Is 1 between 1 and 2?'
31
+ translation['params', 1, 2].should == 'Is 1 between 1 and 2?'
32
+ end
33
+
34
+ it "should load use hierarchical translations" do
35
+ translation = R18n::Translation.load(['ru', 'en'], DIR)
36
+ translation.in.another.should == 'Иерархический'
37
+ translation['in']['another'].should == 'Иерархический'
38
+ translation.only.english.should == 'Only in English'
39
+ end
40
+
41
+ it "should return string with locale info" do
42
+ translation = R18n::Translation.load(['no_LC', 'en'], DIR)
43
+ translation.one.locale.should == 'no_LC'
44
+ translation.two.locale.should == R18n::Locale.new('en')
45
+ end
46
+
47
+ it "should use extension translations" do
48
+ R18n::Translation.extension_translations << EXT
49
+
50
+ translation = R18n::Translation.load('en', DIR)
51
+ translation.ext.should == 'Extension'
52
+ translation.one.should == 'One'
53
+ end
54
+
55
+ it "shouldn't use extension without app translations with same locale" do
56
+ R18n::Translation.extension_translations << EXT
57
+
58
+ translation = R18n::Translation.load(['no_TR', 'en'], DIR)
59
+ translation.ext.should == 'Extension'
60
+ end
61
+
62
+ it "should call proc in translation" do
63
+ translation = R18n::Translation.load('en', DIR)
64
+ translation.sum(2, 3).should == 5
65
+ end
66
+
67
+ it "should pluralize translation" do
68
+ translation = R18n::Translation.load('en', DIR)
69
+ translation.comments(0, 'article').should == 'no comments for article'
70
+ translation.comments(1, 'article').should == 'one comment for article'
71
+ translation.comments(5, 'article').should == '5 comments for article'
72
+
73
+ translation.files(0).should == '0 files'
74
+ end
75
+
76
+ it "should return unknown YAML type" do
77
+ translation = R18n::Translation.load('en', DIR)
78
+
79
+ translation.my_type.class.should == YAML::PrivateType
80
+ translation.my_type.type_id.should == 'special_type'
81
+ translation.my_type.value.should == {'attr' => 'value'}
82
+ end
83
+
84
+ it "should pluralize translation without locale" do
85
+ translation = R18n::Translation.load('no_LC', DIR)
86
+ translation.entries(1).should == 'ONE'
87
+ translation.entries(5).should == 'N'
88
+ end
89
+
90
+ end
@@ -0,0 +1,2 @@
1
+ one: No one
2
+ ext: Extension
@@ -0,0 +1 @@
1
+ ext: NO
@@ -0,0 +1,24 @@
1
+ one: One
2
+ two: Two
3
+
4
+ params: Is %1 between %1 and %2?
5
+
6
+ in:
7
+ another: Hierarchical
8
+
9
+ only:
10
+ english: Only in English
11
+
12
+ sum: !!proc |x, y| x + y
13
+
14
+ comments: !!pl
15
+ 0: no comments for %2
16
+ 1: one comment for %2
17
+ n: %1 comments for %2
18
+
19
+ files: !!pl
20
+ 1: 1 file
21
+ n: %1 files
22
+
23
+ my_type: !!special_type
24
+ attr: value
@@ -0,0 +1,6 @@
1
+ one: ONE
2
+
3
+ entries: !!pl
4
+ 1: ONE
5
+ 2: TWO
6
+ n: N
@@ -0,0 +1,4 @@
1
+ one: Один
2
+
3
+ in:
4
+ another: Иерархический
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r18n-core
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Andrey "A.I." Sitnik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-18 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: R18n is a i18n tool to translate your Ruby application. It can localize your application, has translation for commons words, storage translation in rich YAML format with pluralization and procedures and has sublocales list for each supported locale.
17
+ email: andrey@sitnik.ru
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - base/ru.yml
27
+ - base/en.yml
28
+ - lib/r18n-core.rb
29
+ - lib/r18n-core
30
+ - lib/r18n-core/translation.rb
31
+ - lib/r18n-core/translated_string.rb
32
+ - lib/r18n-core/locale.rb
33
+ - lib/r18n-core/i18n.rb
34
+ - locales/en_US.yml
35
+ - locales/ru.yml
36
+ - locales/en.yml
37
+ - LICENSE
38
+ - Rakefile
39
+ - README.rdoc
40
+ has_rdoc: true
41
+ homepage: http://r18n.rubyforge.org/
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project: r18n-core
62
+ rubygems_version: 1.3.1
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: I18n tool to translate your Ruby application.
66
+ test_files:
67
+ - spec/spec_helper.rb
68
+ - spec/translation_spec.rb
69
+ - spec/i18n_spec.rb
70
+ - spec/translations
71
+ - spec/translations/general
72
+ - spec/translations/general/ru.yml
73
+ - spec/translations/general/en.yml
74
+ - spec/translations/general/no_LC.yml
75
+ - spec/translations/extension
76
+ - spec/translations/extension/no_TR.yml
77
+ - spec/translations/extension/en.yml
78
+ - spec/r18n_spec.rb
79
+ - spec/locale_spec.rb