krasivotokak-russian 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG +64 -0
  2. data/LICENSE +20 -0
  3. data/README.textile +288 -0
  4. data/Rakefile +55 -0
  5. data/TODO +10 -0
  6. data/init.rb +3 -0
  7. data/lib/russian.rb +119 -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 +67 -0
  10. data/lib/russian/active_support_ext/parameterize.rb +31 -0
  11. data/lib/russian/backend/advanced.rb +132 -0
  12. data/lib/russian/locale/actionview.yml +153 -0
  13. data/lib/russian/locale/activerecord.yml +90 -0
  14. data/lib/russian/locale/activesupport.yml +16 -0
  15. data/lib/russian/locale/datetime.yml +46 -0
  16. data/lib/russian/locale/pluralize.rb +36 -0
  17. data/lib/russian/transliteration.rb +60 -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/lib/vendor/i18n_label/README.textile +38 -0
  32. data/lib/vendor/i18n_label/Rakefile +11 -0
  33. data/lib/vendor/i18n_label/init.rb +1 -0
  34. data/lib/vendor/i18n_label/install.rb +1 -0
  35. data/lib/vendor/i18n_label/lib/i18n_label.rb +23 -0
  36. data/lib/vendor/i18n_label/spec/i18n_label_spec.rb +20 -0
  37. data/lib/vendor/i18n_label/spec/spec_helper.rb +10 -0
  38. data/lib/vendor/i18n_label/tasks/i18n_label_tasks.rake +4 -0
  39. data/lib/vendor/i18n_label/uninstall.rb +1 -0
  40. data/spec/fixtures/en.yml +4 -0
  41. data/spec/fixtures/ru.yml +4 -0
  42. data/spec/i18n/locale/datetime_spec.rb +93 -0
  43. data/spec/i18n/locale/pluralization_spec.rb +28 -0
  44. data/spec/locale_spec.rb +123 -0
  45. data/spec/russian_spec.rb +136 -0
  46. data/spec/spec_helper.rb +7 -0
  47. data/spec/transliteration_spec.rb +44 -0
  48. metadata +125 -0
