russian 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +44 -0
- data/Rakefile +55 -0
- data/TODO +11 -0
- data/init.rb +3 -0
- data/lib/russian.rb +91 -0
- data/lib/russian/action_view_ext/helpers/date_helper.rb +90 -0
- data/lib/russian/active_record_ext/custom_error_message.rb +33 -0
- data/lib/russian/backend/advanced.rb +104 -0
- data/lib/russian/locale/actionview.yml +113 -0
- data/lib/russian/locale/activerecord.yml +48 -0
- data/lib/russian/locale/activesupport.yml +5 -0
- data/lib/russian/locale/datetime.yml +29 -0
- data/lib/russian/locale/pluralize.rb +22 -0
- data/lib/vendor/i18n/MIT-LICENSE +20 -0
- data/lib/vendor/i18n/README.textile +18 -0
- data/lib/vendor/i18n/i18n.gemspec +24 -0
- data/lib/vendor/i18n/lib/i18n.rb +180 -0
- data/lib/vendor/i18n/lib/i18n/backend/simple.rb +192 -0
- data/lib/vendor/i18n/lib/i18n/exceptions.rb +53 -0
- data/lib/vendor/i18n/test/all.rb +5 -0
- data/lib/vendor/i18n/test/i18n_exceptions_test.rb +100 -0
- data/lib/vendor/i18n/test/i18n_test.rb +125 -0
- data/lib/vendor/i18n/test/locale/en-US.rb +1 -0
- data/lib/vendor/i18n/test/locale/en-US.yml +3 -0
- data/lib/vendor/i18n/test/simple_backend_test.rb +473 -0
- data/spec/i18n/locale/datetime_spec.rb +91 -0
- data/spec/i18n/locale/pluralization_spec.rb +20 -0
- data/spec/russian_spec.rb +141 -0
- data/spec/spec_helper.rb +5 -0
- metadata +100 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
ru-RU:
|
2
|
+
number:
|
3
|
+
# Used in number_with_delimiter()
|
4
|
+
# These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
|
5
|
+
format:
|
6
|
+
# Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
|
7
|
+
separator: "."
|
8
|
+
# Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
|
9
|
+
delimiter: " "
|
10
|
+
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
|
11
|
+
precision: 3
|
12
|
+
|
13
|
+
# Used in number_to_currency()
|
14
|
+
currency:
|
15
|
+
format:
|
16
|
+
# Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
|
17
|
+
format: "%n %u"
|
18
|
+
unit: "руб."
|
19
|
+
# These three are to override number.format and are optional
|
20
|
+
separator: "."
|
21
|
+
delimiter: " "
|
22
|
+
precision: 2
|
23
|
+
|
24
|
+
# Used in number_to_percentage()
|
25
|
+
percentage:
|
26
|
+
format:
|
27
|
+
# These three are to override number.format and are optional
|
28
|
+
# separator:
|
29
|
+
delimiter: ""
|
30
|
+
precision: 2
|
31
|
+
|
32
|
+
# Used in number_to_precision()
|
33
|
+
precision:
|
34
|
+
format:
|
35
|
+
# These three are to override number.format and are optional
|
36
|
+
# separator:
|
37
|
+
delimiter: ""
|
38
|
+
# precision:
|
39
|
+
|
40
|
+
# Used in number_to_human_size()
|
41
|
+
human:
|
42
|
+
format:
|
43
|
+
# These three are to override number.format and are optional
|
44
|
+
# separator:
|
45
|
+
delimiter: ""
|
46
|
+
precision: 1
|
47
|
+
|
48
|
+
# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
|
49
|
+
datetime:
|
50
|
+
distance_in_words:
|
51
|
+
half_a_minute: "меньше минуты"
|
52
|
+
less_than_x_seconds:
|
53
|
+
one: "меньше секунды"
|
54
|
+
few: "меньше {{count}} секунд"
|
55
|
+
many: "меньше {{count}} секунд"
|
56
|
+
other: "меньше {{count}} секунд"
|
57
|
+
x_seconds:
|
58
|
+
one: "1 секунда"
|
59
|
+
few: "{{count}} секунды"
|
60
|
+
many: "{{count}} секунд"
|
61
|
+
other: "{{count}} секунды"
|
62
|
+
less_than_x_minutes:
|
63
|
+
one: "меньше минуты"
|
64
|
+
few: "меньше {{count}} минут"
|
65
|
+
many: "меньше {{count}} минут"
|
66
|
+
other: "меньше {{count}} минут"
|
67
|
+
x_minutes:
|
68
|
+
one: "1 минуту"
|
69
|
+
few: "{{count}} минуты"
|
70
|
+
many: "{{count}} минут"
|
71
|
+
other: "{{count}} минуты"
|
72
|
+
about_x_hours:
|
73
|
+
one: "около часа"
|
74
|
+
few: "около {{count}} часов"
|
75
|
+
many: "около {{count}} часов"
|
76
|
+
other: "около {{count}} часов"
|
77
|
+
x_days:
|
78
|
+
one: "1 день"
|
79
|
+
few: "{{count}} дня"
|
80
|
+
many: "{{count}} дней"
|
81
|
+
other: "{{count}} дня"
|
82
|
+
about_x_months:
|
83
|
+
one: "около 1 месяца"
|
84
|
+
few: "около {{count}} месяцев"
|
85
|
+
many: "около {{count}} месяцев"
|
86
|
+
other: "около {{count}} месяцев"
|
87
|
+
x_months:
|
88
|
+
one: "1 месяц"
|
89
|
+
few: "{{count}} месяца"
|
90
|
+
many: "{{count}} месяцев"
|
91
|
+
other: "{{count}} месяца"
|
92
|
+
about_x_years:
|
93
|
+
one: "около 1 года"
|
94
|
+
few: "около {{count}} лет"
|
95
|
+
many: "около {{count}} лет"
|
96
|
+
other: "около {{count}} лет"
|
97
|
+
over_x_years:
|
98
|
+
one: "больше 1 года"
|
99
|
+
few: "больше {{count}} лет"
|
100
|
+
many: "больше {{count}} лет"
|
101
|
+
other: "больше {{count}} лет"
|
102
|
+
|
103
|
+
activerecord:
|
104
|
+
errors:
|
105
|
+
template:
|
106
|
+
header:
|
107
|
+
one: "{{model}} не удалось сохранить из-за 1 ошибки"
|
108
|
+
few: "{{model}} не удалось сохранить из-за {{count}} ошибок"
|
109
|
+
many: "{{model}} не удалось сохранить из-за {{count}} ошибок"
|
110
|
+
other: "{{model}} не удалось сохранить из-за {{count}} ошибок"
|
111
|
+
# The variable :count is also available
|
112
|
+
body: "Проблемы возникли со следующими полями:"
|
113
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
ru-RU:
|
2
|
+
activerecord:
|
3
|
+
errors:
|
4
|
+
# The values :model, :attribute and :value are always available for interpolation
|
5
|
+
# The value :count is available when applicable. Can be used for pluralization.
|
6
|
+
#
|
7
|
+
# You can use ^-prefixed messages as well to get rid of human attribute name appearing
|
8
|
+
# before your message in validation messages.
|
9
|
+
messages:
|
10
|
+
inclusion: "имеет непредусмотренное значение"
|
11
|
+
exclusion: "имеет зарезервированное значение"
|
12
|
+
invalid: "имеет неверное значение"
|
13
|
+
confirmation: "не совпадает с подтверждением"
|
14
|
+
accepted: "нужно подтвердить"
|
15
|
+
empty: "не может быть пустым"
|
16
|
+
blank: "не может быть пустым"
|
17
|
+
too_long:
|
18
|
+
one: "слишком большой длины (допустимая длина - менее 1 символа)"
|
19
|
+
few: "слишком большой длины (допустимая длина - менее {{count}} символов)"
|
20
|
+
many: "слишком большой длины (допустимая длина - менее {{count}} символов)"
|
21
|
+
other: "слишком большой длины (допустимая длина - менее {{count}} символов)"
|
22
|
+
too_short:
|
23
|
+
one: "недостаточной длины (допустимая длина - более 1 символа)"
|
24
|
+
few: "недостаточной длины (допустимая длина - более {{count}} символов)"
|
25
|
+
many: "недостаточной длины (допустимая длина - более {{count}} символов)"
|
26
|
+
other: "недостаточной длины (допустимая длина - более {{count}} символов)"
|
27
|
+
wrong_length:
|
28
|
+
one: "неверной длины (допустимая длина - ровно 1 символ)"
|
29
|
+
few: "неверной длины (допустимая длина - ровно {{count}} символа)"
|
30
|
+
many: "неверной длины (допустимая длина - ровно {{count}} символов)"
|
31
|
+
other: "неверной длины (допустимая длина - ровно {{count}} символа)"
|
32
|
+
taken: "уже существует"
|
33
|
+
not_a_number: "не является числом"
|
34
|
+
greater_than: "может иметь значение большее {{count}}"
|
35
|
+
greater_than_or_equal_to: "может иметь значение большее или равное {{count}}"
|
36
|
+
equal_to: "может иметь лишь значение, равное {{count}}"
|
37
|
+
less_than: "может иметь значение меньше чем {{count}}"
|
38
|
+
less_than_or_equal_to: "может иметь значение меньшее или равное {{count}}"
|
39
|
+
odd: "может иметь лишь четное значение"
|
40
|
+
even: "может иметь лишь нечетное значение"
|
41
|
+
# Append your own errors here or at the model/attributes scope.
|
42
|
+
|
43
|
+
models:
|
44
|
+
# Overrides default messages
|
45
|
+
|
46
|
+
attributes:
|
47
|
+
# Overrides model and default messages.
|
48
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
ru-RU:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
# Use the strftime parameters for formats.
|
5
|
+
# When no format has been given, it uses default.
|
6
|
+
# You can provide other formats here if you like!
|
7
|
+
default: "%d.%m.%Y"
|
8
|
+
short: "%d %b"
|
9
|
+
long: "%d %B %Y"
|
10
|
+
|
11
|
+
day_names: [воскресенье, понедельник, вторник, среда, четверг, пятница, суббота]
|
12
|
+
standalone_day_names: [Воскресенье, Понедельник, Вторник, Среда, Четверг, Пятница, Суббота]
|
13
|
+
abbr_day_names: [Вс, Пн, Вт, Ср, Чт, Пт, Сб]
|
14
|
+
|
15
|
+
# Don't forget the nil at the beginning; there's no such thing as a 0th month
|
16
|
+
month_names: [~, января, февраля, марта, апреля, мая, июня, июля, августа, сентября, октября, ноября, декабря]
|
17
|
+
standalone_month_names: [~, Январь, Февраль, Март, Апрель, Май, Июнь, Июль, Август, Сентябрь, Октябрь, Ноябрь, Декабрь]
|
18
|
+
abbr_month_names: [~, янв., февр., марта, апр., мая, июня, июля, авг., сент., окт., нояб., дек.]
|
19
|
+
standalone_abbr_month_names: [~, янв., февр., март, апр., май, июнь, июль, авг., сент., окт., нояб., дек.]
|
20
|
+
# Used in date_select and datime_select.
|
21
|
+
order: [ :day, :month, :year ]
|
22
|
+
|
23
|
+
time:
|
24
|
+
formats:
|
25
|
+
default: "%a, %d %b %Y, %H:%M:%S %z"
|
26
|
+
short: "%d %b, %H:%M"
|
27
|
+
long: "%d %B %Y, %H:%M"
|
28
|
+
am: "утра"
|
29
|
+
pm: "вечера"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
:'ru-RU' => {
|
3
|
+
:pluralize => lambda { |n|
|
4
|
+
# Russian language pluralization rules, taken from CLDR project, http://unicode.org/cldr/
|
5
|
+
#
|
6
|
+
# one -> n mod 10 is 1 and n mod 100 is not 11;
|
7
|
+
# few -> n mod 10 in 2..4 and n mod 100 not in 12..14;
|
8
|
+
# many -> n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14;
|
9
|
+
# other -> everything else
|
10
|
+
if n.modulo(10) == 1 && n.modulo(100) != 11
|
11
|
+
:one
|
12
|
+
elsif (n.modulo(10) >=2 && n.modulo(10) <= 4) && (n.modulo(100) >=12 && n.modulo(100) <= 14)
|
13
|
+
:few
|
14
|
+
elsif n.modulo(10) == 0 || (n.modulo(10) >=5 && n.modulo(10) <= 9) ||
|
15
|
+
(n.modulo(100) >= 11 && n.modulo(100) <= 14)
|
16
|
+
:many
|
17
|
+
else
|
18
|
+
:other
|
19
|
+
end
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 The Ruby I18n team
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
h1. Ruby I18n gem
|
2
|
+
|
3
|
+
I18n and localization solution for Ruby.
|
4
|
+
|
5
|
+
h2. Authors
|
6
|
+
|
7
|
+
* "Matt Aimonetti":http://railsontherun.com
|
8
|
+
* "Sven Fuchs":http://www.artweb-design.de
|
9
|
+
* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
|
10
|
+
* "Saimon Moore":http://saimonmoore.net
|
11
|
+
* "Stephan Soller":http://www.arkanis-development.de
|
12
|
+
|
13
|
+
h2. License
|
14
|
+
|
15
|
+
MIT License. See the included MIT-LICENCE file.
|
16
|
+
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "i18n"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2008-06-13"
|
5
|
+
s.summary = "Internationalization for Ruby"
|
6
|
+
s.email = "rails-patch-i18n@googlegroups.com"
|
7
|
+
s.homepage = "http://groups.google.com/group/rails-patch-i18n"
|
8
|
+
s.description = "Add Internationalization to your Ruby application."
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ['Sven Fuchs', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
|
11
|
+
s.files = [
|
12
|
+
"lib/i18n/backend/minimal.rb",
|
13
|
+
"lib/i18n/core_ext.rb",
|
14
|
+
"lib/i18n/localization.rb",
|
15
|
+
"lib/i18n/translation.rb",
|
16
|
+
"lib/i18n.rb",
|
17
|
+
"LICENSE",
|
18
|
+
"README",
|
19
|
+
"spec/core_ext_spec.rb",
|
20
|
+
"spec/i18n_spec.rb",
|
21
|
+
"spec/spec.opts",
|
22
|
+
"spec/spec_helper.rb"
|
23
|
+
]
|
24
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# Authors:: Matt Aimonetti (http://railsontherun.com/),
|
2
|
+
# Sven Fuchs (http://www.artweb-design.de),
|
3
|
+
# Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey),
|
4
|
+
# Saimon Moore (http://saimonmoore.net),
|
5
|
+
# Stephan Soller (http://www.arkanis-development.de/)
|
6
|
+
# Copyright:: Copyright (c) 2008 The Ruby i18n Team
|
7
|
+
# License:: MIT
|
8
|
+
require 'i18n/backend/simple'
|
9
|
+
require 'i18n/exceptions'
|
10
|
+
|
11
|
+
module I18n
|
12
|
+
@@backend = nil
|
13
|
+
@@default_locale = 'en-US'
|
14
|
+
@@exception_handler = :default_exception_handler
|
15
|
+
|
16
|
+
class << self
|
17
|
+
# Returns the current backend. Defaults to +Backend::Simple+.
|
18
|
+
def backend
|
19
|
+
@@backend ||= Backend::Simple.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sets the current backend. Used to set a custom backend.
|
23
|
+
def backend=(backend)
|
24
|
+
@@backend = backend
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the current default locale. Defaults to 'en-US'
|
28
|
+
def default_locale
|
29
|
+
@@default_locale
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sets the current default locale. Used to set a custom default locale.
|
33
|
+
def default_locale=(locale)
|
34
|
+
@@default_locale = locale
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the current locale. Defaults to I18n.default_locale.
|
38
|
+
def locale
|
39
|
+
Thread.current[:locale] ||= default_locale
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
|
43
|
+
def locale=(locale)
|
44
|
+
Thread.current[:locale] = locale
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sets the exception handler.
|
48
|
+
def exception_handler=(exception_handler)
|
49
|
+
@@exception_handler = exception_handler
|
50
|
+
end
|
51
|
+
|
52
|
+
# Allows client libraries to pass arguments that specify a source for
|
53
|
+
# translation data to be loaded by the backend. The backend defines
|
54
|
+
# acceptable sources.
|
55
|
+
# E.g. the provided SimpleBackend accepts a list of paths to translation
|
56
|
+
# files which are either named *.rb and contain plain Ruby Hashes or are
|
57
|
+
# named *.yml and contain YAML data.)
|
58
|
+
def load_translations(*args)
|
59
|
+
backend.load_translations(*args)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Translates, pluralizes and interpolates a given key using a given locale,
|
63
|
+
# scope, and default, as well as interpolation values.
|
64
|
+
#
|
65
|
+
# *LOOKUP*
|
66
|
+
#
|
67
|
+
# Translation data is organized as a nested hash using the upper-level keys
|
68
|
+
# as namespaces. <em>E.g.</em>, ActionView ships with the translation:
|
69
|
+
# <tt>:date => {:formats => {:short => "%b %d"}}</tt>.
|
70
|
+
#
|
71
|
+
# Translations can be looked up at any level of this hash using the key argument
|
72
|
+
# and the scope option. <em>E.g.</em>, in this example <tt>I18n.t :date</tt>
|
73
|
+
# returns the whole translations hash <tt>{:formats => {:short => "%b %d"}}</tt>.
|
74
|
+
#
|
75
|
+
# Key can be either a single key or a dot-separated key (both Strings and Symbols
|
76
|
+
# work). <em>E.g.</em>, the short format can be looked up using both:
|
77
|
+
# I18n.t 'date.formats.short'
|
78
|
+
# I18n.t :'date.formats.short'
|
79
|
+
#
|
80
|
+
# Scope can be either a single key, a dot-separated key or an array of keys
|
81
|
+
# or dot-separated keys. Keys and scopes can be combined freely. So these
|
82
|
+
# examples will all look up the same short date format:
|
83
|
+
# I18n.t 'date.formats.short'
|
84
|
+
# I18n.t 'formats.short', :scope => 'date'
|
85
|
+
# I18n.t 'short', :scope => 'date.formats'
|
86
|
+
# I18n.t 'short', :scope => %w(date formats)
|
87
|
+
#
|
88
|
+
# *INTERPOLATION*
|
89
|
+
#
|
90
|
+
# Translations can contain interpolation variables which will be replaced by
|
91
|
+
# values passed to #translate as part of the options hash, with the keys matching
|
92
|
+
# the interpolation variable names.
|
93
|
+
#
|
94
|
+
# <em>E.g.</em>, with a translation <tt>:foo => "foo {{bar}}"</tt> the option
|
95
|
+
# value for the key +bar+ will be interpolated into the translation:
|
96
|
+
# I18n.t :foo, :bar => 'baz' # => 'foo baz'
|
97
|
+
#
|
98
|
+
# *PLURALIZATION*
|
99
|
+
#
|
100
|
+
# Translation data can contain pluralized translations. Pluralized translations
|
101
|
+
# are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
|
102
|
+
#
|
103
|
+
# Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
|
104
|
+
# pluralization rules. Other algorithms can be supported by custom backends.
|
105
|
+
#
|
106
|
+
# This returns the singular version of a pluralized translation:
|
107
|
+
# I18n.t :foo, :count => 1 # => 'Foo'
|
108
|
+
#
|
109
|
+
# These both return the plural version of a pluralized translation:
|
110
|
+
# I18n.t :foo, :count => 0 # => 'Foos'
|
111
|
+
# I18n.t :foo, :count => 2 # => 'Foos'
|
112
|
+
#
|
113
|
+
# The <tt>:count</tt> option can be used both for pluralization and interpolation.
|
114
|
+
# <em>E.g.</em>, with the translation
|
115
|
+
# <tt>:foo => ['{{count}} foo', '{{count}} foos']</tt>, count will
|
116
|
+
# be interpolated to the pluralized translation:
|
117
|
+
# I18n.t :foo, :count => 1 # => '1 foo'
|
118
|
+
#
|
119
|
+
# *DEFAULTS*
|
120
|
+
#
|
121
|
+
# This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
|
122
|
+
# I18n.t :foo, :default => 'default'
|
123
|
+
#
|
124
|
+
# This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
|
125
|
+
# translation for <tt>:foo</tt> was found:
|
126
|
+
# I18n.t :foo, :default => :bar
|
127
|
+
#
|
128
|
+
# Returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt>
|
129
|
+
# or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
|
130
|
+
# I18n.t :foo, :default => [:bar, 'default']
|
131
|
+
#
|
132
|
+
# <b>BULK LOOKUP</b>
|
133
|
+
#
|
134
|
+
# This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
|
135
|
+
# I18n.t [:foo, :bar]
|
136
|
+
#
|
137
|
+
# Can be used with dot-separated nested keys:
|
138
|
+
# I18n.t [:'baz.foo', :'baz.bar']
|
139
|
+
#
|
140
|
+
# Which is the same as using a scope option:
|
141
|
+
# I18n.t [:foo, :bar], :scope => :baz
|
142
|
+
def translate(key, options = {})
|
143
|
+
locale = options.delete(:locale) || I18n.locale
|
144
|
+
backend.translate locale, key, options
|
145
|
+
rescue I18n::ArgumentError => e
|
146
|
+
raise e if options[:raise]
|
147
|
+
send @@exception_handler, e, locale, key, options
|
148
|
+
end
|
149
|
+
alias :t :translate
|
150
|
+
|
151
|
+
# Localizes certain objects, such as dates and numbers to local formatting.
|
152
|
+
def localize(object, options = {})
|
153
|
+
locale = options[:locale] || I18n.locale
|
154
|
+
format = options[:format] || :default
|
155
|
+
backend.localize(locale, object, format)
|
156
|
+
end
|
157
|
+
alias :l :localize
|
158
|
+
|
159
|
+
protected
|
160
|
+
# Handles exceptions raised in the backend. All exceptions except for
|
161
|
+
# MissingTranslationData exceptions are re-raised. When a MissingTranslationData
|
162
|
+
# was caught and the option :raise is not set the handler returns an error
|
163
|
+
# message string containing the key/scope.
|
164
|
+
def default_exception_handler(exception, locale, key, options)
|
165
|
+
return exception.message if MissingTranslationData === exception
|
166
|
+
raise exception
|
167
|
+
end
|
168
|
+
|
169
|
+
# Merges the given locale, key and scope into a single array of keys.
|
170
|
+
# Splits keys that contain dots into multiple keys. Makes sure all
|
171
|
+
# keys are Symbols.
|
172
|
+
def normalize_translation_keys(locale, key, scope)
|
173
|
+
keys = [locale] + Array(scope) + [key]
|
174
|
+
keys = keys.map{|k| k.to_s.split(/\./) }
|
175
|
+
keys.flatten.map{|k| k.to_sym}
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|