russian 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +10 -0
- data/README.textile +15 -4
- data/Rakefile +1 -1
- data/lib/russian.rb +4 -2
- data/lib/russian/active_record_ext/custom_error_message.rb +100 -42
- data/lib/russian/locale/actionview.yml +4 -0
- data/lib/russian/locale/activerecord.yml +5 -0
- data/lib/russian/locale/pluralize.rb +3 -14
- data/lib/russian/transliteration.rb +2 -2
- data/spec/locale_spec.rb +5 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/transliteration_spec.rb +2 -2
- metadata +29 -48
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.2.1 - 5.09.2009
|
2
|
+
|
3
|
+
* Rails 2.3.4 compat (ActiveRecord::Error) and deprecation warning (use errors.full_messages.format from now on) [Alexander Semyonov/Yaroslav Markin]
|
4
|
+
* Added a couple of missing translations from Rails 2.3.4
|
5
|
+
* transliteration: Ы now transforms to Y [Alex Fortuna]
|
6
|
+
|
7
|
+
* Совместимость с Rails 2.3.4 (ActiveRecord::Error) и устаревшее форматирование через "^" (теперь надо использовать errors.full_messages.format) [Alexander Semyonov/Yaroslav Markin]
|
8
|
+
* Добавлена пара недостающих переводов из Rails 2.3.4
|
9
|
+
* транслитерация: Ы теперь превращается в Y [Alex Fortuna]
|
10
|
+
|
1
11
|
=== 0.2.0 - 16.03.2009
|
2
12
|
|
3
13
|
* number_to_human_size() translations: using edge format (Rails 2.3)
|
data/README.textile
CHANGED
@@ -233,7 +233,9 @@ ru:
|
|
233
233
|
|
234
234
|
h3. Валидация
|
235
235
|
|
236
|
-
|
236
|
+
До версии Rails 2.3.4 форматирование сообщений об ошибках не было гибким, и для нормального отображения ошибок на русском языке приходилось испольковать хаки. Если вы используете Rails 2.3.4 и выше, пропустите этот пункт (используйте ключ переводов @activerecord.errors.full_messages.format@).
|
237
|
+
|
238
|
+
Для Rails 2.3.3 и ниже обработка ошибок в ActiveRecord перегружается -- в Russian включен популярный плагин custom_error_message, с помощью которого можно переопределять стандартное отображение сообщений об ошибках. Так, например,
|
237
239
|
|
238
240
|
@validates_acceptance_of :accepted_terms, :message => 'нужно принять соглашение'@
|
239
241
|
|
@@ -277,12 +279,21 @@ end
|
|
277
279
|
# => <a href="/person/1-donald-knut">Дональд Кнут</a>
|
278
280
|
</code></pre>
|
279
281
|
|
280
|
-
h1.
|
282
|
+
h1. Авторы
|
281
283
|
|
282
284
|
Для сообщений об ошибках, обнаруженных неточностях и предложений:
|
283
285
|
|
284
|
-
Ярослав Маркин ("yaroslav@markin.net":mailto:yaroslav@markin.net)
|
286
|
+
* "Ярослав Маркин":http://yaroslav.markin.net ("yaroslav@markin.net":mailto:yaroslav@markin.net)
|
287
|
+
|
288
|
+
При участии:
|
289
|
+
|
290
|
+
* "Юлика Тарханова":http://julik.nl
|
291
|
+
* "Евгения Пименова":http://libc.st/
|
292
|
+
* "Дмитрия Смалько":http://github.com/dsmalko
|
293
|
+
* Alex Fortuna ("alex@askit.org":mailto:alex@askit.org)
|
294
|
+
* "Антона Агеева":http://blog.antage.name/
|
295
|
+
* "Александра Семенова":http://rotuka.com/
|
285
296
|
|
286
297
|
Огромное спасибо:
|
287
298
|
|
288
|
-
Юлику Тарханову
|
299
|
+
"Юлику Тарханову":http://julik.nl за "rutils":http://rutils.rubyforge.org/
|
data/Rakefile
CHANGED
data/lib/russian.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
if RUBY_VERSION < "1.9"
|
4
|
+
$KCODE = 'u'
|
5
|
+
end
|
4
6
|
|
5
7
|
$:.push File.join(File.dirname(__FILE__), 'russian')
|
6
8
|
require 'transliteration'
|
@@ -27,7 +29,7 @@ module Russian
|
|
27
29
|
module VERSION
|
28
30
|
MAJOR = 0
|
29
31
|
MINOR = 2
|
30
|
-
TINY =
|
32
|
+
TINY = 1
|
31
33
|
|
32
34
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
33
35
|
end
|
@@ -1,53 +1,111 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
module ActiveRecord
|
6
|
-
class Errors
|
3
|
+
require 'active_record/version'
|
4
|
+
ma, mi, ti = ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR, ActiveRecord::VERSION::TINY
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
6
|
+
if (ma >= 2 && mi >= 3 && ti >= 4)
|
7
|
+
module ActiveRecord
|
8
|
+
class Error
|
9
|
+
protected
|
10
|
+
# Redefine the ActiveRecord::Error::generate_full_message method:
|
11
|
+
# Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
12
|
+
# Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
|
13
|
+
# in which case the attribute name is omitted.
|
14
|
+
# E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# Переопределяет метод ActiveRecord::Error::generate_full_message. Сообщения об ошибках для атрибутов
|
18
|
+
# теперь не имеют префикса с названием атрибута если в сообщении об ошибке первым символом указан "^".
|
19
|
+
#
|
20
|
+
# Так, например,
|
21
|
+
#
|
22
|
+
# validates_acceptance_of :accepted_terms, :message => 'нужно принять соглашение'
|
23
|
+
#
|
24
|
+
# даст сообщение
|
25
|
+
#
|
26
|
+
# Accepted terms нужно принять соглашение
|
27
|
+
#
|
28
|
+
# однако,
|
29
|
+
#
|
30
|
+
# validates_acceptance_of :accepted_terms, :message => '^Нужно принять соглашение'
|
31
|
+
#
|
32
|
+
# даст сообщение
|
33
|
+
#
|
34
|
+
# Нужно принять соглашение
|
35
|
+
def generate_full_message(message, options = {})
|
36
|
+
options.reverse_merge! :message => self.message,
|
37
|
+
:model => @base.class.human_name,
|
38
|
+
:attribute => @base.class.human_attribute_name(attribute.to_s),
|
39
|
+
:value => value
|
40
|
+
|
41
|
+
key = :"full_messages.#{@message}"
|
42
|
+
|
43
|
+
if options[:message].is_a?(String) && options[:message] =~ /^\^/
|
44
|
+
ActiveSupport::Deprecation.warn("Using '^' hack for ActiveRecord error messages has been deprecated. Please use errors.full_messages.format I18n key for formatting")
|
35
45
|
|
36
|
-
|
37
|
-
|
38
|
-
next if msg.nil?
|
39
|
-
|
40
|
-
if attr == "base"
|
41
|
-
full_messages << msg
|
42
|
-
elsif msg =~ /^\^/
|
43
|
-
full_messages << msg[1..-1]
|
46
|
+
options[:full_message] = options[:message][1..-1]
|
47
|
+
defaults = [:'full_messages.format', '{{full_message}}']
|
44
48
|
else
|
45
|
-
|
49
|
+
defaults = [:'full_messages.format', '{{attribute}} {{message}}']
|
46
50
|
end
|
51
|
+
|
52
|
+
I18n.t(key, options.merge(:default => defaults, :scope => [:activerecord, :errors]))
|
47
53
|
end
|
48
|
-
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
else
|
58
|
+
module ActiveRecord
|
59
|
+
class Errors
|
60
|
+
# DEPRECATED as of Rails 2.3.4
|
61
|
+
#
|
62
|
+
# The following is taken from custom_error_message plugin by David Easley
|
63
|
+
# (http://rubyforge.org/projects/custom-err-msg/)
|
64
|
+
#
|
65
|
+
# Redefine the ActiveRecord::Errors::full_messages method:
|
66
|
+
# Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
67
|
+
# Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
|
68
|
+
# in which case the attribute name is omitted.
|
69
|
+
# E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
70
|
+
#
|
71
|
+
#
|
72
|
+
# Переопределяет метод ActiveRecord::Errors::full_messages. Сообщения об ошибках для атрибутов
|
73
|
+
# теперь не имеют префикса с названием атрибута если в сообщении об ошибке первым символом указан "^".
|
74
|
+
#
|
75
|
+
# Так, например,
|
76
|
+
#
|
77
|
+
# validates_acceptance_of :accepted_terms, :message => 'нужно принять соглашение'
|
78
|
+
#
|
79
|
+
# даст сообщение
|
80
|
+
#
|
81
|
+
# Accepted terms нужно принять соглашение
|
82
|
+
#
|
83
|
+
# однако,
|
84
|
+
#
|
85
|
+
# validates_acceptance_of :accepted_terms, :message => '^Нужно принять соглашение'
|
86
|
+
#
|
87
|
+
# даст сообщение
|
88
|
+
#
|
89
|
+
# Нужно принять соглашение
|
90
|
+
def full_messages
|
91
|
+
full_messages = []
|
49
92
|
|
50
|
-
|
93
|
+
@errors.each_key do |attr|
|
94
|
+
@errors[attr].each do |msg|
|
95
|
+
next if msg.nil?
|
96
|
+
|
97
|
+
if attr == "base"
|
98
|
+
full_messages << msg
|
99
|
+
elsif msg =~ /^\^/
|
100
|
+
full_messages << msg[1..-1]
|
101
|
+
else
|
102
|
+
full_messages << @base.class.human_attribute_name(attr) + " " + msg
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
return full_messages
|
108
|
+
end
|
51
109
|
end
|
52
110
|
end
|
53
111
|
end
|
@@ -47,6 +47,11 @@ ru:
|
|
47
47
|
less_than_or_equal_to: "может иметь значение меньшее или равное {{count}}"
|
48
48
|
odd: "может иметь лишь четное значение"
|
49
49
|
even: "может иметь лишь нечетное значение"
|
50
|
+
record_invalid: "Возникли ошибки: {{errors}}"
|
51
|
+
|
52
|
+
full_messages:
|
53
|
+
format: "{{attribute}} {{message}}"
|
54
|
+
|
50
55
|
# Можно добавить собственные сообщения об ошибке тут или задавать их в контексте атрибута.
|
51
56
|
#
|
52
57
|
#
|
@@ -15,22 +15,11 @@
|
|
15
15
|
#
|
16
16
|
# Пример
|
17
17
|
#
|
18
|
-
# :one
|
19
|
-
# :few
|
18
|
+
# :one = 1, 21, 31, 41, 51, 61...
|
19
|
+
# :few = 2-4, 22-24, 32-34...
|
20
20
|
# :many = 0, 5-20, 25-30, 35-40...
|
21
21
|
# :other = 1.31, 2.31, 5.31...
|
22
|
-
|
23
|
-
modulo100 = n.modulo(100)
|
24
|
-
|
25
|
-
if modulo10 == 1 && modulo100 != 11
|
26
|
-
:one
|
27
|
-
elsif (modulo10 == 2 || modulo10 == 3 || modulo10 == 4) && !(modulo100 == 12 || modulo100 == 13 || modulo100 == 14)
|
28
|
-
:few
|
29
|
-
elsif modulo10 == 0 || (modulo10 == 5 || modulo10 == 6 || modulo10 == 7 || modulo10 == 8 || modulo10 == 9) || (modulo100 == 11 || modulo100 == 12 || modulo100 == 13 || modulo100 == 14)
|
30
|
-
:many
|
31
|
-
else
|
32
|
-
:other
|
33
|
-
end
|
22
|
+
n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other
|
34
23
|
}
|
35
24
|
}
|
36
25
|
}
|
@@ -19,7 +19,7 @@ module Russian
|
|
19
19
|
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
|
20
20
|
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
|
21
21
|
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
|
22
|
-
"ы"=>"
|
22
|
+
"ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya"
|
23
23
|
}.freeze
|
24
24
|
|
25
25
|
UPPER = {
|
@@ -29,7 +29,7 @@ module Russian
|
|
29
29
|
"Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
|
30
30
|
"О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
|
31
31
|
"У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
|
32
|
-
"Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"
|
32
|
+
"Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"",
|
33
33
|
"Э"=>"E","Ю"=>"YU","Я"=>"YA",
|
34
34
|
}.freeze
|
35
35
|
|
data/spec/locale_spec.rb
CHANGED
@@ -72,6 +72,8 @@ describe Russian, "loading locales" do
|
|
72
72
|
|
73
73
|
activerecord.errors.template.header
|
74
74
|
activerecord.errors.template.body
|
75
|
+
|
76
|
+
support.select.prompt
|
75
77
|
).each do |key|
|
76
78
|
it "should define '#{key}' in actionview translations" do
|
77
79
|
lookup(key).should_not be_nil
|
@@ -98,6 +100,9 @@ describe Russian, "loading locales" do
|
|
98
100
|
activerecord.errors.messages.less_than_or_equal_to
|
99
101
|
activerecord.errors.messages.odd
|
100
102
|
activerecord.errors.messages.even
|
103
|
+
activerecord.errors.messages.record_invalid
|
104
|
+
|
105
|
+
activerecord.errors.full_messages.format
|
101
106
|
).each do |key|
|
102
107
|
it "should define '#{key}' in activerecord translations" do
|
103
108
|
lookup(key).should_not be_nil
|
data/spec/spec_helper.rb
CHANGED
@@ -21,7 +21,7 @@ describe Russian do
|
|
21
21
|
it "should transliterate properly" do
|
22
22
|
t("Это просто некий текст").should == "Eto prosto nekiy tekst"
|
23
23
|
t("щ").should == "sch"
|
24
|
-
t("стансы").should == "
|
24
|
+
t("стансы").should == "stansy"
|
25
25
|
t("упущение").should == "upuschenie"
|
26
26
|
t("ш").should == "sh"
|
27
27
|
t("Ш").should == "SH"
|
@@ -38,7 +38,7 @@ describe Russian do
|
|
38
38
|
t("Невероятное Упущение").should == "Neveroyatnoe Upuschenie"
|
39
39
|
t("Шерстяной Заяц").should == "Sherstyanoy Zayats"
|
40
40
|
t("Н.П. Шерстяков").should == "N.P. Sherstyakov"
|
41
|
-
t("ШАРОВАРЫ").should == "
|
41
|
+
t("ШАРОВАРЫ").should == "SHAROVARY"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: russian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Markin
|
@@ -9,7 +9,7 @@ autorequire: russian
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-05 00:00:00 +04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,70 +31,51 @@ files:
|
|
31
31
|
- CHANGELOG
|
32
32
|
- TODO
|
33
33
|
- init.rb
|
34
|
-
- lib/russian
|
35
|
-
- lib/russian/active_record_ext
|
34
|
+
- lib/russian/action_view_ext/helpers/date_helper.rb
|
36
35
|
- lib/russian/active_record_ext/custom_error_message.rb
|
37
|
-
- lib/russian/active_support_ext
|
38
36
|
- lib/russian/active_support_ext/parameterize.rb
|
39
|
-
- lib/russian/
|
37
|
+
- lib/russian/backend/advanced.rb
|
40
38
|
- lib/russian/locale/actionview.yml
|
41
|
-
- lib/russian/locale/pluralize.rb
|
42
|
-
- lib/russian/locale/datetime.yml
|
43
39
|
- lib/russian/locale/activerecord.yml
|
44
40
|
- lib/russian/locale/activesupport.yml
|
45
|
-
- lib/russian/
|
46
|
-
- lib/russian/
|
47
|
-
- lib/russian/action_view_ext/helpers/date_helper.rb
|
41
|
+
- lib/russian/locale/datetime.yml
|
42
|
+
- lib/russian/locale/pluralize.rb
|
48
43
|
- lib/russian/transliteration.rb
|
49
|
-
- lib/russian
|
50
|
-
- lib/russian/backend/advanced.rb
|
51
|
-
- lib/vendor
|
52
|
-
- lib/vendor/i18n
|
53
|
-
- lib/vendor/i18n/test
|
54
|
-
- lib/vendor/i18n/test/i18n_exceptions_test.rb
|
55
|
-
- lib/vendor/i18n/test/simple_backend_test.rb
|
56
|
-
- lib/vendor/i18n/test/all.rb
|
57
|
-
- lib/vendor/i18n/test/i18n_test.rb
|
58
|
-
- lib/vendor/i18n/test/locale
|
59
|
-
- lib/vendor/i18n/test/locale/en.yml
|
60
|
-
- lib/vendor/i18n/test/locale/en.rb
|
44
|
+
- lib/russian.rb
|
61
45
|
- lib/vendor/i18n/i18n.gemspec
|
62
|
-
- lib/vendor/i18n/lib
|
63
|
-
- lib/vendor/i18n/lib/i18n.rb
|
64
|
-
- lib/vendor/i18n/lib/i18n
|
65
|
-
- lib/vendor/i18n/lib/i18n/exceptions.rb
|
66
|
-
- lib/vendor/i18n/lib/i18n/backend
|
67
46
|
- lib/vendor/i18n/lib/i18n/backend/simple.rb
|
47
|
+
- lib/vendor/i18n/lib/i18n/exceptions.rb
|
48
|
+
- lib/vendor/i18n/lib/i18n.rb
|
68
49
|
- lib/vendor/i18n/MIT-LICENSE
|
69
|
-
- lib/vendor/i18n/README.textile
|
70
50
|
- lib/vendor/i18n/Rakefile
|
71
|
-
- lib/vendor/
|
72
|
-
- lib/vendor/
|
73
|
-
- lib/vendor/
|
74
|
-
- lib/vendor/
|
51
|
+
- lib/vendor/i18n/README.textile
|
52
|
+
- lib/vendor/i18n/test/all.rb
|
53
|
+
- lib/vendor/i18n/test/i18n_exceptions_test.rb
|
54
|
+
- lib/vendor/i18n/test/i18n_test.rb
|
55
|
+
- lib/vendor/i18n/test/locale/en.rb
|
56
|
+
- lib/vendor/i18n/test/locale/en.yml
|
57
|
+
- lib/vendor/i18n/test/simple_backend_test.rb
|
75
58
|
- lib/vendor/i18n_label/init.rb
|
76
59
|
- lib/vendor/i18n_label/install.rb
|
77
|
-
- lib/vendor/i18n_label/uninstall.rb
|
78
|
-
- lib/vendor/i18n_label/lib
|
79
60
|
- lib/vendor/i18n_label/lib/i18n_label.rb
|
61
|
+
- lib/vendor/i18n_label/Rakefile
|
80
62
|
- lib/vendor/i18n_label/README.textile
|
81
|
-
- lib/vendor/i18n_label/
|
63
|
+
- lib/vendor/i18n_label/spec/i18n_label_spec.rb
|
64
|
+
- lib/vendor/i18n_label/spec/spec_helper.rb
|
82
65
|
- lib/vendor/i18n_label/tasks/i18n_label_tasks.rake
|
83
|
-
- lib/vendor/i18n_label/
|
84
|
-
-
|
66
|
+
- lib/vendor/i18n_label/uninstall.rb
|
67
|
+
- spec/fixtures/en.yml
|
68
|
+
- spec/fixtures/ru.yml
|
69
|
+
- spec/i18n/locale/datetime_spec.rb
|
70
|
+
- spec/i18n/locale/pluralization_spec.rb
|
71
|
+
- spec/locale_spec.rb
|
85
72
|
- spec/russian_spec.rb
|
86
73
|
- spec/spec_helper.rb
|
87
|
-
- spec/locale_spec.rb
|
88
|
-
- spec/i18n
|
89
|
-
- spec/i18n/locale
|
90
|
-
- spec/i18n/locale/pluralization_spec.rb
|
91
|
-
- spec/i18n/locale/datetime_spec.rb
|
92
|
-
- spec/fixtures
|
93
|
-
- spec/fixtures/ru.yml
|
94
|
-
- spec/fixtures/en.yml
|
95
74
|
- spec/transliteration_spec.rb
|
96
75
|
has_rdoc: true
|
97
76
|
homepage: http://github.com/yaroslav/russian/
|
77
|
+
licenses: []
|
78
|
+
|
98
79
|
post_install_message:
|
99
80
|
rdoc_options: []
|
100
81
|
|
@@ -115,9 +96,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
96
|
requirements: []
|
116
97
|
|
117
98
|
rubyforge_project:
|
118
|
-
rubygems_version: 1.3.
|
99
|
+
rubygems_version: 1.3.5
|
119
100
|
signing_key:
|
120
|
-
specification_version:
|
101
|
+
specification_version: 3
|
121
102
|
summary: Russian language support for Ruby and Rails
|
122
103
|
test_files: []
|
123
104
|
|