synergy_russian 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG +113 -0
  2. data/LICENSE +20 -0
  3. data/README.textile +272 -0
  4. data/Rakefile +55 -0
  5. data/TODO +10 -0
  6. data/init.rb +3 -0
  7. data/lib/russian.rb +118 -0
  8. data/lib/russian/action_view_ext/helpers/date_helper.rb +112 -0
  9. data/lib/russian/active_record_ext/custom_error_message.rb +163 -0
  10. data/lib/russian/active_support_ext/parameterize.rb +31 -0
  11. data/lib/russian/backend/advanced.rb +134 -0
  12. data/lib/russian/locale/actionview.yml +162 -0
  13. data/lib/russian/locale/activerecord.yml +95 -0
  14. data/lib/russian/locale/activesupport.yml +16 -0
  15. data/lib/russian/locale/datetime.yml +49 -0
  16. data/lib/russian/locale/pluralize.rb +25 -0
  17. data/lib/russian/transliteration.rb +72 -0
  18. data/lib/vendor/i18n/MIT-LICENSE +20 -0
  19. data/lib/vendor/i18n/README.textile +20 -0
  20. data/lib/vendor/i18n/Rakefile +5 -0
  21. data/lib/vendor/i18n/i18n.gemspec +27 -0
  22. data/lib/vendor/i18n/lib/i18n.rb +199 -0
  23. data/lib/vendor/i18n/lib/i18n/backend/simple.rb +214 -0
  24. data/lib/vendor/i18n/lib/i18n/exceptions.rb +53 -0
  25. data/lib/vendor/i18n/test/all.rb +5 -0
  26. data/lib/vendor/i18n/test/i18n_exceptions_test.rb +100 -0
  27. data/lib/vendor/i18n/test/i18n_test.rb +125 -0
  28. data/lib/vendor/i18n/test/locale/en.rb +1 -0
  29. data/lib/vendor/i18n/test/locale/en.yml +3 -0
  30. data/lib/vendor/i18n/test/simple_backend_test.rb +568 -0
  31. data/spec/fixtures/en.yml +4 -0
  32. data/spec/fixtures/ru.yml +4 -0
  33. data/spec/i18n/locale/datetime_spec.rb +99 -0
  34. data/spec/i18n/locale/pluralization_spec.rb +28 -0
  35. data/spec/locale_spec.rb +129 -0
  36. data/spec/russian_spec.rb +136 -0
  37. data/spec/spec_helper.rb +7 -0
  38. data/spec/transliteration_spec.rb +51 -0
  39. metadata +102 -0
