r18n-core 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/r18n-core.rb CHANGED
@@ -32,22 +32,22 @@ require dir + 'i18n'
32
32
 
33
33
  module R18n
34
34
  class << self
35
- # Set <tt>i18n</tt> object to current thread
35
+ # Set I18n object to current thread.
36
36
  def set(i18n)
37
37
  Thread.current['i18n'] = i18n
38
38
  end
39
39
 
40
- # Get I18n object for current thread
40
+ # Get I18n object for current thread.
41
41
  def get
42
42
  Thread.current['i18n']
43
43
  end
44
44
  end
45
45
 
46
46
  module Utils
47
- # Recursively hash merge
47
+ # Recursively hash merge.
48
48
  def self.deep_merge!(a, b)
49
49
  b.each_pair do |name, value|
50
- if Hash == a[name].class
50
+ if a[name].is_a? Hash
51
51
  self.deep_merge!(a[name], value)
52
52
  else
53
53
  a[name] = value
@@ -104,7 +104,7 @@ module R18n
104
104
  # +Locales+ must be a locale code (RFC 3066) or array, ordered by priority.
105
105
  # +Translations_dirs+ must be a string with path or array.
106
106
  def initialize(locales, translations_dirs = nil)
107
- locales = [locales] if String == locales.class
107
+ locales = [locales] if locales.is_a? String
108
108
 
109
109
  @locales = locales.map do |locale|
110
110
  if Locale.exists? locale
@@ -160,14 +160,14 @@ module R18n
160
160
  # <tt>:short_datetime</tt> or <tt>:long_datetime</tt>). Without format it
161
161
  # use <tt>:datetime</tt> for Time and DateTime and <tt>:date</tt> for Date.
162
162
  def localize(object, format = nil)
163
- if Fixnum == object.class or Bignum == object.class
164
- locale.format_number(object)
165
- elsif Float == object.class
163
+ if object.is_a? Integer
164
+ locale.format_integer(object)
165
+ elsif object.is_a? Float
166
166
  locale.format_float(object)
167
- elsif Time == object.class or DateTime == object.class
167
+ elsif object.is_a? Time or object.is_a? DateTime
168
168
  format = :datetime if format.nil?
169
169
  locale.strftime(object, format)
170
- elsif Date == object.class
170
+ elsif object.is_a? Date
171
171
  format = :date if format.nil?
172
172
  locale.strftime(object, format)
173
173
  end
@@ -181,7 +181,7 @@ module R18n
181
181
  # Translation can contain variable part. Just set is as <tt>%1</tt>,
182
182
  # <tt>%2</tt>, etc in translations file and set values as methods params.
183
183
  def method_missing(name, *params)
184
- self[name.to_s, *params]
184
+ @translation[name.to_s, *params]
185
185
  end
186
186
 
187
187
  # Return translation with special +name+.
@@ -102,7 +102,7 @@ module R18n
102
102
  # This is internal a constructor. To load translation use
103
103
  # <tt>R18n::Translation.load(locales, translations_dir)</tt>.
104
104
  def initialize(locale)
105
- p 1 if String == locale.class
105
+ p 1 if locale.is_a? String
106
106
  @locale = locale
107
107
  end
108
108
 
@@ -123,9 +123,9 @@ module R18n
123
123
 
124
124
  # Returns the integer in String form, according to the rules of the locale.
125
125
  # It will also put real typographic minus.
126
- def format_number(number)
127
- str = number.to_s
128
- str[0] = '−' if 0 > number # Real typographic minus
126
+ def format_integer(integer)
127
+ str = integer.to_s
128
+ str[0] = '−' if 0 > integer # Real typographic minus
129
129
  group = @locale['numbers']['group_delimiter']
130
130
 
131
131
  str.gsub(/(\d)(?=(\d\d\d)+(?!\d))/) do |match|
@@ -137,7 +137,7 @@ module R18n
137
137
  # It will also put real typographic minus.
138
138
  def format_float(float)
139
139
  decimal = @locale['numbers']['decimal_separator']
140
- self.format_number(float.to_i) + decimal + float.to_s.split('.').last
140
+ self.format_integer(float.to_i) + decimal + float.to_s.split('.').last
141
141
  end
