r18n-core 0.1.1 → 0.2
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/README.rdoc +1 -1
- data/base/fr.yml +7 -0
- data/base/kk.yml +7 -0
- data/lib/r18n-core.rb +15 -0
- data/lib/r18n-core/i18n.rb +13 -12
- data/lib/r18n-core/locale.rb +38 -19
- data/lib/r18n-core/translation.rb +22 -16
- data/lib/r18n-core/untranslated.rb +40 -0
- data/lib/r18n-core/version.rb +1 -1
- data/locales/en.yml +1 -2
- data/locales/eo.yml +5 -8
- data/locales/fr.yml +31 -0
- data/locales/kk.yml +31 -0
- data/locales/ru.rb +17 -0
- data/locales/ru.yml +5 -8
- data/spec/i18n_spec.rb +4 -4
- data/spec/locale_spec.rb +23 -17
- data/spec/locales/ru_spec.rb +24 -0
- data/spec/r18n_spec.rb +13 -0
- data/spec/spec_helper.rb +3 -13
- data/spec/translation_spec.rb +12 -3
- data/spec/translations/two/en.yml +3 -0
- data/spec/translations/two/fr.yml +0 -0
- metadata +13 -2
data/README.rdoc
CHANGED
@@ -26,7 +26,7 @@ add your locale, please write me to andrey@sitnik.ru.
|
|
26
26
|
|
27
27
|
To get information about locale create R18n::Locale instance:
|
28
28
|
|
29
|
-
locale = R18n::Locale.
|
29
|
+
locale = R18n::Locale.load('en')
|
30
30
|
|
31
31
|
You can get from locale:
|
32
32
|
* Locale title and RFC 3066 code:
|
data/base/fr.yml
ADDED
data/base/kk.yml
ADDED
data/lib/r18n-core.rb
CHANGED
@@ -25,6 +25,7 @@ dir = Pathname(__FILE__).dirname.expand_path + 'r18n-core'
|
|
25
25
|
require dir + 'version'
|
26
26
|
require dir + 'locale'
|
27
27
|
require dir + 'translated_string'
|
28
|
+
require dir + 'untranslated'
|
28
29
|
require dir + 'translation'
|
29
30
|
require dir + 'i18n'
|
30
31
|
|
@@ -40,4 +41,18 @@ module R18n
|
|
40
41
|
Thread.current['i18n']
|
41
42
|
end
|
42
43
|
end
|
44
|
+
|
45
|
+
module Utils
|
46
|
+
# Recursively hash merge
|
47
|
+
def self.deep_merge!(a, b)
|
48
|
+
b.each_pair do |name, value|
|
49
|
+
if Hash == a[name].class
|
50
|
+
self.deep_merge!(a[name], value)
|
51
|
+
else
|
52
|
+
a[name] = value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
a
|
56
|
+
end
|
57
|
+
end
|
43
58
|
end
|
data/lib/r18n-core/i18n.rb
CHANGED
@@ -89,31 +89,32 @@ module R18n
|
|
89
89
|
# User locales, ordered by priority
|
90
90
|
attr_reader :locales
|
91
91
|
|
92
|
-
#
|
93
|
-
attr_reader :
|
92
|
+
# Dirs with translations files
|
93
|
+
attr_reader :translations_dirs
|
94
94
|
|
95
95
|
# First locale with locale file
|
96
96
|
attr_reader :locale
|
97
97
|
|
98
|
-
# Create i18n for +locales+ with translations from +
|
98
|
+
# Create i18n for +locales+ with translations from +translations_dirs+ and
|
99
99
|
# locales data. Translations will be also loaded for default locale,
|
100
100
|
# +sublocales+ from first in +locales+ and general languages for dialects
|
101
101
|
# (it will load +fr+ for +fr_CA+ too).
|
102
102
|
#
|
103
103
|
# +Locales+ must be a locale code (RFC 3066) or array, ordered by priority.
|
104
|
-
|
104
|
+
# +Translations_dirs+ must be a string with path or array.
|
105
|
+
def initialize(locales, translations_dirs = nil)
|
105
106
|
locales = locales.to_a if String == locales.class
|
106
107
|
|
107
108
|
@locales = locales.map do |locale|
|
108
109
|
if Locale.exists? locale
|
109
|
-
Locale.
|
110
|
+
Locale.load(locale)
|
110
111
|
else
|
111
112
|
locale
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
115
116
|
locales << @@default
|
116
|
-
if
|
117
|
+
if @locales.first.kind_of? Locale
|
117
118
|
locales += @locales.first['sublocales']
|
118
119
|
end
|
119
120
|
locales.each_with_index do |locale, i|
|
@@ -125,23 +126,23 @@ module R18n
|
|
125
126
|
|
126
127
|
locales.each do |locale|
|
127
128
|
if Locale.exists? locale
|
128
|
-
@locale = Locale.
|
129
|
+
@locale = Locale.load(locale)
|
129
130
|
break
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
133
|
-
if not
|
134
|
-
@
|
135
|
-
@translation = Translation.load(locales, @
|
134
|
+
if not translations_dirs.nil?
|
135
|
+
@translations_dirs = translations_dirs
|
136
|
+
@translation = Translation.load(locales, @translations_dirs)
|
136
137
|
end
|
137
138
|
end
|
138
139
|
|
139
140
|
# Return Hash with titles (or code for translation without locale file) of
|
140
141
|
# available translations.
|
141
142
|
def translations
|
142
|
-
Translation.available(@
|
143
|
+
Translation.available(@translations_dirs).inject({}) do |all, code|
|
143
144
|
all[code] = if Locale.exists? code
|
144
|
-
Locale.
|
145
|
+
Locale.load(code)['title']
|
145
146
|
else
|
146
147
|
code
|
147
148
|
end
|
data/lib/r18n-core/locale.rb
CHANGED
@@ -36,7 +36,7 @@ module R18n
|
|
36
36
|
#
|
37
37
|
# Get Russian locale and print it information
|
38
38
|
#
|
39
|
-
# ru = R18n::Locale.
|
39
|
+
# ru = R18n::Locale.load('ru')
|
40
40
|
# ru['title'] #=> "Русский"
|
41
41
|
# ru['code'] #=> "ru"
|
42
42
|
# ru['direction'] #=> "ltr"
|
@@ -47,7 +47,6 @@ module R18n
|
|
47
47
|
# * +title+: locale name on it language;
|
48
48
|
# * +direction+: writing direction, +ltr+ or +rtl+ (for Arabic and Hebrew);
|
49
49
|
# * +sublocales+: often known languages for people from this locale;
|
50
|
-
# * +pluralization+: function to get pluralization type for +n+ items;
|
51
50
|
# * +include+: locale code to include it data, optional.
|
52
51
|
#
|
53
52
|
# You can see more available data about locale in samples in
|
@@ -61,32 +60,49 @@ module R18n
|
|
61
60
|
File.basename(i, '.yml')
|
62
61
|
end
|
63
62
|
end
|
64
|
-
|
63
|
+
|
65
64
|
# Is +locale+ has info file
|
66
65
|
def self.exists?(locale)
|
67
66
|
File.exists?(File.join(LOCALES_DIR, locale + '.yml'))
|
68
67
|
end
|
69
|
-
|
68
|
+
|
70
69
|
# Default pluralization rule to translation without locale file
|
71
70
|
def self.default_pluralize(n)
|
72
71
|
n == 0 ? 0 : n == 1 ? 1 : 'n'
|
73
72
|
end
|
74
73
|
|
75
74
|
# Load locale by RFC 3066 +code+
|
76
|
-
def
|
75
|
+
def self.load(code)
|
77
76
|
code.delete! '/'
|
78
77
|
code.delete! '\\'
|
78
|
+
code.delete! ';'
|
79
79
|
|
80
|
-
|
80
|
+
data = {}
|
81
|
+
klass = R18n::Locale
|
81
82
|
while code
|
82
83
|
file = LOCALES_DIR + "#{code}.yml"
|
83
84
|
raise "Locale #{code} isn't exists" if not File.exists? file
|
85
|
+
|
86
|
+
if R18n::Locale == klass and File.exists? LOCALES_DIR + "#{code}.rb"
|
87
|
+
require LOCALES_DIR + "#{code}.rb"
|
88
|
+
klass = eval 'R18n::Locales::' + code.capitalize
|
89
|
+
end
|
90
|
+
|
84
91
|
loaded = YAML.load_file(file)
|
85
|
-
@locale = loaded.merge @locale
|
86
92
|
code = loaded['include']
|
93
|
+
data = Utils.deep_merge! loaded, data
|
87
94
|
end
|
88
95
|
|
89
|
-
|
96
|
+
klass.new(data)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Create locale object hash with +locale+ data.
|
100
|
+
#
|
101
|
+
# This is internal a constructor. To load translation use
|
102
|
+
# <tt>R18n::Translation.load(locales, translations_dir)</tt>.
|
103
|
+
def initialize(locale)
|
104
|
+
p 1 if String == locale.class
|
105
|
+
@locale = locale
|
90
106
|
end
|
91
107
|
|
92
108
|
# Get information about locale
|
@@ -111,14 +127,8 @@ module R18n
|
|
111
127
|
str[0] = '−' if 0 > number # Real typographic minus
|
112
128
|
group = @locale['numbers']['group_delimiter']
|
113
129
|
|
114
|
-
|
115
|
-
|
116
|
-
match + group
|
117
|
-
end
|
118
|
-
else
|
119
|
-
str.gsub(/(\d)(?=(\d\d\d)+(?!\d))/) do |match|
|
120
|
-
match + group
|
121
|
-
end
|
130
|
+
str.gsub(/(\d)(?=(\d\d\d)+(?!\d))/) do |match|
|
131
|
+
match + group
|
122
132
|
end
|
123
133
|
end
|
124
134
|
|
@@ -168,8 +178,17 @@ module R18n
|
|
168
178
|
time.strftime(translated)
|
169
179
|
end
|
170
180
|
|
171
|
-
# Return pluralization type for +n+ items.
|
172
|
-
#
|
173
|
-
def pluralize(n)
|
181
|
+
# Return pluralization type for +n+ items. This is simple form. For special
|
182
|
+
# cases you can replace it in locale’s class.
|
183
|
+
def pluralize(n)
|
184
|
+
case n
|
185
|
+
when 0
|
186
|
+
0
|
187
|
+
when 1
|
188
|
+
1
|
189
|
+
else
|
190
|
+
'n'
|
191
|
+
end
|
192
|
+
end
|
174
193
|
end
|
175
194
|
end
|
@@ -105,33 +105,39 @@ module R18n
|
|
105
105
|
@@extension_translations
|
106
106
|
end
|
107
107
|
|
108
|
-
# Return available translations in +
|
109
|
-
def self.available(
|
110
|
-
|
108
|
+
# Return available translations in +dirs+
|
109
|
+
def self.available(dirs)
|
110
|
+
if Array == dirs.class
|
111
|
+
return dirs.inject([]) do |available, i|
|
112
|
+
available |= self.available(i)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
Dir.glob(File.join(dirs, '*.yml')).map do |i|
|
111
117
|
File.basename(i, '.yml')
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
115
|
-
# Load all available translations for +locales+. +
|
116
|
-
# with one user locale or array with many.
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
+
# Load all available translations for +locales+. +Locales+ may be a string
|
122
|
+
# with one user locale or array with many. +Dirs+ may be an array or
|
123
|
+
# a string with path to dir with translations.
|
124
|
+
def self.load(locales, dirs)
|
125
|
+
locales = Array(locales) & self.available(dirs)
|
126
|
+
dirs = @@extension_translations + Array(dirs)
|
121
127
|
|
122
128
|
translations = []
|
123
129
|
locales.map! do |locale|
|
124
130
|
translation = {}
|
125
|
-
|
131
|
+
dirs.each do |dir|
|
126
132
|
file = File.join(dir, "#{locale}.yml")
|
127
|
-
|
133
|
+
if File.exists? file
|
134
|
+
Utils.deep_merge! translation, YAML::load_file(file)
|
135
|
+
end
|
128
136
|
end
|
129
|
-
file = File.join(translations_dir, "#{locale}.yml")
|
130
|
-
translation.merge! YAML::load_file(file)
|
131
137
|
translations << translation
|
132
138
|
|
133
139
|
if Locale.exists? locale
|
134
|
-
Locale.
|
140
|
+
Locale.load(locale)
|
135
141
|
else
|
136
142
|
locale
|
137
143
|
end
|
@@ -185,7 +191,7 @@ module R18n
|
|
185
191
|
if @@call_proc
|
186
192
|
return eval("proc {#{result.value}}").call(*params)
|
187
193
|
else
|
188
|
-
return
|
194
|
+
return result.value
|
189
195
|
end
|
190
196
|
when 'pl'
|
191
197
|
locale = @locales[i]
|
@@ -217,7 +223,7 @@ module R18n
|
|
217
223
|
end
|
218
224
|
end
|
219
225
|
|
220
|
-
return
|
226
|
+
return Untranslated.instance
|
221
227
|
end
|
222
228
|
end
|
223
229
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
=begin
|
2
|
+
Untranslation string for i18n support.
|
3
|
+
|
4
|
+
Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
5
|
+
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
|
11
|
+
This program is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
17
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
=end
|
19
|
+
|
20
|
+
require 'singleton'
|
21
|
+
|
22
|
+
module R18n
|
23
|
+
# Return if translation isn’t exists. Unlike nil, it didn’t raise error when
|
24
|
+
# you try to access for subtranslations.
|
25
|
+
class Untranslated
|
26
|
+
include ::Singleton
|
27
|
+
|
28
|
+
def nil?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(*params)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](*params)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/r18n-core/version.rb
CHANGED
data/locales/en.yml
CHANGED
data/locales/eo.yml
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
title: Esperanto
|
2
2
|
code: eo
|
3
3
|
sublocales: [en]
|
4
|
-
direction: ltr
|
5
|
-
|
6
|
-
pluralization: "n == 0 ? 0 : n == 1 ? 1 : 'n'"
|
7
|
-
|
4
|
+
direction: ltr
|
5
|
+
|
8
6
|
week:
|
9
7
|
start: monday
|
10
8
|
days: [dimanĉo, lundo, mardo, merkredo, ĵaŭdo, vendredo, sabato]
|
@@ -26,9 +24,8 @@ formats:
|
|
26
24
|
long_date: "la %d-a de %B de %Y"
|
27
25
|
datetime: "%a, %d %b %Y, %H:%M:%S %Z"
|
28
26
|
short_datetime: "%d %b, %H:%M"
|
29
|
-
long_datetime: "la %d-a de %B de %Y, %H:%M"
|
30
|
-
|
27
|
+
long_datetime: "la %d-a de %B de %Y, %H:%M"
|
28
|
+
|
31
29
|
numbers:
|
32
|
-
|
33
|
-
decimal_separator: "."
|
30
|
+
decimal_separator: "."
|
34
31
|
group_delimiter: " "
|
data/locales/fr.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
title: Français
|
2
|
+
code: fr
|
3
|
+
sublocales: [en]
|
4
|
+
direction: ltr
|
5
|
+
|
6
|
+
week:
|
7
|
+
start: monday
|
8
|
+
days: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi]
|
9
|
+
abbrs: [dim, lun, mar, mer, jeu, ven, sam]
|
10
|
+
|
11
|
+
months:
|
12
|
+
names: [janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre]
|
13
|
+
abbrs: [jan, fév, mar, avr, mai, jun, jui, aoû, sep, oct, nov, déc]
|
14
|
+
standalone: [Janvier, Février, Mars, Avril, Mai, Juin, Juillet, Août, Septembre, Octobre, Novembre, Décembre]
|
15
|
+
|
16
|
+
time:
|
17
|
+
am: AM
|
18
|
+
pm: PM
|
19
|
+
|
20
|
+
formats:
|
21
|
+
time: "%H:%M"
|
22
|
+
date: "%d/%m/%Y"
|
23
|
+
short_date: "%d %b"
|
24
|
+
long_date: "%d %B %Y"
|
25
|
+
datetime: "%a %d %b %Y %H:%M:%S %Z"
|
26
|
+
short_datetime: "%d %b %H:%M"
|
27
|
+
long_datetime: "%d %B %Y %H:%M"
|
28
|
+
|
29
|
+
numbers:
|
30
|
+
decimal_separator: ","
|
31
|
+
group_delimiter: " "
|
data/locales/kk.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
title: Қазақша
|
2
|
+
code: kk
|
3
|
+
sublocales: [ru, en]
|
4
|
+
direction: ltr
|
5
|
+
|
6
|
+
week:
|
7
|
+
start: monday
|
8
|
+
days: [Жексенбі, Дүйсенбі, Сейсенбі, Сәрсенбі, Бейсенбі, Жұма, Сенбі]
|
9
|
+
abbrs: [Жк, Дс, Сс, Ср, Бс, Жм, Сн]
|
10
|
+
|
11
|
+
months:
|
12
|
+
names: [қаңтар, ақпан, наурыз, сәуір, мамыр, маусым, шілде, тамыз, қырқүйек, қазан, қараша, желтоқсан]
|
13
|
+
abbrs: [қаң, ақп, нау, сәу, мам, мау, шіл, там, қыр, қаз, қар, жел]
|
14
|
+
standalone: [Қаңтар, Ақпан, Наурыз, Сәуір, Мамыр, Маусым, Шілде, Тамыз, Қыркүйек, Қазан, Қараша, Желтоқсан]
|
15
|
+
|
16
|
+
time:
|
17
|
+
am: " ертеңің"
|
18
|
+
pm: " кештің"
|
19
|
+
|
20
|
+
formats:
|
21
|
+
time: "%H:%M"
|
22
|
+
date: "%Y-%m-%d"
|
23
|
+
short_date: "%b %d"
|
24
|
+
long_date: "%Y жылы %B %d-і"
|
25
|
+
datetime: "%a, %Y ж. %b %d-і, %H:%M:%S %Z"
|
26
|
+
short_datetime: "%b %d, %H:%M"
|
27
|
+
long_datetime: "%Y жылы %B %d-і, %H:%M"
|
28
|
+
|
29
|
+
numbers:
|
30
|
+
decimal_separator: ","
|
31
|
+
group_delimiter: " "
|
data/locales/ru.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module R18n
|
2
|
+
module Locales
|
3
|
+
class Ru < R18n::Locale
|
4
|
+
def pluralize(n)
|
5
|
+
if 0 == n
|
6
|
+
0
|
7
|
+
elsif 1 == n % 10 and 11 != n % 100
|
8
|
+
1
|
9
|
+
elsif 2 <= n % 10 and 4 >= n % 10 and (10 > n % 100 or 20 <= n % 100)
|
10
|
+
2
|
11
|
+
else
|
12
|
+
'n'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/locales/ru.yml
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
title: Русский
|
2
2
|
code: ru
|
3
3
|
sublocales: [en]
|
4
|
-
direction: ltr
|
5
|
-
|
6
|
-
pluralization: "n==0 ? 0 : n%10==1 && n%100!=11 ? 1 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 'n'"
|
7
|
-
|
4
|
+
direction: ltr
|
5
|
+
|
8
6
|
week:
|
9
7
|
start: monday
|
10
8
|
days: [Воскресенье, Понедельник, Вторник, Среда, Четверг, Пятница, Суббота]
|
@@ -26,9 +24,8 @@ formats:
|
|
26
24
|
long_date: "%d %B %Y"
|
27
25
|
datetime: "%a, %d %b %Y, %H:%M:%S %Z"
|
28
26
|
short_datetime: "%d %b, %H:%M"
|
29
|
-
long_datetime: "%d %B %Y, %H:%M"
|
30
|
-
|
27
|
+
long_datetime: "%d %B %Y, %H:%M"
|
28
|
+
|
31
29
|
numbers:
|
32
|
-
|
33
|
-
decimal_separator: ","
|
30
|
+
decimal_separator: ","
|
34
31
|
group_delimiter: " "
|
data/spec/i18n_spec.rb
CHANGED
@@ -16,15 +16,15 @@ describe R18n::I18n do
|
|
16
16
|
|
17
17
|
it "should load locales" do
|
18
18
|
i18n = R18n::I18n.new('en', DIR)
|
19
|
-
i18n.locales.should == [R18n::Locale.
|
19
|
+
i18n.locales.should == [R18n::Locale.load('en')]
|
20
20
|
|
21
21
|
i18n = R18n::I18n.new(['ru', 'no_LC'], DIR)
|
22
|
-
i18n.locales.should == [R18n::Locale.
|
22
|
+
i18n.locales.should == [R18n::Locale.load('ru'), 'no_LC']
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should return translations dir" do
|
26
26
|
i18n = R18n::I18n.new('en', DIR)
|
27
|
-
i18n.
|
27
|
+
i18n.translations_dirs.expand_path.to_s.should == DIR.expand_path.to_s
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should load translations" do
|
@@ -57,7 +57,7 @@ describe R18n::I18n do
|
|
57
57
|
|
58
58
|
it "should return first locale with locale file" do
|
59
59
|
i18n = R18n::I18n.new(['no_LC', 'ru', 'en'], DIR)
|
60
|
-
i18n.locale.should == R18n::Locale.
|
60
|
+
i18n.locale.should == R18n::Locale.load('ru')
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should localize objects" do
|
data/spec/locale_spec.rb
CHANGED
@@ -8,14 +8,22 @@ describe R18n::Locale do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should load locale" do
|
11
|
-
locale = R18n::Locale.
|
11
|
+
locale = R18n::Locale.load('ru')
|
12
12
|
locale['code'].should == 'ru'
|
13
13
|
locale['title'].should == 'Русский'
|
14
14
|
end
|
15
|
+
|
16
|
+
it "should use locale's class" do
|
17
|
+
ru = R18n::Locale.load('ru')
|
18
|
+
ru.class.should == R18n::Locales::Ru
|
19
|
+
|
20
|
+
en = R18n::Locale.load('en')
|
21
|
+
en.class.should == R18n::Locale
|
22
|
+
end
|
15
23
|
|
16
24
|
it "should include locale by +include+ option" do
|
17
|
-
en_US = R18n::Locale.
|
18
|
-
en = R18n::Locale.
|
25
|
+
en_US = R18n::Locale.load('en_US')
|
26
|
+
en = R18n::Locale.load('en')
|
19
27
|
en_US['title'].should == 'English (US)'
|
20
28
|
en['title'].should == 'English'
|
21
29
|
en_US['week'].should == en['week']
|
@@ -23,28 +31,29 @@ describe R18n::Locale do
|
|
23
31
|
|
24
32
|
it "should raise error if locale isn't exists" do
|
25
33
|
lambda {
|
26
|
-
R18n::Locale.
|
34
|
+
R18n::Locale.load('no_LC')
|
27
35
|
}.should raise_error
|
28
36
|
end
|
29
37
|
|
30
38
|
it "should be equal to another locale with same code" do
|
31
|
-
ru = R18n::Locale.
|
32
|
-
en = R18n::Locale.
|
33
|
-
another_en = R18n::Locale.
|
39
|
+
ru = R18n::Locale.load('ru')
|
40
|
+
en = R18n::Locale.load('en')
|
41
|
+
another_en = R18n::Locale.load('en')
|
34
42
|
en.should_not == ru
|
35
43
|
en.should == another_en
|
36
44
|
end
|
37
45
|
|
38
46
|
it "should print human readable representation" do
|
39
|
-
R18n::Locale.
|
47
|
+
R18n::Locale.load('ru').inspect.should == 'Locale ru (Русский)'
|
40
48
|
end
|
41
49
|
|
42
50
|
it "should return all available locales" do
|
43
|
-
R18n::Locale.available.
|
51
|
+
R18n::Locale.available.class.should == Array
|
52
|
+
R18n::Locale.available.should_not be_empty
|
44
53
|
end
|
45
54
|
|
46
55
|
it "should return pluralization type by elements count" do
|
47
|
-
locale = R18n::Locale.
|
56
|
+
locale = R18n::Locale.load('en')
|
48
57
|
locale.pluralize(0).should == 0
|
49
58
|
locale.pluralize(1).should == 1
|
50
59
|
locale.pluralize(5).should == 'n'
|
@@ -57,20 +66,17 @@ describe R18n::Locale do
|
|
57
66
|
end
|
58
67
|
|
59
68
|
it "should format number in local traditions" do
|
60
|
-
locale = R18n::Locale.
|
69
|
+
locale = R18n::Locale.load('en')
|
61
70
|
locale.format_number(-123456789).should == "−123,456,789"
|
62
|
-
|
63
|
-
locale = FakeIndianLocale.new # While indian locale isn’t exists
|
64
|
-
locale.format_number(-123456789).should == "−12,34,56,789"
|
65
71
|
end
|
66
72
|
|
67
73
|
it "should format float in local traditions" do
|
68
|
-
locale = R18n::Locale.
|
74
|
+
locale = R18n::Locale.load('en')
|
69
75
|
locale.format_float(-12345.67).should == "−12,345.67"
|
70
76
|
end
|
71
77
|
|
72
78
|
it "should translate month, week days and am/pm names in strftime" do
|
73
|
-
locale = R18n::Locale.
|
79
|
+
locale = R18n::Locale.load('ru')
|
74
80
|
time = Time.at(0).utc
|
75
81
|
|
76
82
|
locale.strftime(time, '%a %A').should == 'Чтв Четверг'
|
@@ -83,7 +89,7 @@ describe R18n::Locale do
|
|
83
89
|
|
84
90
|
it "should delete slashed from locale for security reasons" do
|
85
91
|
lambda {
|
86
|
-
R18n::Locale.
|
92
|
+
R18n::Locale.load('../spec/translations/general/en')
|
87
93
|
}.should raise_error
|
88
94
|
end
|
89
95
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "..", "locales", "ru")
|
3
|
+
|
4
|
+
describe R18n::Locales::Ru do
|
5
|
+
it "should use Russian pluralization" do
|
6
|
+
ru = R18n::Locale.load 'ru'
|
7
|
+
ru.pluralize(0).should == 0
|
8
|
+
|
9
|
+
ru.pluralize(1).should == 1
|
10
|
+
ru.pluralize(21).should == 1
|
11
|
+
ru.pluralize(101).should == 1
|
12
|
+
|
13
|
+
ru.pluralize(2).should == 2
|
14
|
+
ru.pluralize(4).should == 2
|
15
|
+
ru.pluralize(22).should == 2
|
16
|
+
ru.pluralize(102).should == 2
|
17
|
+
|
18
|
+
ru.pluralize(5).should == 'n'
|
19
|
+
ru.pluralize(11).should == 'n'
|
20
|
+
ru.pluralize(12).should == 'n'
|
21
|
+
ru.pluralize(57).should == 'n'
|
22
|
+
ru.pluralize(111).should == 'n'
|
23
|
+
end
|
24
|
+
end
|
data/spec/r18n_spec.rb
CHANGED
@@ -8,4 +8,17 @@ describe R18n do
|
|
8
8
|
R18n.get.should == i18n
|
9
9
|
end
|
10
10
|
|
11
|
+
it "should merge hash recursively" do
|
12
|
+
a = { :a => 1,
|
13
|
+
:b => {:ba => 1, :bb => 1},
|
14
|
+
:c => 1 }
|
15
|
+
b = { :b => {:bb => 2, :bc => 2},
|
16
|
+
:c => 2 }
|
17
|
+
|
18
|
+
R18n::Utils.deep_merge! a, b
|
19
|
+
a.should == { :a => 1,
|
20
|
+
:b => { :ba => 1, :bb => 2, :bc => 2 },
|
21
|
+
:c => 2 }
|
22
|
+
end
|
23
|
+
|
11
24
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../lib/r18n-core')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@locale['numbers'] = {
|
7
|
-
'separation' => 'indian',
|
8
|
-
'decimal_separator' => '.',
|
9
|
-
'group_delimiter' => ','
|
10
|
-
}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
DIR = Pathname(__FILE__).dirname + 'translations/general'
|
15
|
-
EXT = Pathname(__FILE__).dirname + 'translations/extension'
|
3
|
+
DIR = Pathname(__FILE__).dirname + 'translations/general' unless defined? DIR
|
4
|
+
TWO = Pathname(__FILE__).dirname + 'translations/two' unless defined? TWO
|
5
|
+
EXT = Pathname(__FILE__).dirname + 'translations/extension' unless defined? EXT
|
data/spec/translation_spec.rb
CHANGED
@@ -4,6 +4,8 @@ describe R18n::Translation do
|
|
4
4
|
|
5
5
|
it "should return all available translations" do
|
6
6
|
R18n::Translation.available(DIR).sort.should == ['en', 'no_LC', 'ru']
|
7
|
+
R18n::Translation.available([TWO, DIR]).sort.should == [
|
8
|
+
'en', 'fr', 'no_LC', 'ru']
|
7
9
|
end
|
8
10
|
|
9
11
|
it "should load translations" do
|
@@ -20,7 +22,8 @@ describe R18n::Translation do
|
|
20
22
|
|
21
23
|
it "should return nil if translation isn't found" do
|
22
24
|
translation = R18n::Translation.load('en', DIR)
|
23
|
-
translation.
|
25
|
+
translation.not.exists.should be_nil
|
26
|
+
translation['not']['exists'].should be_nil
|
24
27
|
end
|
25
28
|
|
26
29
|
it "should can use params in translation" do
|
@@ -39,7 +42,13 @@ describe R18n::Translation do
|
|
39
42
|
it "should return string with locale info" do
|
40
43
|
translation = R18n::Translation.load(['no_LC', 'en'], DIR)
|
41
44
|
translation.one.locale.should == 'no_LC'
|
42
|
-
translation.two.locale.should == R18n::Locale.
|
45
|
+
translation.two.locale.should == R18n::Locale.load('en')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should load translations from several dirs" do
|
49
|
+
translation = R18n::Translation.load(['no_LC', 'en'], [TWO, DIR])
|
50
|
+
translation.in.two.should == 'Two'
|
51
|
+
translation.in.another.should == 'Hierarchical'
|
43
52
|
end
|
44
53
|
|
45
54
|
it "should use extension translations" do
|
@@ -66,7 +75,7 @@ describe R18n::Translation do
|
|
66
75
|
translation = R18n::Translation.load('en', DIR)
|
67
76
|
R18n::Translation.call_proc = false
|
68
77
|
R18n::Translation.call_proc.should be_false
|
69
|
-
translation.sum(2, 3).should
|
78
|
+
translation.sum(2, 3).should == '|x, y| x + y'
|
70
79
|
R18n::Translation.call_proc = true
|
71
80
|
end
|
72
81
|
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey "A.I." Sitnik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-06 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,9 +23,11 @@ extra_rdoc_files:
|
|
23
23
|
- README.rdoc
|
24
24
|
- LICENSE
|
25
25
|
files:
|
26
|
+
- base/kk.yml
|
26
27
|
- base/ru.yml
|
27
28
|
- base/eo.yml
|
28
29
|
- base/en.yml
|
30
|
+
- base/fr.yml
|
29
31
|
- lib/r18n-core.rb
|
30
32
|
- lib/r18n-core
|
31
33
|
- lib/r18n-core/translation.rb
|
@@ -33,10 +35,14 @@ files:
|
|
33
35
|
- lib/r18n-core/locale.rb
|
34
36
|
- lib/r18n-core/version.rb
|
35
37
|
- lib/r18n-core/i18n.rb
|
38
|
+
- lib/r18n-core/untranslated.rb
|
36
39
|
- locales/en_US.yml
|
40
|
+
- locales/kk.yml
|
37
41
|
- locales/ru.yml
|
42
|
+
- locales/ru.rb
|
38
43
|
- locales/eo.yml
|
39
44
|
- locales/en.yml
|
45
|
+
- locales/fr.yml
|
40
46
|
- LICENSE
|
41
47
|
- Rakefile
|
42
48
|
- README.rdoc
|
@@ -70,6 +76,8 @@ test_files:
|
|
70
76
|
- spec/spec_helper.rb
|
71
77
|
- spec/translation_spec.rb
|
72
78
|
- spec/i18n_spec.rb
|
79
|
+
- spec/locales
|
80
|
+
- spec/locales/ru_spec.rb
|
73
81
|
- spec/translations
|
74
82
|
- spec/translations/general
|
75
83
|
- spec/translations/general/ru.yml
|
@@ -78,5 +86,8 @@ test_files:
|
|
78
86
|
- spec/translations/extension
|
79
87
|
- spec/translations/extension/no_TR.yml
|
80
88
|
- spec/translations/extension/en.yml
|
89
|
+
- spec/translations/two
|
90
|
+
- spec/translations/two/en.yml
|
91
|
+
- spec/translations/two/fr.yml
|
81
92
|
- spec/r18n_spec.rb
|
82
93
|
- spec/locale_spec.rb
|