r18n-core 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/base/pl.yml +7 -0
- data/lib/r18n-core.rb +21 -1
- data/lib/r18n-core/i18n.rb +3 -9
- data/lib/r18n-core/locale.rb +33 -24
- data/lib/r18n-core/translated_string.rb +6 -2
- data/lib/r18n-core/translation.rb +15 -20
- data/lib/r18n-core/unsupported_locale.rb +59 -0
- data/lib/r18n-core/untranslated.rb +26 -3
- data/lib/r18n-core/version.rb +1 -1
- data/locales/en.yml +0 -2
- data/locales/pl.rb +22 -0
- data/locales/pl.yml +33 -0
- data/spec/i18n_spec.rb +2 -1
- data/spec/locale_spec.rb +9 -13
- data/spec/locales/pl_spec.rb +25 -0
- data/spec/r18n_spec.rb +9 -0
- data/spec/translation_spec.rb +17 -4
- data/spec/translations/general/en.yml +2 -1
- data/spec/translations/general/ru.yml +2 -1
- metadata +30 -25
data/base/pl.yml
ADDED
data/lib/r18n-core.rb
CHANGED
@@ -18,13 +18,14 @@ You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
=end
|
20
20
|
|
21
|
-
$KCODE = 'u'
|
21
|
+
$KCODE = 'u' if '1.8.' == RUBY_VERSION[0..3]
|
22
22
|
|
23
23
|
require 'pathname'
|
24
24
|
|
25
25
|
dir = Pathname(__FILE__).dirname.expand_path + 'r18n-core'
|
26
26
|
require dir + 'version'
|
27
27
|
require dir + 'locale'
|
28
|
+
require dir + 'unsupported_locale'
|
28
29
|
require dir + 'translated_string'
|
29
30
|
require dir + 'untranslated'
|
30
31
|
require dir + 'translation'
|
@@ -41,8 +42,27 @@ module R18n
|
|
41
42
|
def get
|
42
43
|
Thread.current['i18n']
|
43
44
|
end
|
45
|
+
|
46
|
+
# String, which will be print by untranslated items. You can use special
|
47
|
+
# values:
|
48
|
+
# * <tt>%1</tt> – path to untranslated string.
|
49
|
+
# * <tt>%2</tt> – part in path, that exists in translation.
|
50
|
+
# * <tt>%3</tt> – part in path, that isn’t exists in translation.
|
51
|
+
#
|
52
|
+
# For example, if you have in translation only:
|
53
|
+
# user:
|
54
|
+
# login: Login
|
55
|
+
#
|
56
|
+
# And write code:
|
57
|
+
#
|
58
|
+
# R18n.untranslated = '%2[%3]'
|
59
|
+
#
|
60
|
+
# i18n.user.password #=> "user.[password]"
|
61
|
+
attr_accessor :untranslated
|
44
62
|
end
|
45
63
|
|
64
|
+
self.untranslated = '%1'
|
65
|
+
|
46
66
|
module Utils
|
47
67
|
# Recursively hash merge.
|
48
68
|
def self.deep_merge!(a, b)
|
data/lib/r18n-core/i18n.rb
CHANGED
@@ -106,13 +106,7 @@ module R18n
|
|
106
106
|
def initialize(locales, translations_dirs = nil)
|
107
107
|
locales = [locales] if locales.is_a? String
|
108
108
|
|
109
|
-
@locales = locales.map
|
110
|
-
if Locale.exists? locale
|
111
|
-
Locale.load(locale)
|
112
|
-
else
|
113
|
-
locale
|
114
|
-
end
|
115
|
-
end
|
109
|
+
@locales = locales.map { |i| Locale.load(i) }
|
116
110
|
|
117
111
|
locales << @@default
|
118
112
|
if @locales.first.kind_of? Locale
|
@@ -138,8 +132,8 @@ module R18n
|
|
138
132
|
end
|
139
133
|
end
|
140
134
|
|
141
|
-
# Return Hash with titles (or code for
|
142
|
-
#
|
135
|
+
# Return Hash with titles (or code for unsupported locales) for available
|
136
|
+
# translations.
|
143
137
|
def translations
|
144
138
|
Translation.available(@translations_dirs).inject({}) do |all, code|
|
145
139
|
all[code] = if Locale.exists? code
|
data/lib/r18n-core/locale.rb
CHANGED
@@ -67,22 +67,21 @@ module R18n
|
|
67
67
|
File.exists?(File.join(LOCALES_DIR, locale + '.yml'))
|
68
68
|
end
|
69
69
|
|
70
|
-
# Default pluralization rule to translation without locale file
|
71
|
-
def self.default_pluralize(n)
|
72
|
-
n == 0 ? 0 : n == 1 ? 1 : 'n'
|
73
|
-
end
|
74
|
-
|
75
70
|
# Load locale by RFC 3066 +code+
|
76
71
|
def self.load(code)
|
77
72
|
code.delete! '/'
|
78
73
|
code.delete! '\\'
|
79
74
|
code.delete! ';'
|
80
75
|
|
76
|
+
return UnsupportedLocale.new(code) unless exists? code
|
77
|
+
|
81
78
|
data = {}
|
82
79
|
klass = R18n::Locale
|
83
|
-
|
80
|
+
default_loaded = false
|
81
|
+
|
82
|
+
while code and exists? code
|
84
83
|
file = LOCALES_DIR + "#{code}.yml"
|
85
|
-
|
84
|
+
default_loaded = true if I18n.default == code
|
86
85
|
|
87
86
|
if R18n::Locale == klass and File.exists? LOCALES_DIR + "#{code}.rb"
|
88
87
|
require LOCALES_DIR + "#{code}.rb"
|
@@ -94,31 +93,41 @@ module R18n
|
|
94
93
|
data = Utils.deep_merge! loaded, data
|
95
94
|
end
|
96
95
|
|
96
|
+
unless default_loaded
|
97
|
+
code = I18n.default
|
98
|
+
while code and exists? code
|
99
|
+
loaded = YAML.load_file(LOCALES_DIR + "#{code}.yml")
|
100
|
+
code = loaded['include']
|
101
|
+
data = Utils.deep_merge! loaded, data
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
97
105
|
klass.new(data)
|
98
106
|
end
|
107
|
+
|
108
|
+
attr_reader :data
|
99
109
|
|
100
|
-
# Create locale object
|
110
|
+
# Create locale object with locale +data+.
|
101
111
|
#
|
102
112
|
# This is internal a constructor. To load translation use
|
103
113
|
# <tt>R18n::Translation.load(locales, translations_dir)</tt>.
|
104
|
-
def initialize(
|
105
|
-
|
106
|
-
@locale = locale
|
114
|
+
def initialize(data)
|
115
|
+
@data = data
|
107
116
|
end
|
108
117
|
|
109
118
|
# Get information about locale
|
110
119
|
def [](name)
|
111
|
-
@
|
120
|
+
@data[name]
|
112
121
|
end
|
113
122
|
|
114
123
|
# Is another locale has same code
|
115
124
|
def ==(locale)
|
116
|
-
@
|
125
|
+
@data['code'] == locale['code']
|
117
126
|
end
|
118
127
|
|
119
128
|
# Human readable locale code and title
|
120
129
|
def inspect
|
121
|
-
"Locale #{@
|
130
|
+
"Locale #{@data['code']} (#{@data['title']})"
|
122
131
|
end
|
123
132
|
|
124
133
|
# Returns the integer in String form, according to the rules of the locale.
|
@@ -126,7 +135,7 @@ module R18n
|
|
126
135
|
def format_integer(integer)
|
127
136
|
str = integer.to_s
|
128
137
|
str[0] = '−' if 0 > integer # Real typographic minus
|
129
|
-
group = @
|
138
|
+
group = @data['numbers']['group_delimiter']
|
130
139
|
|
131
140
|
str.gsub(/(\d)(?=(\d\d\d)+(?!\d))/) do |match|
|
132
141
|
match + group
|
@@ -136,7 +145,7 @@ module R18n
|
|
136
145
|
# Returns the float in String form, according to the rules of the locale.
|
137
146
|
# It will also put real typographic minus.
|
138
147
|
def format_float(float)
|
139
|
-
decimal = @
|
148
|
+
decimal = @data['numbers']['decimal_separator']
|
140
149
|
self.format_integer(float.to_i) + decimal + float.to_s.split('.').last
|
141
150
|
end
|
142
151
|
|
@@ -150,27 +159,27 @@ module R18n
|
|
150
159
|
def strftime(time, format)
|
151
160
|
if format.is_a? Symbol
|
152
161
|
if :month == format
|
153
|
-
return @
|
162
|
+
return @data['months']['standalone'][time.month - 1]
|
154
163
|
end
|
155
|
-
format = @
|
164
|
+
format = @data['formats'][format.to_s]
|
156
165
|
end
|
157
166
|
|
158
167
|
translated = ''
|
159
168
|
format.scan(/%[EO]?.|./o) do |c|
|
160
169
|
case c.sub(/^%[EO]?(.)$/o, '%\\1')
|
161
170
|
when '%A'
|
162
|
-
translated << @
|
171
|
+
translated << @data['week']['days'][time.wday]
|
163
172
|
when '%a'
|
164
|
-
translated << @
|
173
|
+
translated << @data['week']['abbrs'][time.wday]
|
165
174
|
when '%B'
|
166
|
-
translated << @
|
175
|
+
translated << @data['months']['names'][time.month - 1]
|
167
176
|
when '%b'
|
168
|
-
translated << @
|
177
|
+
translated << @data['months']['abbrs'][time.month - 1]
|
169
178
|
when '%p'
|
170
179
|
translated << if time.hour < 12
|
171
|
-
@
|
180
|
+
@data['time']['am']
|
172
181
|
else
|
173
|
-
@
|
182
|
+
@data['time']['pm']
|
174
183
|
end
|
175
184
|
else
|
176
185
|
translated << c
|
@@ -24,11 +24,15 @@ module R18n
|
|
24
24
|
# String locale
|
25
25
|
attr_reader :locale
|
26
26
|
|
27
|
+
# Path for this translation.
|
28
|
+
attr_reader :path
|
29
|
+
|
27
30
|
# Returns a new string object containing a copy of +str+, which translated
|
28
|
-
# to +locale+
|
29
|
-
def initialize(str, locale)
|
31
|
+
# for +path+ to +locale+
|
32
|
+
def initialize(str, locale, path)
|
30
33
|
super(str)
|
31
34
|
@locale = locale
|
35
|
+
@path = path
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -137,11 +137,7 @@ module R18n
|
|
137
137
|
end
|
138
138
|
translations << translation
|
139
139
|
|
140
|
-
|
141
|
-
Locale.load(locale)
|
142
|
-
else
|
143
|
-
locale
|
144
|
-
end
|
140
|
+
Locale.load(locale)
|
145
141
|
end
|
146
142
|
|
147
143
|
self.new(locales, translations)
|
@@ -158,13 +154,15 @@ module R18n
|
|
158
154
|
@@call_proc
|
159
155
|
end
|
160
156
|
|
161
|
-
# Create translation hash with messages in +translations+ for
|
157
|
+
# Create translation hash for +path+ with messages in +translations+ for
|
158
|
+
# +locales+.
|
162
159
|
#
|
163
160
|
# This is internal a constructor. To load translation use
|
164
161
|
# <tt>R18n::Translation.load(locales, translations_dir)</tt>.
|
165
|
-
def initialize(locales, translations)
|
162
|
+
def initialize(locales, translations, path = '')
|
166
163
|
@locales = locales
|
167
164
|
@translations = translations
|
165
|
+
@path = path
|
168
166
|
end
|
169
167
|
|
170
168
|
# Short and pretty way to get translation by method name. If translation
|
@@ -182,6 +180,8 @@ module R18n
|
|
182
180
|
# Translation can contain variable part. Just set is as <tt>%1</tt>,
|
183
181
|
# <tt>%2</tt>, etc in translations file and set values in next +params+.
|
184
182
|
def [](name, *params)
|
183
|
+
path = @path.empty? ? name : "#{@path}.#{name}"
|
184
|
+
|
185
185
|
@translations.each_with_index do |translation, i|
|
186
186
|
result = translation[name]
|
187
187
|
next if result.nil?
|
@@ -197,16 +197,11 @@ module R18n
|
|
197
197
|
when 'pl'
|
198
198
|
locale = @locales[i]
|
199
199
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
elsif params.first.is_a? Integer
|
206
|
-
params[0] = locale.format_integer(params.first)
|
207
|
-
end
|
208
|
-
else
|
209
|
-
type = Locale.default_pluralize(params.first)
|
200
|
+
type = locale.pluralize(params.first)
|
201
|
+
if params.first.is_a? Float
|
202
|
+
params[0] = locale.format_float(params.first)
|
203
|
+
elsif params.first.is_a? Integer
|
204
|
+
params[0] = locale.format_integer(params.first)
|
210
205
|
end
|
211
206
|
|
212
207
|
type = 'n' if not result.value.include? type
|
@@ -221,17 +216,17 @@ module R18n
|
|
221
216
|
params.each_with_index do |param, i|
|
222
217
|
result.gsub! "%#{i+1}", param.to_s
|
223
218
|
end
|
224
|
-
return TranslatedString.new(result, @locales[i])
|
219
|
+
return TranslatedString.new(result, @locales[i], path)
|
225
220
|
elsif result.is_a? Hash
|
226
221
|
return self.class.new(@locales, @translations.map { |i|
|
227
222
|
i[name] or {}
|
228
|
-
})
|
223
|
+
}, path)
|
229
224
|
else
|
230
225
|
return result.clone
|
231
226
|
end
|
232
227
|
end
|
233
228
|
|
234
|
-
return Untranslated.
|
229
|
+
return Untranslated.new(path, name)
|
235
230
|
end
|
236
231
|
end
|
237
232
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
=begin
|
3
|
+
Locale withou information file to i18n support.
|
4
|
+
|
5
|
+
Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
This program is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
18
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
=end
|
20
|
+
|
21
|
+
module R18n
|
22
|
+
# Locale without information file. Contain only it code, empty title and data
|
23
|
+
# from default locale.
|
24
|
+
class UnsupportedLocale
|
25
|
+
# Create object for unsupported locale with +code+ and load other locale
|
26
|
+
# data from default locale.
|
27
|
+
def initialize(code)
|
28
|
+
@@default_locale ||= Locale.load(I18n.default)
|
29
|
+
@code = code
|
30
|
+
end
|
31
|
+
|
32
|
+
# Human readable locale code and title
|
33
|
+
def inspect
|
34
|
+
"Unsupported locale #{@code}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get information about locale
|
38
|
+
def [](name)
|
39
|
+
case name
|
40
|
+
when 'code'
|
41
|
+
@code
|
42
|
+
when 'title'
|
43
|
+
''
|
44
|
+
else
|
45
|
+
@@default_locale[name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Is another locale has same code
|
50
|
+
def ==(locale)
|
51
|
+
@code == locale['code']
|
52
|
+
end
|
53
|
+
|
54
|
+
# Proxy to default locale object.
|
55
|
+
def method_missing(name, *params)
|
56
|
+
@@default_locale.send(name, *params)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -24,18 +24,41 @@ module R18n
|
|
24
24
|
# Return if translation isn’t exists. Unlike nil, it didn’t raise error when
|
25
25
|
# you try to access for subtranslations.
|
26
26
|
class Untranslated
|
27
|
-
|
27
|
+
# Path to translation.
|
28
|
+
attr_reader :path
|
29
|
+
|
30
|
+
# Path, that isn’t in translation.
|
31
|
+
attr_reader :untranslated_path
|
32
|
+
|
33
|
+
# Path, that exists in translation.
|
34
|
+
attr_reader :translated_path
|
35
|
+
|
36
|
+
def initialize(path, untranslated_path)
|
37
|
+
@path = path
|
38
|
+
@untranslated_path = untranslated_path
|
39
|
+
@translated_path = path[0...(-untranslated_path.length)]
|
40
|
+
end
|
28
41
|
|
29
42
|
def nil?
|
30
43
|
true
|
31
44
|
end
|
32
45
|
|
33
46
|
def method_missing(*params)
|
34
|
-
self
|
47
|
+
self[params.first]
|
35
48
|
end
|
36
49
|
|
37
50
|
def [](*params)
|
38
|
-
|
51
|
+
Untranslated.new("#{@path}.#{params.first}",
|
52
|
+
"#{@untranslated_path}.#{params.first}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
if R18n.untranslated.respond_to? :gsub
|
57
|
+
R18n.untranslated.gsub('%1', @path).gsub('%2', @translated_path).
|
58
|
+
gsub('%3', @untranslated_path)
|
59
|
+
else
|
60
|
+
R18n.untranslated
|
61
|
+
end
|
39
62
|
end
|
40
63
|
end
|
41
64
|
end
|
data/lib/r18n-core/version.rb
CHANGED
data/locales/en.yml
CHANGED
data/locales/pl.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module R18n
|
2
|
+
module Locales
|
3
|
+
class Pl < R18n::Locale
|
4
|
+
def pluralize(n)
|
5
|
+
return 0 if n == 0
|
6
|
+
# 0 - 0
|
7
|
+
# 1 - 1
|
8
|
+
# 2..4 - 2
|
9
|
+
# n
|
10
|
+
|
11
|
+
case n % 10
|
12
|
+
when 1
|
13
|
+
n > 10 ? 'n' : 1
|
14
|
+
when 2..4
|
15
|
+
n % 100 > 10 && n % 100 < 20 ? 'n' : 2
|
16
|
+
else
|
17
|
+
'n'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/locales/pl.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
title: Polski
|
2
|
+
code: pl
|
3
|
+
sublocales: []
|
4
|
+
direction: ltr
|
5
|
+
|
6
|
+
pluralization: "n == 0 ? 0 : n == 1 ? 1 : 'n'"
|
7
|
+
|
8
|
+
week:
|
9
|
+
start: monday
|
10
|
+
days: [Niedziela, Poniedziałek, Wtorek, Sroda, Czwartek, Piątek, Sobota]
|
11
|
+
abbrs: [Niedz, Pon, Wt, Sr, Czw, Pt, Sob]
|
12
|
+
|
13
|
+
months:
|
14
|
+
names: [Stycznia, Lutego, Marca, Kwietnia, Maja, Czerwca, Lipa, Sierpnia, Września, Pażdziernika, Listopada, Grudnia]
|
15
|
+
abbrs: [Sty, Lut, Mar, Kwi, Maj, Cze, Lip, Sie, Wrz, Paź, Lis, Gru]
|
16
|
+
standalone: [Styczen, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Pażdziernik, Listopad, Grudzień]
|
17
|
+
|
18
|
+
time:
|
19
|
+
am: AM
|
20
|
+
pm: PM
|
21
|
+
|
22
|
+
formats:
|
23
|
+
time: "%H:%M"
|
24
|
+
date: "%d/%m/%Y"
|
25
|
+
short_date: "%d %b"
|
26
|
+
long_date: "%d %B, %Y"
|
27
|
+
datetime: "%a %d %b %H:%M:%S %Z %Y"
|
28
|
+
short_datetime: "%d %b %H:%M"
|
29
|
+
long_datetime: "%d %B, %Y %H:%M"
|
30
|
+
|
31
|
+
numbers:
|
32
|
+
decimal_separator: "."
|
33
|
+
group_delimiter: ","
|
data/spec/i18n_spec.rb
CHANGED
@@ -20,7 +20,8 @@ describe R18n::I18n do
|
|
20
20
|
i18n.locales.should == [R18n::Locale.load('en')]
|
21
21
|
|
22
22
|
i18n = R18n::I18n.new(['ru', 'no_LC'], DIR)
|
23
|
-
i18n.locales.should == [R18n::Locale.load('ru'),
|
23
|
+
i18n.locales.should == [R18n::Locale.load('ru'),
|
24
|
+
R18n::UnsupportedLocale.new('no_LC')]
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should return translations dir" do
|
data/spec/locale_spec.rb
CHANGED
@@ -30,12 +30,6 @@ describe R18n::Locale do
|
|
30
30
|
en_US['week'].should == en['week']
|
31
31
|
end
|
32
32
|
|
33
|
-
it "should raise error if locale isn't exists" do
|
34
|
-
lambda {
|
35
|
-
R18n::Locale.load('no_LC')
|
36
|
-
}.should raise_error
|
37
|
-
end
|
38
|
-
|
39
33
|
it "should be equal to another locale with same code" do
|
40
34
|
ru = R18n::Locale.load('ru')
|
41
35
|
en = R18n::Locale.load('en')
|
@@ -60,10 +54,13 @@ describe R18n::Locale do
|
|
60
54
|
locale.pluralize(5).should == 'n'
|
61
55
|
end
|
62
56
|
|
63
|
-
it "should
|
64
|
-
R18n::Locale.
|
65
|
-
R18n::
|
66
|
-
|
57
|
+
it "should use UnsupportedLocale if locale file isn't exists" do
|
58
|
+
locale = R18n::Locale.load('no_LC')
|
59
|
+
locale.should be_a(R18n::UnsupportedLocale)
|
60
|
+
locale['code'].should == 'no_LC'
|
61
|
+
locale['title'].should be_empty
|
62
|
+
locale['direction'].should == 'ltr'
|
63
|
+
locale.pluralize(5).should == 'n'
|
67
64
|
end
|
68
65
|
|
69
66
|
it "should format number in local traditions" do
|
@@ -89,9 +86,8 @@ describe R18n::Locale do
|
|
89
86
|
end
|
90
87
|
|
91
88
|
it "should delete slashed from locale for security reasons" do
|
92
|
-
|
93
|
-
|
94
|
-
}.should raise_error
|
89
|
+
locale = R18n::Locale.load('../spec/translations/general/en')
|
90
|
+
locale.should be_a(R18n::UnsupportedLocale)
|
95
91
|
end
|
96
92
|
|
97
93
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "..", "locales", "pl")
|
3
|
+
|
4
|
+
describe R18n::Locales::Pl do
|
5
|
+
it "should use Polish pluralization" do
|
6
|
+
ru = R18n::Locale.load 'pl'
|
7
|
+
ru.pluralize(0).should == 0
|
8
|
+
|
9
|
+
ru.pluralize(1).should == 1
|
10
|
+
ru.pluralize(21).should == 'n'
|
11
|
+
ru.pluralize(101).should == 'n'
|
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
|
+
ru.pluralize(112).should == 'n'
|
24
|
+
end
|
25
|
+
end
|
data/spec/r18n_spec.rb
CHANGED
@@ -21,5 +21,14 @@ describe R18n do
|
|
21
21
|
:b => { :ba => 1, :bb => 2, :bc => 2 },
|
22
22
|
:c => 2 }
|
23
23
|
end
|
24
|
+
|
25
|
+
it "should set untranslated format" do
|
26
|
+
translation = R18n::Translation.load('en', DIR)
|
27
|
+
R18n.untranslated = nil
|
28
|
+
translation.in.not.to_s.should be_nil
|
29
|
+
|
30
|
+
R18n.untranslated = '%1 %2[%3]'
|
31
|
+
translation.in.not.to_s.should == 'in.not in.[not]'
|
32
|
+
end
|
24
33
|
|
25
34
|
end
|
data/spec/translation_spec.rb
CHANGED
@@ -35,21 +35,34 @@ describe R18n::Translation do
|
|
35
35
|
|
36
36
|
it "should load use hierarchical translations" do
|
37
37
|
translation = R18n::Translation.load(['ru', 'en'], DIR)
|
38
|
-
translation.in.another.should == 'Иерархический'
|
39
|
-
translation['in']['another'].should == 'Иерархический'
|
38
|
+
translation.in.another.level.should == 'Иерархический'
|
39
|
+
translation['in']['another']['level'].should == 'Иерархический'
|
40
40
|
translation.only.english.should == 'Only in English'
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should save path for translation" do
|
44
|
+
translation = R18n::Translation.load('en', DIR)
|
45
|
+
|
46
|
+
translation.in.another.level.path.should == 'in.another.level'
|
47
|
+
|
48
|
+
translation.in.another.not.exists.path.should == 'in.another.not.exists'
|
49
|
+
translation.in.another.not.exists.untranslated_path.should == 'not.exists'
|
50
|
+
translation.in.another.not.exists.translated_path.should == 'in.another.'
|
51
|
+
|
52
|
+
translation.not.untranslated_path.should == 'not'
|
53
|
+
translation.not.translated_path.should == ''
|
54
|
+
end
|
42
55
|
|
43
56
|
it "should return string with locale info" do
|
44
57
|
translation = R18n::Translation.load(['no_LC', 'en'], DIR)
|
45
|
-
translation.one.locale.should == 'no_LC'
|
58
|
+
translation.one.locale.should == R18n::UnsupportedLocale.new('no_LC')
|
46
59
|
translation.two.locale.should == R18n::Locale.load('en')
|
47
60
|
end
|
48
61
|
|
49
62
|
it "should load translations from several dirs" do
|
50
63
|
translation = R18n::Translation.load(['no_LC', 'en'], [TWO, DIR])
|
51
64
|
translation.in.two.should == 'Two'
|
52
|
-
translation.in.another.should == 'Hierarchical'
|
65
|
+
translation.in.another.level.should == 'Hierarchical'
|
53
66
|
end
|
54
67
|
|
55
68
|
it "should use extension translations" do
|
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.2.
|
4
|
+
version: 0.2.3
|
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: 2009-
|
12
|
+
date: 2009-07-22 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,28 +23,32 @@ extra_rdoc_files:
|
|
23
23
|
- README.rdoc
|
24
24
|
- LICENSE
|
25
25
|
files:
|
26
|
-
- base/ru.yml
|
27
|
-
- base/kk.yml
|
28
|
-
- base/fr.yml
|
29
|
-
- base/en.yml
|
30
26
|
- base/de.yml
|
27
|
+
- base/en.yml
|
28
|
+
- base/fr.yml
|
29
|
+
- base/pl.yml
|
30
|
+
- base/ru.yml
|
31
31
|
- base/eo.yml
|
32
|
+
- base/kk.yml
|
33
|
+
- lib/r18n-core.rb
|
32
34
|
- lib/r18n-core
|
35
|
+
- lib/r18n-core/unsupported_locale.rb
|
36
|
+
- lib/r18n-core/translation.rb
|
33
37
|
- lib/r18n-core/untranslated.rb
|
34
38
|
- lib/r18n-core/i18n.rb
|
39
|
+
- lib/r18n-core/translated_string.rb
|
35
40
|
- lib/r18n-core/locale.rb
|
36
41
|
- lib/r18n-core/version.rb
|
37
|
-
-
|
38
|
-
-
|
39
|
-
- lib/r18n-core.rb
|
42
|
+
- locales/de.yml
|
43
|
+
- locales/en.yml
|
40
44
|
- locales/ru.rb
|
41
|
-
- locales/
|
42
|
-
- locales/kk.yml
|
45
|
+
- locales/pl.rb
|
43
46
|
- locales/fr.yml
|
47
|
+
- locales/pl.yml
|
48
|
+
- locales/ru.yml
|
44
49
|
- locales/en_US.yml
|
45
|
-
- locales/en.yml
|
46
|
-
- locales/de.yml
|
47
50
|
- locales/eo.yml
|
51
|
+
- locales/kk.yml
|
48
52
|
- LICENSE
|
49
53
|
- README.rdoc
|
50
54
|
has_rdoc: true
|
@@ -74,21 +78,22 @@ signing_key:
|
|
74
78
|
specification_version: 2
|
75
79
|
summary: I18n tool to translate your Ruby application.
|
76
80
|
test_files:
|
77
|
-
- spec/locales
|
78
|
-
- spec/locales/ru_spec.rb
|
79
|
-
- spec/spec_helper.rb
|
80
81
|
- spec/translations
|
81
|
-
- spec/translations/two
|
82
|
-
- spec/translations/two/fr.yml
|
83
|
-
- spec/translations/two/en.yml
|
84
|
-
- spec/translations/general
|
85
|
-
- spec/translations/general/ru.yml
|
86
|
-
- spec/translations/general/no_LC.yml
|
87
|
-
- spec/translations/general/en.yml
|
88
82
|
- spec/translations/extension
|
89
83
|
- spec/translations/extension/no_TR.yml
|
90
84
|
- spec/translations/extension/en.yml
|
91
|
-
- spec/
|
92
|
-
- spec/
|
85
|
+
- spec/translations/general
|
86
|
+
- spec/translations/general/en.yml
|
87
|
+
- spec/translations/general/no_LC.yml
|
88
|
+
- spec/translations/general/ru.yml
|
89
|
+
- spec/translations/two
|
90
|
+
- spec/translations/two/en.yml
|
91
|
+
- spec/translations/two/fr.yml
|
92
|
+
- spec/locales
|
93
|
+
- spec/locales/pl_spec.rb
|
94
|
+
- spec/locales/ru_spec.rb
|
93
95
|
- spec/locale_spec.rb
|
94
96
|
- spec/i18n_spec.rb
|
97
|
+
- spec/r18n_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/translation_spec.rb
|