@@ -0,0 +1,38 @@
1
+ h1. I18nLabel
2
+
3
+ Since labels don't use I18n in Rails 2.2 (I was too late in submitting the
4
+ patch), we'd have to make due with a plugin.
5
+
6
+ Installation and configuration consists of 1 easy steps:
7
+
8
+ # Run:
9
+
10
+ ./script/plugin install git://github.com/iain/i18n_label.git
11
+
12
+
13
+ h1. Example
14
+
15
+ In your translation file:
16
+
17
+ en-US:
18
+ activerecord:
19
+ attributes:
20
+ topic:
21
+ name: A nice name
22
+
23
+ In your view:
24
+
25
+ <% form_for @topic do |f| %>
26
+ <%= f.label :name %>
27
+ <% end %>
28
+
29
+ The result is:
30
+
31
+ &lt;label for="topic_name">A nice name</label> (please ignore the minor problem with html in github)
32
+
33
+
34
+
35
+ For more information about where to put your translations,
36
+ visit "my blog":http://iain.nl/2008/09/translating-activerecord/
37
+
38
+ Copyright (c) 2008 "Iain Hecker":http://iain.nl/, released under the MIT license
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc 'Run the specs'
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
10
+ t.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/lib/i18n_label.rb'
@@ -0,0 +1 @@
1
+ File.readlines(File.dirname(__FILE__)+'/README.textile').each { |line| puts line }
@@ -0,0 +1,23 @@
1
+ # Just replace the method...
2
+ module ActionView
3
+ module Helpers
4
+ class InstanceTag
5
+ def to_label_tag(text = nil, options = {})
6
+ options = options.stringify_keys
7
+ name_and_id = options.dup
8
+ add_default_name_and_id(name_and_id)
9
+ options.delete("index")
10
+ options["for"] ||= name_and_id["id"]
11
+ if text.blank?
12
+ content = method_name.humanize
13
+ if object.class.respond_to?(:human_attribute_name)
14
+ content = object.class.human_attribute_name(method_name)
15
+ end
16
+ else
17
+ content = text.to_s
18
+ end
19
+ label_tag(name_and_id["id"], content, options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ # give a model to play with
4
+ class Reply < ActiveRecord::Base
5
+ attr_accessor :title
6
+ end
7
+
8
+ describe ActionView::Helpers do
9
+
10
+ # NOTE gives deprication warning in RSpec 1.1.4:
11
+ # Modules will no longer be automatically included in RSpec version 1.1.4. Called from ./spec/i18n_label_spec.rb:15
12
+ it "label should make a call to human_attribute_name" do
13
+ Reply.should_receive(:human_attribute_name).with('title').and_return("translated title")
14
+ reply = mock_model(Reply)
15
+ fields_for(reply) do |f|
16
+ f.label(:title).should == "<label for=\"reply_title\">translated title</label>"
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,10 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
3
+ rescue LoadError
4
+ puts "You need to install rspec in your base app"
5
+ exit
6
+ end
7
+
8
+ plugin_spec_dir = File.dirname(__FILE__)
9
+ ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
10
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :i18n_label do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1 @@
1
+ puts "Bye!"
@@ -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,93 @@
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
+ @date = Date.parse("1985-12-01")
8
+ @time = Time.local(1985, 12, 01, 16, 05)
9
+ end
10
+
11
+ describe "with date formats" do
12
+ it "should use default format" do
13
+ l(@date).should == "01.12.1985"
14
+ end
15
+
16
+ it "should use short format" do
17
+ l(@date, :format => :short).should == "01 дек."
18
+ end
19
+
20
+ it "should use long format" do
21
+ l(@date, :format => :long).should == "01 декабря 1985"
22
+ end
23
+ end
24
+
25
+ describe "with date day names" do
26
+ it "should use day names" do
27
+ l(@date, :format => "%d %B (%A)").should == "01 декабря (воскресенье)"
28
+ l(@date, :format => "%d %B %Y года было %A").should == "01 декабря 1985 года было воскресенье"
29
+ end
30
+
31
+ it "should use standalone day names" do
32
+ l(@date, :format => "%A").should == "Воскресенье"
33
+ l(@date, :format => "%A, %d %B").should == "Воскресенье, 01 декабря"
34
+ end
35
+
36
+ it "should use abbreviated day names" do
37
+ l(@date, :format => "%a").should == "Вс"
38
+ l(@date, :format => "%a, %d %b %Y").should == "Вс, 01 дек. 1985"
39
+ end
40
+ end
41
+
42
+ describe "with month names" do
43
+ it "should use month names" do
44
+ l(@date, :format => "%d %B").should == "01 декабря"
45
+ l(@date, :format => "%e %B %Y").should == " 1 декабря 1985"
46
+ end
47
+
48
+ it "should use standalone month names" do
49
+ l(@date, :format => "%B").should == "Декабрь"
50
+ l(@date, :format => "%B %Y").should == "Декабрь 1985"
51
+ end
52
+
53
+ it "should use abbreviated month names" do
54
+ @date = Date.parse("1985-03-01")
55
+ l(@date, :format => "%d %b").should == "01 марта"
56
+ l(@date, :format => "%e %b %Y").should == " 1 марта 1985"
57
+ end
58
+
59
+ it "should use standalone abbreviated month names" do
60
+ @date = Date.parse("1985-03-01")
61
+ l(@date, :format => "%b").should == "март"
62
+ l(@date, :format => "%b %Y").should == "март 1985"
63
+ end
64
+ end
65
+
66
+ it "should define default date components order: day, month, year" do
67
+ I18n.backend.translate(Russian.locale, :"date.order").should == [:day, :month, :year]
68
+ end
69
+
70
+ describe "with time formats" do
71
+ it "should use default format" do
72
+ l(@time).should =~ /^Вс, 01 дек. 1985, 16:05:00/
73
+ end
74
+
75
+ it "should use short format" do
76
+ l(@time, :format => :short).should == "01 дек., 16:05"
77
+ end
78
+
79
+ it "should use long format" do
80
+ l(@time, :format => :long).should == "01 декабря 1985, 16:05"
81
+ end
82
+
83
+ it "should define am and pm" do
84
+ I18n.backend.translate(Russian.locale, :"time.am").should_not be_nil
85
+ I18n.backend.translate(Russian.locale, :"time.pm").should_not be_nil
86
+ end
87
+ end
88
+
89
+ protected
90
+ def l(object, options = {})
91
+ I18n.l(object, options.merge( { :locale => Russian.locale }))
92
+ end
93
+ 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,123 @@
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
+
66
+ datetime.prompts.year
67
+ datetime.prompts.month
68
+ datetime.prompts.day
69
+ datetime.prompts.hour
70
+ datetime.prompts.minute
71
+ datetime.prompts.second
72
+
73
+ activerecord.errors.template.header
74
+ activerecord.errors.template.body
75
+ ).each do |key|
76
+ it "should define '#{key}' in actionview translations" do
77
+ lookup(key).should_not be_nil
78
+ end
79
+ end
80
+
81
+ %w(
82
+ activerecord.errors.messages.inclusion
83
+ activerecord.errors.messages.exclusion
84
+ activerecord.errors.messages.invalid
85
+ activerecord.errors.messages.confirmation
86
+ activerecord.errors.messages.accepted
87
+ activerecord.errors.messages.empty
88
+ activerecord.errors.messages.blank
89
+ activerecord.errors.messages.too_long
90
+ activerecord.errors.messages.too_short
91
+ activerecord.errors.messages.wrong_length
92
+ activerecord.errors.messages.taken
93
+ activerecord.errors.messages.not_a_number
94
+ activerecord.errors.messages.greater_than
95
+ activerecord.errors.messages.greater_than_or_equal_to
96
+ activerecord.errors.messages.equal_to
97
+ activerecord.errors.messages.less_than
98
+ activerecord.errors.messages.less_than_or_equal_to
99
+ activerecord.errors.messages.odd
100
+ activerecord.errors.messages.even
101
+ ).each do |key|
102
+ it "should define '#{key}' in activerecord translations" do
103
+ lookup(key).should_not be_nil
104
+ end
105
+ end
106
+
107
+ %w(
108
+ support.array.sentence_connector
109
+ support.array.skip_last_comma
110
+
111
+ support.array.words_connector
112
+ support.array.two_words_connector
113
+ support.array.last_word_connector
114
+ ).each do |key|
115
+ it "should define '#{key}' in activesupport translations" do
116
+ lookup(key).should_not be_nil
117
+ end
118
+ end
119
+
120
+ def lookup(*args)
121
+ I18n.backend.send(:lookup, Russian.locale, *args)
122
+ end
123
+ 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