belorussian 0.6.0
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 +132 -0
- data/Gemfile +9 -0
- data/LICENSE +20 -0
- data/README.textile +297 -0
- data/Rakefile +10 -0
- data/TODO +4 -0
- data/belorussian.gemspec +26 -0
- data/lib/belorussian.rb +98 -0
- data/lib/belorussian/action_view_ext/helpers/date_helper.rb +118 -0
- data/lib/belorussian/active_model_ext/custom_error_message.rb +70 -0
- data/lib/belorussian/belorussian_rails.rb +8 -0
- data/lib/belorussian/locale/actionview.yml +212 -0
- data/lib/belorussian/locale/activemodel.yml +50 -0
- data/lib/belorussian/locale/activerecord.yml +95 -0
- data/lib/belorussian/locale/activesupport.yml +16 -0
- data/lib/belorussian/locale/datetime.rb +39 -0
- data/lib/belorussian/locale/datetime.yml +50 -0
- data/lib/belorussian/locale/pluralization.rb +28 -0
- data/lib/belorussian/locale/transliterator.rb +17 -0
- data/lib/belorussian/transliteration.rb +72 -0
- data/lib/belorussian/version.rb +9 -0
- data/spec/belorussian_spec.rb +118 -0
- data/spec/fixtures/en.yml +4 -0
- data/spec/fixtures/ru.yml +4 -0
- data/spec/i18n/locale/datetime_spec.rb +106 -0
- data/spec/i18n/locale/pluralization_spec.rb +28 -0
- data/spec/locale_spec.rb +47 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/transliteration_spec.rb +51 -0
- metadata +125 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
by:
|
|
2
|
+
errors:
|
|
3
|
+
format: "%{attribute} %{message}"
|
|
4
|
+
|
|
5
|
+
messages:
|
|
6
|
+
inclusion: "имеет непредусмотренное значение"
|
|
7
|
+
exclusion: "имеет зарезервированное значение"
|
|
8
|
+
invalid: "имеет неверное значение"
|
|
9
|
+
confirmation: "не совпадает с подтверждением"
|
|
10
|
+
accepted: "нужно подтвердить"
|
|
11
|
+
empty: "не может быть пустым"
|
|
12
|
+
blank: "не может быть пустым"
|
|
13
|
+
too_long:
|
|
14
|
+
one: "слишком большой длины (не может быть больше чем %{count} символ)"
|
|
15
|
+
few: "слишком большой длины (не может быть больше чем %{count} символа)"
|
|
16
|
+
many: "слишком большой длины (не может быть больше чем %{count} символов)"
|
|
17
|
+
other: "слишком большой длины (не может быть больше чем %{count} символа)"
|
|
18
|
+
too_short:
|
|
19
|
+
one: "недостаточной длины (не может быть меньше %{count} символа)"
|
|
20
|
+
few: "недостаточной длины (не может быть меньше %{count} символов)"
|
|
21
|
+
many: "недостаточной длины (не может быть меньше %{count} символов)"
|
|
22
|
+
other: "недостаточной длины (не может быть меньше %{count} символа)"
|
|
23
|
+
wrong_length:
|
|
24
|
+
one: "неверной длины (может быть длиной ровно %{count} символ)"
|
|
25
|
+
few: "неверной длины (может быть длиной ровно %{count} символа)"
|
|
26
|
+
many: "неверной длины (может быть длиной ровно %{count} символов)"
|
|
27
|
+
other: "неверной длины (может быть длиной ровно %{count} символа)"
|
|
28
|
+
taken: "уже существует"
|
|
29
|
+
not_a_number: "не является числом"
|
|
30
|
+
not_an_integer: "не является целым числом"
|
|
31
|
+
greater_than: "может иметь значение большее %{count}"
|
|
32
|
+
greater_than_or_equal_to: "может иметь значение большее или равное %{count}"
|
|
33
|
+
equal_to: "может иметь лишь значение, равное %{count}"
|
|
34
|
+
less_than: "может иметь значение меньшее чем %{count}"
|
|
35
|
+
less_than_or_equal_to: "может иметь значение меньшее или равное %{count}"
|
|
36
|
+
odd: "может иметь лишь четное значение"
|
|
37
|
+
even: "может иметь лишь нечетное значение"
|
|
38
|
+
record_invalid: "Возникли ошибки: %{errors}"
|
|
39
|
+
|
|
40
|
+
template:
|
|
41
|
+
# Заголовок сообщения об ошибке
|
|
42
|
+
header:
|
|
43
|
+
one: "%{model}: сохранение не удалось из-за %{count} ошибки"
|
|
44
|
+
few: "%{model}: сохранение не удалось из-за %{count} ошибок"
|
|
45
|
+
many: "%{model}: сохранение не удалось из-за %{count} ошибок"
|
|
46
|
+
other: "%{model}: сохранение не удалось из-за %{count} ошибки"
|
|
47
|
+
|
|
48
|
+
# Первый параграф сообщения об ошибке. Можно использовать макрос %{count}
|
|
49
|
+
# The variable :count is also available
|
|
50
|
+
body: "Проблемы возникли со следующими полями:"
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
by:
|
|
2
|
+
activerecord:
|
|
3
|
+
# Сообщения об ошибке (валидации) ActiveRecord
|
|
4
|
+
errors:
|
|
5
|
+
# Для всех сообщений доступны макросы %{model}, {{attribute}}, {{value}}.
|
|
6
|
+
# Для некоторых доступен макрос %{count} -- в этом случае можно задать несколько вариантов
|
|
7
|
+
# сообщения (плюрализация)
|
|
8
|
+
#
|
|
9
|
+
# Также можно использовать сообщения, начинающиеся с "^" -- в этом случае
|
|
10
|
+
# в списке ошибок валидации перед конкретным сообщением не будет выводиться имя атрибута.
|
|
11
|
+
#
|
|
12
|
+
#
|
|
13
|
+
# The values :model, :attribute and :value are always available for interpolation
|
|
14
|
+
# The value :count is available when applicable. Can be used for pluralization.
|
|
15
|
+
#
|
|
16
|
+
# You can use ^-prefixed messages as well to get rid of human attribute name appearing
|
|
17
|
+
# before your message in validation messages.
|
|
18
|
+
messages:
|
|
19
|
+
inclusion: "имеет непредусмотренное значение"
|
|
20
|
+
exclusion: "имеет зарезервированное значение"
|
|
21
|
+
invalid: "имеет неверное значение"
|
|
22
|
+
confirmation: "не совпадает с подтверждением"
|
|
23
|
+
accepted: "нужно подтвердить"
|
|
24
|
+
empty: "не может быть пустым"
|
|
25
|
+
blank: "не может быть пустым"
|
|
26
|
+
too_long:
|
|
27
|
+
one: "слишком большой длины (не может быть больше чем %{count} символ)"
|
|
28
|
+
few: "слишком большой длины (не может быть больше чем %{count} символа)"
|
|
29
|
+
many: "слишком большой длины (не может быть больше чем %{count} символов)"
|
|
30
|
+
other: "слишком большой длины (не может быть больше чем %{count} символа)"
|
|
31
|
+
too_short:
|
|
32
|
+
one: "недостаточной длины (не может быть меньше %{count} символа)"
|
|
33
|
+
few: "недостаточной длины (не может быть меньше %{count} символов)"
|
|
34
|
+
many: "недостаточной длины (не может быть меньше %{count} символов)"
|
|
35
|
+
other: "недостаточной длины (не может быть меньше %{count} символа)"
|
|
36
|
+
wrong_length:
|
|
37
|
+
one: "неверной длины (может быть длиной ровно %{count} символ)"
|
|
38
|
+
few: "неверной длины (может быть длиной ровно %{count} символа)"
|
|
39
|
+
many: "неверной длины (может быть длиной ровно %{count} символов)"
|
|
40
|
+
other: "неверной длины (может быть длиной ровно %{count} символа)"
|
|
41
|
+
taken: "уже существует"
|
|
42
|
+
not_a_number: "не является числом"
|
|
43
|
+
greater_than: "может иметь лишь значение большее %{count}"
|
|
44
|
+
greater_than_or_equal_to: "может иметь лишь значение большее или равное %{count}"
|
|
45
|
+
equal_to: "может иметь лишь значение, равное %{count}"
|
|
46
|
+
less_than: "может иметь лишь значение меньшее чем %{count}"
|
|
47
|
+
less_than_or_equal_to: "может иметь значение меньшее или равное %{count}"
|
|
48
|
+
odd: "может иметь лишь четное значение"
|
|
49
|
+
even: "может иметь лишь нечетное значение"
|
|
50
|
+
record_invalid: "Возникли ошибки: %{errors}"
|
|
51
|
+
|
|
52
|
+
full_messages:
|
|
53
|
+
format: "%{attribute} %{message}"
|
|
54
|
+
|
|
55
|
+
# Можно добавить собственные сообщения об ошибке тут или задавать их в контексте атрибута.
|
|
56
|
+
#
|
|
57
|
+
#
|
|
58
|
+
# Append your own errors here or at the model/attributes scope.
|
|
59
|
+
#
|
|
60
|
+
#
|
|
61
|
+
# Например,
|
|
62
|
+
# models:
|
|
63
|
+
# user:
|
|
64
|
+
# # Задает сообщение об ошибке (пустое значение) для атрибутов модели User
|
|
65
|
+
# # Можно использовать макросы %{model}, {{attribute}}.
|
|
66
|
+
# # Также можно использовать сообщения, начинающиеся с "^" -- в этом случае
|
|
67
|
+
# # в списке ошибок валидации перед конкретным сообщением не будет выводиться имя атрибута.
|
|
68
|
+
# blank: "собственное сообщение об ошибке (пустой атрибут) для модели %{model} и атрибута {{attribute}}"
|
|
69
|
+
# attributes:
|
|
70
|
+
# # Также можно задавать собственные сообщения об ошибке для конкретных атрибутов модели.
|
|
71
|
+
# # Ниже определим собственное сообщение об ошибке для атрибута name модели User.
|
|
72
|
+
# name:
|
|
73
|
+
# blank: "Атрибут %{attribute} особенный -- у него свое сообщение об ошибке при пустом атрибуте"
|
|
74
|
+
models:
|
|
75
|
+
|
|
76
|
+
# Перевод названий моделей. Используется в Model.human_name().
|
|
77
|
+
#
|
|
78
|
+
#models:
|
|
79
|
+
# Например,
|
|
80
|
+
# user: "Пользователь"
|
|
81
|
+
# переведет модель User как "Пользователь".
|
|
82
|
+
#
|
|
83
|
+
#
|
|
84
|
+
# Overrides default messages
|
|
85
|
+
|
|
86
|
+
# Перевод названий атрибутов моделей. Используется в Model.human_attribute_name(attribute).
|
|
87
|
+
#attributes:
|
|
88
|
+
# Например,
|
|
89
|
+
# user:
|
|
90
|
+
# name: "Имя"
|
|
91
|
+
# переведет атрибут name модели User как "Имя".
|
|
92
|
+
#
|
|
93
|
+
#
|
|
94
|
+
# Overrides model and default messages.
|
|
95
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
by:
|
|
2
|
+
# Используется в array.to_sentence
|
|
3
|
+
#
|
|
4
|
+
#
|
|
5
|
+
# Used in array.to_sentence.
|
|
6
|
+
support:
|
|
7
|
+
array:
|
|
8
|
+
# Rails 2.2
|
|
9
|
+
sentence_connector: "и"
|
|
10
|
+
skip_last_comma: true
|
|
11
|
+
|
|
12
|
+
# Rails 2.3
|
|
13
|
+
words_connector: ", "
|
|
14
|
+
two_words_connector: " и "
|
|
15
|
+
last_word_connector: " и "
|
|
16
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# Context-based month name and day name switching for Belorussian
|
|
4
|
+
#
|
|
5
|
+
# Названия месяцев и дней недели в зависимости от контекста ("1 декабря", но "Декабрь 1985")
|
|
6
|
+
{
|
|
7
|
+
:by => {
|
|
8
|
+
:date => {
|
|
9
|
+
:abbr_day_names => lambda { |key, options|
|
|
10
|
+
if options[:format] && options[:format] =~ Belorussian::LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH
|
|
11
|
+
:'date.common_abbr_day_names'
|
|
12
|
+
else
|
|
13
|
+
:'date.standalone_abbr_day_names'
|
|
14
|
+
end
|
|
15
|
+
},
|
|
16
|
+
:day_names => lambda { |key, options|
|
|
17
|
+
if options[:format] && options[:format] =~ Belorussian::LOCALIZE_STANDALONE_DAY_NAMES_MATCH
|
|
18
|
+
:'date.standalone_day_names'
|
|
19
|
+
else
|
|
20
|
+
:'date.common_day_names'
|
|
21
|
+
end
|
|
22
|
+
},
|
|
23
|
+
:abbr_month_names => lambda { |key, options|
|
|
24
|
+
if options[:format] && options[:format] =~ Belorussian::LOCALIZE_ABBR_MONTH_NAMES_MATCH
|
|
25
|
+
:'date.common_abbr_month_names'
|
|
26
|
+
else
|
|
27
|
+
:'date.standalone_abbr_month_names'
|
|
28
|
+
end
|
|
29
|
+
},
|
|
30
|
+
:month_names => lambda { |key, options|
|
|
31
|
+
if options[:format] && options[:format] =~ Belorussian::LOCALIZE_MONTH_NAMES_MATCH
|
|
32
|
+
:'date.common_month_names'
|
|
33
|
+
else
|
|
34
|
+
:'date.standalone_month_names'
|
|
35
|
+
end
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
by:
|
|
2
|
+
date:
|
|
3
|
+
formats:
|
|
4
|
+
# Форматы указываются в виде, поддерживаемом strftime.
|
|
5
|
+
# По умолчанию используется default.
|
|
6
|
+
# Можно добавлять собственные форматы
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
# Use the strftime parameters for formats.
|
|
10
|
+
# When no format has been given, it uses default.
|
|
11
|
+
# You can provide other formats here if you like!
|
|
12
|
+
default: "%d.%m.%Y"
|
|
13
|
+
short: "%d %b"
|
|
14
|
+
long: "%d %B %Y"
|
|
15
|
+
|
|
16
|
+
# Названия дней недели -- контекстные и отдельностоящие
|
|
17
|
+
common_day_names: [воскресенье, понедельник, вторник, среда, четверг, пятница, суббота]
|
|
18
|
+
standalone_day_names: [Воскресенье, Понедельник, Вторник, Среда, Четверг, Пятница, Суббота]
|
|
19
|
+
common_abbr_day_names: [Вс, Пн, Вт, Ср, Чт, Пт, Сб]
|
|
20
|
+
standalone_abbr_day_names: [вс, пн, вт, ср, чт, пт, сб]
|
|
21
|
+
|
|
22
|
+
# Названия месяцев -- сокращенные и полные, плюс отдельностоящие.
|
|
23
|
+
# Не забудьте nil в начале массиве (~)
|
|
24
|
+
#
|
|
25
|
+
#
|
|
26
|
+
# Don't forget the nil at the beginning; there's no such thing as a 0th month
|
|
27
|
+
common_month_names: [~, января, февраля, марта, апреля, мая, июня, июля, августа, сентября, октября, ноября, декабря]
|
|
28
|
+
standalone_month_names: [~, Январь, Февраль, Март, Апрель, Май, Июнь, Июль, Август, Сентябрь, Октябрь, Ноябрь, Декабрь]
|
|
29
|
+
common_abbr_month_names: [~, янв., февр., марта, апр., мая, июня, июля, авг., сент., окт., нояб., дек.]
|
|
30
|
+
standalone_abbr_month_names: [~, янв., февр., март, апр., май, июнь, июль, авг., сент., окт., нояб., дек.]
|
|
31
|
+
|
|
32
|
+
# Порядок компонентов даты для хелперов
|
|
33
|
+
#
|
|
34
|
+
#
|
|
35
|
+
# Used in date_select and datime_select.
|
|
36
|
+
order:
|
|
37
|
+
- :day
|
|
38
|
+
- :month
|
|
39
|
+
- :year
|
|
40
|
+
|
|
41
|
+
time:
|
|
42
|
+
# Форматы времени
|
|
43
|
+
formats:
|
|
44
|
+
default: "%a, %d %b %Y, %H:%M:%S %z"
|
|
45
|
+
short: "%d %b, %H:%M"
|
|
46
|
+
long: "%d %B %Y, %H:%M"
|
|
47
|
+
|
|
48
|
+
# am/pm решено перевести как "утра/вечера" :)
|
|
49
|
+
am: "утра"
|
|
50
|
+
pm: "вечера"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# Правило плюрализации для русского языка, взято из CLDR, http://unicode.org/cldr/
|
|
4
|
+
#
|
|
5
|
+
# Belorussian language pluralization rules, taken from CLDR project, http://unicode.org/cldr/
|
|
6
|
+
#
|
|
7
|
+
# one -> n mod 10 is 1 and n mod 100 is not 11;
|
|
8
|
+
# few -> n mod 10 in 2..4 and n mod 100 not in 12..14;
|
|
9
|
+
# many -> n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14;
|
|
10
|
+
# other -> everything else
|
|
11
|
+
#
|
|
12
|
+
# Пример
|
|
13
|
+
#
|
|
14
|
+
# :one = 1, 21, 31, 41, 51, 61...
|
|
15
|
+
# :few = 2-4, 22-24, 32-34...
|
|
16
|
+
# :many = 0, 5-20, 25-30, 35-40...
|
|
17
|
+
# :other = 1.31, 2.31, 5.31...
|
|
18
|
+
{
|
|
19
|
+
:by => {
|
|
20
|
+
:'i18n' => {
|
|
21
|
+
:plural => {
|
|
22
|
+
:rule => lambda { |n|
|
|
23
|
+
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
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# I18n transliteration delegates to Belorussian::Transliteration (we're unable
|
|
4
|
+
# to use common I18n transliteration tables with Belorussian)
|
|
5
|
+
#
|
|
6
|
+
# Правило транслитерации для I18n использует Belorussian::Transliteration
|
|
7
|
+
# (использовать обычный механизм и таблицу транслитерации I18n с
|
|
8
|
+
# русским языком не получится)
|
|
9
|
+
{
|
|
10
|
+
:by => {
|
|
11
|
+
:i18n => {
|
|
12
|
+
:transliterate => {
|
|
13
|
+
:rule => lambda { |str| Belorussian.transliterate(str) }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
module Belorussian
|
|
4
|
+
# Belorussian transliteration
|
|
5
|
+
#
|
|
6
|
+
# Транслитерация для букв русского алфавита
|
|
7
|
+
module Transliteration
|
|
8
|
+
extend self
|
|
9
|
+
|
|
10
|
+
# Transliteration heavily based on rutils gem by Julian "julik" Tarkhanov and Co.
|
|
11
|
+
# <http://rutils.rubyforge.org/>
|
|
12
|
+
# Cleaned up and optimized.
|
|
13
|
+
|
|
14
|
+
LOWER_SINGLE = {
|
|
15
|
+
"і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e",
|
|
16
|
+
"ї"=>"yi","а"=>"a","б"=>"b",
|
|
17
|
+
"в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
|
|
18
|
+
"з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
|
|
19
|
+
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
|
|
20
|
+
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
|
|
21
|
+
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
|
|
22
|
+
"ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
|
|
23
|
+
}
|
|
24
|
+
LOWER_MULTI = {
|
|
25
|
+
"ье"=>"ie",
|
|
26
|
+
"ьё"=>"ie",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
UPPER_SINGLE = {
|
|
30
|
+
"Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
|
|
31
|
+
"А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
|
|
32
|
+
"Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
|
|
33
|
+
"Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
|
|
34
|
+
"О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
|
|
35
|
+
"У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
|
|
36
|
+
"Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"",
|
|
37
|
+
"Э"=>"E","Ю"=>"YU","Я"=>"YA",
|
|
38
|
+
}
|
|
39
|
+
UPPER_MULTI = {
|
|
40
|
+
"ЬЕ"=>"IE",
|
|
41
|
+
"ЬЁ"=>"IE",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
LOWER = (LOWER_SINGLE.merge(LOWER_MULTI)).freeze
|
|
45
|
+
UPPER = (UPPER_SINGLE.merge(UPPER_MULTI)).freeze
|
|
46
|
+
MULTI_KEYS = (LOWER_MULTI.merge(UPPER_MULTI)).keys.sort_by {|s| s.length}.reverse.freeze
|
|
47
|
+
|
|
48
|
+
# Transliterate a string with belorussian characters
|
|
49
|
+
#
|
|
50
|
+
# Возвращает строку, в которой все буквы русского алфавита заменены на похожую по звучанию латиницу
|
|
51
|
+
def transliterate(str)
|
|
52
|
+
chars = str.scan(%r{#{MULTI_KEYS.join '|'}|\w|.})
|
|
53
|
+
|
|
54
|
+
result = ""
|
|
55
|
+
|
|
56
|
+
chars.each_with_index do |char, index|
|
|
57
|
+
if UPPER.has_key?(char) && LOWER.has_key?(chars[index+1])
|
|
58
|
+
# combined case
|
|
59
|
+
result << UPPER[char].downcase.capitalize
|
|
60
|
+
elsif UPPER.has_key?(char)
|
|
61
|
+
result << UPPER[char]
|
|
62
|
+
elsif LOWER.has_key?(char)
|
|
63
|
+
result << LOWER[char]
|
|
64
|
+
else
|
|
65
|
+
result << char
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
result
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Belorussian do
|
|
6
|
+
describe "with locale" do
|
|
7
|
+
it "should define :'by' LOCALE" do
|
|
8
|
+
Belorussian::LOCALE.should == :'by'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should provide 'locale' proxy" do
|
|
12
|
+
Belorussian.locale.should == Belorussian::LOCALE
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "during i18n initialization" do
|
|
17
|
+
after(:each) do
|
|
18
|
+
I18n.load_path = []
|
|
19
|
+
Belorussian.init_i18n
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should keep existing translations while switching backends" do
|
|
23
|
+
I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'en.yml')
|
|
24
|
+
Belorussian.init_i18n
|
|
25
|
+
I18n.t(:foo, :locale => :'en').should == "bar"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should keep existing :by translations while switching backends" do
|
|
29
|
+
I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'by.yml')
|
|
30
|
+
Belorussian.init_i18n
|
|
31
|
+
I18n.t(:'date.formats.default', :locale => :'by').should == "override"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should NOT set default locale to Belorussian locale" do
|
|
35
|
+
locale = I18n.default_locale
|
|
36
|
+
Belorussian.init_i18n
|
|
37
|
+
I18n.default_locale.should == locale
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "with localize proxy" do
|
|
42
|
+
before(:each) do
|
|
43
|
+
@time = mock(:time)
|
|
44
|
+
@options = { :format => "%d %B %Y" }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
%w(l localize).each do |method|
|
|
48
|
+
it "'#{method}' should call I18n backend localize" do
|
|
49
|
+
I18n.should_receive(:localize).with(@time, @options.merge({ :locale => Belorussian.locale }))
|
|
50
|
+
Belorussian.send(method, @time, @options)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe "with translate proxy" do
|
|
56
|
+
before(:all) do
|
|
57
|
+
@object = :bar
|
|
58
|
+
@options = { :scope => :foo }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
%w(t translate).each do |method|
|
|
62
|
+
it "'#{method}' should call I18n backend translate" do
|
|
63
|
+
I18n.should_receive(:translate).with(@object, @options.merge({ :locale => Belorussian.locale }))
|
|
64
|
+
Belorussian.send(method, @object, @options)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "strftime" do
|
|
70
|
+
before(:each) do
|
|
71
|
+
@time = mock(:time)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should call localize with object and format" do
|
|
75
|
+
format = "%d %B %Y"
|
|
76
|
+
Belorussian.should_receive(:localize).with(@time, { :format => format })
|
|
77
|
+
Belorussian.strftime(@time, format)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should call localize with object and default format when format is not specified" do
|
|
81
|
+
Belorussian.should_receive(:localize).with(@time, { :format => :default })
|
|
82
|
+
Belorussian.strftime(@time)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "with pluralization" do
|
|
87
|
+
%w(p pluralize).each do |method|
|
|
88
|
+
it "'#{method}' should pluralize with variants given" do
|
|
89
|
+
variants = %w(вещь вещи вещей вещи)
|
|
90
|
+
|
|
91
|
+
Belorussian.send(method, 1, *variants).should == "вещь"
|
|
92
|
+
Belorussian.send(method, 2, *variants).should == 'вещи'
|
|
93
|
+
Belorussian.send(method, 3, *variants).should == 'вещи'
|
|
94
|
+
Belorussian.send(method, 5, *variants).should == 'вещей'
|
|
95
|
+
Belorussian.send(method, 10, *variants).should == 'вещей'
|
|
96
|
+
Belorussian.send(method, 21, *variants).should == 'вещь'
|
|
97
|
+
Belorussian.send(method, 29, *variants).should == 'вещей'
|
|
98
|
+
Belorussian.send(method, 129, *variants).should == 'вещей'
|
|
99
|
+
Belorussian.send(method, 131, *variants).should == 'вещь'
|
|
100
|
+
Belorussian.send(method, 3.14, *variants).should == 'вещи'
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should raise an exception when first parameter is not a number" do
|
|
104
|
+
lambda { Belorussian.send(method, nil, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError)
|
|
105
|
+
lambda { Belorussian.send(method, "вещь", "вещь", "вещи", "вещей") }.should raise_error(ArgumentError)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should raise an exception when there are not enough variants" do
|
|
109
|
+
lambda { Belorussian.send(method, 1) }.should raise_error(ArgumentError)
|
|
110
|
+
lambda { Belorussian.send(method, 1, "вещь") }.should raise_error(ArgumentError)
|
|
111
|
+
lambda { Belorussian.send(method, 1, "вещь", "вещи") }.should raise_error(ArgumentError)
|
|
112
|
+
lambda { Belorussian.send(method, 1, "вещь", "вещи", "вещей") }.should_not raise_error(ArgumentError)
|
|
113
|
+
lambda { Belorussian.send(method, 3.14, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError)
|
|
114
|
+
lambda { Belorussian.send(method, 3.14, "вещь", "вещи", "вещей", "вещи") }.should_not raise_error(ArgumentError)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|