@@ -0,0 +1,4 @@
1
+ # Fixture dummy translation
2
+ # Need this to test if we preserve translation data that is already loaded when switching backends
3
+ en:
4
+ foo: "bar"
@@ -0,0 +1,4 @@
1
+ ru:
2
+ date:
3
+ formats:
4
+ default: "override"
@@ -0,0 +1,99 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe I18n, "Russian Date/Time localization" do
6
+ before(:all) do
7
+ Russian.init_i18n
8
+ @date = Date.parse("1985-12-01")
9
+ @time = Time.local(1985, 12, 01, 16, 05)
10
+ end
11
+
12
+ describe "with date formats" do
13
+ it "should use default format" do
14
+ l(@date).should == "01.12.1985"
15
+ end
16
+
17
+ it "should use short format" do
18
+ l(@date, :format => :short).should == "01 дек."
19
+ end
20
+
21
+ it "should use long format" do
22
+ l(@date, :format => :long).should == "01 декабря 1985"
23
+ end
24
+ end
25
+
26
+ describe "with date day names" do
27
+ it "should use day names" do
28
+ l(@date, :format => "%d %B (%A)").should == "01 декабря (воскресенье)"
29
+ l(@date, :format => "%d %B %Y года было %A").should == "01 декабря 1985 года было воскресенье"
30
+ end
31
+
32
+ it "should use standalone day names" do
33
+ l(@date, :format => "%A").should == "Воскресенье"
34
+ l(@date, :format => "%A, %d %B").should == "Воскресенье, 01 декабря"
35
+ end
36
+
37
+ it "should use abbreviated day names" do
38
+ l(@date, :format => "%a").should == "Вс"
39
+ l(@date, :format => "%a, %d %b %Y").should == "Вс, 01 дек. 1985"
40
+ end
41
+ end
42
+
43
+ describe "with month names" do
44
+ it "should use month names" do
45
+ l(@date, :format => "%d %B").should == "01 декабря"
46
+ l(@date, :format => "%e %B %Y").should == " 1 декабря 1985"
47
+ l(@date, :format => "<b>%d</b> %B").should == "<b>01</b> декабря"
48
+ l(@date, :format => "<strong>%e</strong> %B %Y").should == "<strong> 1</strong> декабря 1985"
49
+ l(@date, :format => "А было тогда %eе число %B %Y").should == "А было тогда 1е число декабря 1985"
50
+ end
51
+
52
+ it "should use standalone month names" do
53
+ l(@date, :format => "%B").should == "Декабрь"
54
+ l(@date, :format => "%B %Y").should == "Декабрь 1985"
55
+ end
56
+
57
+ it "should use abbreviated month names" do
58
+ @date = Date.parse("1985-03-01")
59
+ l(@date, :format => "%d %b").should == "01 марта"
60
+ l(@date, :format => "%e %b %Y").should == " 1 марта 1985"
61
+ l(@date, :format => "<b>%d</b> %b").should == "<b>01</b> марта"
62
+ l(@date, :format => "<strong>%e</strong> %b %Y").should == "<strong> 1</strong> марта 1985"
63
+ end
64
+
65
+ it "should use standalone abbreviated month names" do
66
+ @date = Date.parse("1985-03-01")
67
+ l(@date, :format => "%b").should == "март"
68
+ l(@date, :format => "%b %Y").should == "март 1985"
69
+ end
70
+ end
71
+
72
+ it "should define default date components order: day, month, year" do
73
+ I18n.backend.translate(Russian.locale, :"date.order").should == [:day, :month, :year]
74
+ end
75
+
76
+ describe "with time formats" do
77
+ it "should use default format" do
78
+ l(@time).should =~ /^Вс, 01 дек. 1985, 16:05:00/
79
+ end
80
+
81
+ it "should use short format" do
82
+ l(@time, :format => :short).should == "01 дек., 16:05"
83
+ end
84
+
85
+ it "should use long format" do
86
+ l(@time, :format => :long).should == "01 декабря 1985, 16:05"
87
+ end
88
+
89
+ it "should define am and pm" do
90
+ I18n.backend.translate(Russian.locale, :"time.am").should_not be_nil
91
+ I18n.backend.translate(Russian.locale, :"time.pm").should_not be_nil
92
+ end
93
+ end
94
+
95
+ protected
96
+ def l(object, options = {})
97
+ I18n.l(object, options.merge( { :locale => Russian.locale }))
98
+ end
99
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe I18n, "Russian pluralization" do
6
+ before(:each) do
7
+ @hash = {}
8
+ %w(one few many other).each do |key|
9
+ @hash[key.to_sym] = key
10
+ end
11
+ @backend = I18n.backend
12
+ end
13
+
14
+ it "should pluralize correctly" do
15
+ @backend.send(:pluralize, :'ru', @hash, 1).should == 'one'
16
+ @backend.send(:pluralize, :'ru', @hash, 2).should == 'few'
17
+ @backend.send(:pluralize, :'ru', @hash, 3).should == 'few'
18
+ @backend.send(:pluralize, :'ru', @hash, 5).should == 'many'
19
+ @backend.send(:pluralize, :'ru', @hash, 10).should == 'many'
20
+ @backend.send(:pluralize, :'ru', @hash, 11).should == 'many'
21
+ @backend.send(:pluralize, :'ru', @hash, 21).should == 'one'
22
+ @backend.send(:pluralize, :'ru', @hash, 29).should == 'many'
23
+ @backend.send(:pluralize, :'ru', @hash, 131).should == 'one'
24
+ @backend.send(:pluralize, :'ru', @hash, 1.31).should == 'other'
25
+ @backend.send(:pluralize, :'ru', @hash, 2.31).should == 'other'
26
+ @backend.send(:pluralize, :'ru', @hash, 3.31).should == 'other'
27
+ end
28
+ end
@@ -0,0 +1,129 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe Russian, "loading locales" do
6
+ before(:all) do
7
+ Russian.init_i18n
8
+ end
9
+
10
+ %w(
11
+ date.formats.default
12
+ date.formats.short
13
+ date.formats.long
14
+ date.day_names
15
+ date.standalone_day_names
16
+ date.abbr_day_names
17
+ date.month_names
18
+ date.standalone_month_names
19
+ date.abbr_month_names
20
+ date.standalone_abbr_month_names
21
+ date.order
22
+
23
+ time.formats.default
24
+ time.formats.short
25
+ time.formats.long
26
+ time.am
27
+ time.pm
28
+ ).each do |key|
29
+ it "should define '#{key}' in datetime translations" do
30
+ lookup(key).should_not be_nil
31
+ end
32
+ end
33
+
34
+ it "should load pluralization rules" do
35
+ lookup(:"pluralize").should_not be_nil
36
+ lookup(:"pluralize").is_a?(Proc).should be_true
37
+ end
38
+
39
+ %w(
40
+ number.format.separator
41
+ number.format.delimiter
42
+ number.format.precision
43
+ number.currency.format.format
44
+ number.currency.format.unit
45
+ number.currency.format.separator
46
+ number.currency.format.delimiter
47
+ number.currency.format.precision
48
+ number.percentage.format.delimiter
49
+ number.precision.format.delimiter
50
+ number.human.format.delimiter
51
+ number.human.format.precision
52
+ number.human.storage_units
53
+
54
+ datetime.distance_in_words.half_a_minute
55
+ datetime.distance_in_words.less_than_x_seconds
56
+ datetime.distance_in_words.x_seconds
57
+ datetime.distance_in_words.less_than_x_minutes
58
+ datetime.distance_in_words.x_minutes
59
+ datetime.distance_in_words.about_x_hours
60
+ datetime.distance_in_words.x_days
61
+ datetime.distance_in_words.about_x_months
62
+ datetime.distance_in_words.x_months
63
+ datetime.distance_in_words.about_x_years
64
+ datetime.distance_in_words.over_x_years
65
+ datetime.distance_in_words.almost_x_years
66
+
67
+ datetime.prompts.year
68
+ datetime.prompts.month
69
+ datetime.prompts.day
70
+ datetime.prompts.hour
71
+ datetime.prompts.minute
72
+ datetime.prompts.second
73
+
74
+ activerecord.errors.template.header
75
+ activerecord.errors.template.body
76
+
77
+ support.select.prompt
78
+ ).each do |key|
79
+ it "should define '#{key}' in actionview translations" do
80
+ lookup(key).should_not be_nil
81
+ end
82
+ end
83
+
84
+ %w(
85
+ activerecord.errors.messages.inclusion
86
+ activerecord.errors.messages.exclusion
87
+ activerecord.errors.messages.invalid
88
+ activerecord.errors.messages.confirmation
89
+ activerecord.errors.messages.accepted
90
+ activerecord.errors.messages.empty
91
+ activerecord.errors.messages.blank
92
+ activerecord.errors.messages.too_long
93
+ activerecord.errors.messages.too_short
94
+ activerecord.errors.messages.wrong_length
95
+ activerecord.errors.messages.taken
96
+ activerecord.errors.messages.not_a_number
97
+ activerecord.errors.messages.greater_than
98
+ activerecord.errors.messages.greater_than_or_equal_to
99
+ activerecord.errors.messages.equal_to
100
+ activerecord.errors.messages.less_than
101
+ activerecord.errors.messages.less_than_or_equal_to
102
+ activerecord.errors.messages.odd
103
+ activerecord.errors.messages.even
104
+ activerecord.errors.messages.record_invalid
105
+
106
+ activerecord.errors.full_messages.format
107
+ ).each do |key|
108
+ it "should define '#{key}' in activerecord translations" do
109
+ lookup(key).should_not be_nil
110
+ end
111
+ end
112
+
113
+ %w(
114
+ support.array.sentence_connector
115
+ support.array.skip_last_comma
116
+
117
+ support.array.words_connector
118
+ support.array.two_words_connector
119
+ support.array.last_word_connector
120
+ ).each do |key|
121
+ it "should define '#{key}' in activesupport translations" do
122
+ lookup(key).should_not be_nil
123
+ end
124
+ end
125
+
126
+ def lookup(*args)
127
+ I18n.backend.send(:lookup, Russian.locale, *args)
128
+ end
129
+ end
@@ -0,0 +1,136 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe Russian, "VERSION" do
6
+ it "should be defined" do
7
+ %w(MAJOR MINOR TINY STRING).each do |v|
8
+ Russian::VERSION.const_defined?(v).should == true
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Russian do
14
+ describe "with locale" do
15
+ it "should define :'ru' LOCALE" do
16
+ Russian::LOCALE.should == :'ru'
17
+ end
18
+
19
+ it "should provide 'locale' proxy" do
20
+ Russian.locale.should == Russian::LOCALE
21
+ end
22
+ end
23
+
24
+ describe "with custom backend class" do
25
+ it "should define i18n_backend_class" do
26
+ Russian.i18n_backend_class.should == I18n::Backend::Advanced
27
+ end
28
+ end
29
+
30
+ describe "during i18n initialization" do
31
+ after(:each) do
32
+ I18n.load_path = []
33
+ Russian.init_i18n
34
+ end
35
+
36
+ it "should set I18n backend to an instance of a custom backend" do
37
+ Russian.init_i18n
38
+ I18n.backend.class.should == Russian.i18n_backend_class
39
+ end
40
+
41
+ it "should keep existing translations while switching backends" do
42
+ I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'en.yml')
43
+ Russian.init_i18n
44
+ I18n.t(:foo, :locale => :'en').should == "bar"
45
+ end
46
+
47
+ it "should keep existing :ru translations while switching backends" do
48
+ I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'ru.yml')
49
+ Russian.init_i18n
50
+ I18n.t(:'date.formats.default', :locale => :'ru').should == "override"
51
+ end
52
+
53
+ it "should set default locale to Russian locale" do
54
+ Russian.init_i18n
55
+ I18n.default_locale.should == Russian.locale
56
+ end
57
+ end
58
+
59
+ describe "with localize proxy" do
60
+ before(:all) do
61
+ @time = mock(:time)
62
+ @options = { :format => "%d %B %Y" }
63
+ end
64
+
65
+ %w(l localize).each do |method|
66
+ it "'#{method}' should call I18n backend localize" do
67
+ I18n.should_receive(:localize).with(@time, @options.merge({ :locale => Russian.locale }))
68
+ Russian.send(method, @time, @options)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "with translate proxy" do
74
+ before(:all) do
75
+ @object = :bar
76
+ @options = { :scope => :foo }
77
+ end
78
+
79
+ %w(t translate).each do |method|
80
+ it "'#{method}' should call I18n backend translate" do
81
+ I18n.should_receive(:translate).with(@object, @options.merge({ :locale => Russian.locale }))
82
+ Russian.send(method, @object, @options)
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "strftime" do
88
+ before(:all) do
89
+ @time = mock(:time)
90
+ end
91
+
92
+ it "should call localize with object and format" do
93
+ format = "%d %B %Y"
94
+ Russian.should_receive(:localize).with(@time, { :format => format })
95
+ Russian.strftime(@time, format)
96
+ end
97
+
98
+ it "should call localize with object and default format when format is not specified" do
99
+ Russian.should_receive(:localize).with(@time, { :format => :default })
100
+ Russian.strftime(@time)
101
+ end
102
+ end
103
+
104
+ describe "with pluralization" do
105
+ %w(p pluralize).each do |method|
106
+ it "'#{method}' should pluralize with variants given" do
107
+ variants = %w(вещь вещи вещей вещи)
108
+
109
+ Russian.send(method, 1, *variants).should == "вещь"
110
+ Russian.send(method, 2, *variants).should == 'вещи'
111
+ Russian.send(method, 3, *variants).should == 'вещи'
112
+ Russian.send(method, 5, *variants).should == 'вещей'
113
+ Russian.send(method, 10, *variants).should == 'вещей'
114
+ Russian.send(method, 21, *variants).should == 'вещь'
115
+ Russian.send(method, 29, *variants).should == 'вещей'
116
+ Russian.send(method, 129, *variants).should == 'вещей'
117
+ Russian.send(method, 131, *variants).should == 'вещь'
118
+ Russian.send(method, 3.14, *variants).should == 'вещи'
119
+ end
120
+
121
+ it "should raise an exception when first parameter is not a number" do
122
+ lambda { Russian.send(method, nil, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError)
123
+ lambda { Russian.send(method, "вещь", "вещь", "вещи", "вещей") }.should raise_error(ArgumentError)
124
+ end
125
+
126
+ it "should raise an exception when there are not enough variants" do
127
+ lambda { Russian.send(method, 1) }.should raise_error(ArgumentError)
128
+ lambda { Russian.send(method, 1, "вещь") }.should raise_error(ArgumentError)
129
+ lambda { Russian.send(method, 1, "вещь", "вещи") }.should raise_error(ArgumentError)
130
+ lambda { Russian.send(method, 1, "вещь", "вещи", "вещей") }.should_not raise_error(ArgumentError)
131
+ lambda { Russian.send(method, 3.14, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError)
132
+ lambda { Russian.send(method, 3.14, "вещь", "вещи", "вещей", "вещи") }.should_not raise_error(ArgumentError)
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $TESTING=true
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+
6
+ require 'russian'
7
+
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe Russian do
6
+ describe "transliteration" do
7
+ def t(str)
8
+ Russian::transliterate(str)
9
+ end
10
+
11
+ %w(transliterate translit).each do |method|
12
+ it "'#{method}' method should perform transliteration" do
13
+ str = mock(:str)
14
+ Russian::Transliteration.should_receive(:transliterate).with(str)
15
+ Russian.send(method, str)
16
+ end
17
+ end
18
+
19
+ # These tests are from rutils, <http://rutils.rubyforge.org>.
20
+
21
+ it "should transliterate properly" do
22
+ t("Это просто некий текст").should == "Eto prosto nekiy tekst"
23
+ t("щ").should == "sch"
24
+ t("стансы").should == "stansy"
25
+ t("упущение").should == "upuschenie"
26
+ t("ш").should == "sh"
27
+ t("Ш").should == "SH"
28
+ t("ц").should == "ts"
29
+ end
30
+
31
+ it "should properly transliterate mixed russian-english strings" do
32
+ t("Это кусок строки русских букв v peremeshku s latinizey i амперсандом (pozor!) & something").should ==
33
+ "Eto kusok stroki russkih bukv v peremeshku s latinizey i ampersandom (pozor!) & something"
34
+ end
35
+
36
+ it "should properly transliterate mixed case chars in a string" do
37
+ t("НЕВЕРОЯТНОЕ УПУЩЕНИЕ").should == "NEVEROYATNOE UPUSCHENIE"
38
+ t("Невероятное Упущение").should == "Neveroyatnoe Upuschenie"
39
+ t("Шерстяной Заяц").should == "Sherstyanoy Zayats"
40
+ t("Н.П. Шерстяков").should == "N.P. Sherstyakov"
41
+ t("ШАРОВАРЫ").should == "SHAROVARY"
42
+ end
43
+
44
+ it "should work for multi-char substrings" do
45
+ t("38 воробьёв").should == "38 vorobiev"
46
+ t("Вася Воробьёв").should == "Vasya Vorobiev"
47
+ t("Алябьев").should == "Alyabiev"
48
+ t("АЛЯБЬЕВ").should == "ALYABIEV"
49
+ end
50
+ end
51
+ end