142
142
 
143
143
  # Same that <tt>Time.strftime</tt>, but translate months and week days
@@ -148,7 +148,7 @@ module R18n
148
148
  # <tt>:long_data</tt>, <tt>:datetime</tt>, <tt>:short_datetime</tt> or
149
149
  # <tt>:long_datetime</tt>).
150
150
  def strftime(time, format)
151
- if Symbol == format.class
151
+ if format.is_a? Symbol
152
152
  if :month == format
153
153
  return @locale['months']['standalone'][time.month - 1]
154
154
  end
@@ -108,7 +108,7 @@ module R18n
108
108
 
109
109
  # Return available translations in +dirs+
110
110
  def self.available(dirs)
111
- if Array == dirs.class
111
+ if dirs.is_a? Array
112
112
  return dirs.inject([]) do |available, i|
113
113
  available |= self.available(i)
114
114
  end
@@ -186,7 +186,7 @@ module R18n
186
186
  result = translation[name]
187
187
  next if result.nil?
188
188
 
189
- if YAML::PrivateType == result.class
189
+ if result.is_a? YAML::PrivateType
190
190
  case result.type_id
191
191
  when 'proc'
192
192
  if @@call_proc
@@ -197,10 +197,16 @@ module R18n
197
197
  when 'pl'
198
198
  locale = @locales[i]
199
199
 
200
- type = if Locale == locale.class
201
- locale.pluralize(params.first)
200
+ if locale.is_a? Locale
201
+ type = locale.pluralize(params.first)
202
+
203
+ if params.first.is_a? Float
204
+ params[0] = locale.format_float(params.first)
205
+ elsif params.first.is_a? Integer
206
+ params[0] = locale.format_integer(params.first)
207
+ end
202
208
  else
203
- Locale.default_pluralize(params.first)
209
+ type = Locale.default_pluralize(params.first)
204
210
  end
205
211
 
206
212
  type = 'n' if not result.value.include? type
@@ -210,17 +216,18 @@ module R18n
210
216
  end
211
217
  end
212
218
 
213
- if String == result.class
219
+ if result.is_a? String
220
+ result = result.clone
214
221
  params.each_with_index do |param, i|
215
222
  result.gsub! "%#{i+1}", param.to_s
216
223
  end
217
224
  return TranslatedString.new(result, @locales[i])
218
- elsif Hash == result.class
225
+ elsif result.is_a? Hash
219
226
  return self.class.new(@locales, @translations.map { |i|
220
227
  i[name] or {}
221
228
  })
222
229
  else
223
- return result
230
+ return result.clone
224
231
  end
225
232
  end
226
233
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module R18n
3
- VERSION = '0.2.1' unless defined? R18n::VERSION
3
+ VERSION = '0.2.2' unless defined? R18n::VERSION
4
4
  end
data/spec/i18n_spec.rb CHANGED
@@ -31,6 +31,7 @@ describe R18n::I18n do
31
31
  it "should load translations" do
32
32
  i18n = R18n::I18n.new(['ru', 'en'], DIR)
33
33
  i18n.one.should == 'Один'
34
+ i18n['one'].should == 'Один'
34
35
  i18n.only.english.should == 'Only in English'
35
36
  end
36
37
 
@@ -68,7 +69,7 @@ describe R18n::I18n do
68
69
  i18n.l(-12345.67).should == '−12 345,67'
69
70
 
70
71
  time = Time.at(0).utc
71
- i18n.l(time).should == 'Чтв, 01 янв 1970, 00:00:00 UTC'
72
+ i18n.l(time).should =~ /^Чтв, 01 янв 1970, 00:00:00 (GMT|UTC)$/
72
73
  i18n.l(time, :time).should == '00:00'
73
74
  i18n.l(time, '%A').should == 'Четверг'
74
75
 
data/spec/locale_spec.rb CHANGED
@@ -68,7 +68,7 @@ describe R18n::Locale do
68
68
 
69
69
  it "should format number in local traditions" do
70
70
  locale = R18n::Locale.load('en')
71
- locale.format_number(-123456789).should == "−123,456,789"
71
+ locale.format_integer(-123456789).should == "−123,456,789"
72
72
  end
73
73
 
74
74
  it "should format float in local traditions" do
@@ -85,7 +85,7 @@ describe R18n::Locale do
85
85
  locale.strftime(time, '%H:%M%p').should == '00:00 утра'
86
86
 
87
87
  locale.strftime(time, :month).should == 'Январь'
88
- locale.strftime(time, :datetime).should == 'Чтв, 01 янв 1970, 00:00:00 UTC'
88
+ locale.strftime(time, :datetime).should =~ /^Чтв, 01 янв 1970, 00:00:00 (GMT|UTC)$/
89
89
  end
90
90
 
91
91
  it "should delete slashed from locale for security reasons" do
@@ -87,6 +87,8 @@ describe R18n::Translation do
87
87
  translation.comments(5, 'article').should == '5 comments for article'
88
88
 
89
89
  translation.files(0).should == '0 files'
90
+ translation.files(-5.5).should == '−5.5 files'
91
+ translation.files(5000).should == '5,000 files'
90
92
  end
91
93
 
92
94
  it "should return unknown YAML type" 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.1
4
+ version: 0.2.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: 2009-02-18 00:00:00 +03:00
12
+ date: 2009-06-25 00:00:00 +04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,28 +23,28 @@ extra_rdoc_files:
23
23
  - README.rdoc
24
24
  - LICENSE
25
25
  files:
26
- - base/de.yml
27
- - base/kk.yml
28
26
  - base/ru.yml
29
- - base/eo.yml
30
- - base/en.yml
27
+ - base/kk.yml
31
28
  - base/fr.yml
32
- - lib/r18n-core.rb
29
+ - base/en.yml
30
+ - base/de.yml
31
+ - base/eo.yml
33
32
  - lib/r18n-core
34
- - lib/r18n-core/translation.rb
35
- - lib/r18n-core/translated_string.rb
33
+ - lib/r18n-core/untranslated.rb
34
+ - lib/r18n-core/i18n.rb
36
35
  - lib/r18n-core/locale.rb
37
36
  - lib/r18n-core/version.rb
38
- - lib/r18n-core/i18n.rb
39
- - lib/r18n-core/untranslated.rb
37
+ - lib/r18n-core/translation.rb
38
+ - lib/r18n-core/translated_string.rb
39
+ - lib/r18n-core.rb
40
+ - locales/ru.rb
41
+ - locales/ru.yml
42
+ - locales/kk.yml
43
+ - locales/fr.yml
40
44
  - locales/en_US.yml
45
+ - locales/en.yml
41
46
  - locales/de.yml
42
- - locales/kk.yml
43
- - locales/ru.yml
44
- - locales/ru.rb
45
47
  - locales/eo.yml
46
- - locales/en.yml
47
- - locales/fr.yml
48
48
  - LICENSE
49
49
  - README.rdoc
50
50
  has_rdoc: true
@@ -74,21 +74,21 @@ signing_key:
74
74
  specification_version: 2
75
75
  summary: I18n tool to translate your Ruby application.
76
76
  test_files:
77
- - spec/spec_helper.rb
78
- - spec/translation_spec.rb
79
- - spec/i18n_spec.rb
80
77
  - spec/locales
81
78
  - spec/locales/ru_spec.rb
79
+ - spec/spec_helper.rb
82
80
  - spec/translations
81
+ - spec/translations/two
82
+ - spec/translations/two/fr.yml
83
+ - spec/translations/two/en.yml
83
84
  - spec/translations/general
84
85
  - spec/translations/general/ru.yml
85
- - spec/translations/general/en.yml
86
86
  - spec/translations/general/no_LC.yml
87
+ - spec/translations/general/en.yml
87
88
  - spec/translations/extension
88
89
  - spec/translations/extension/no_TR.yml
89
90
  - spec/translations/extension/en.yml
90
- - spec/translations/two
91
- - spec/translations/two/en.yml
92
- - spec/translations/two/fr.yml
91
+ - spec/translation_spec.rb
93
92
  - spec/r18n_spec.rb
94
93
  - spec/locale_spec.rb
94
+ - spec/i18n_spec.rb