i18n-complements 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -22,7 +22,7 @@ With extensions:
22
22
  I18n.localize(13500, :currency => :JPY, :locale => :jpn) # => "13,500円"
23
23
 
24
24
  I18n.localize(13500, :currency => :EUR, :locale => :eng) # => "€13,500.00"
25
- I18n.localize(13500, :currency => :EUR, :locale => :fra) # => "13 500.00 €"
25
+ I18n.localize(13500, :currency => :EUR, :locale => :fra) # => "13 500,00 €"
26
26
 
27
27
  With extensions:
28
28
  13500.l(:currency => :JPY, :locale => :jpn) # => "13,500円"
@@ -55,6 +55,7 @@ To find existing currencies:
55
55
 
56
56
  == To do
57
57
 
58
- * Enhances numerals localization using bases (10, 20...) and characters
59
- of the language. Ex: Roman (Ⅰ, Ⅱ, Ⅲ, Ⅳ...), traditionnal chinese/japanese
60
- numbers (一, 二, 三, 四...)
58
+ * Enhance numerals localization using systems (decimal,
59
+ vigesimal...) and characters of the language for numerals.
60
+ Ex: Abjad numerals (ا, ب, ج, د...), Roman numbers (Ⅰ, Ⅱ, Ⅲ, Ⅳ...),
61
+ traditional chinese/japanese numbers (一, 二, 三, 四...),
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,10 +1,13 @@
1
1
  module I18n
2
2
  module Backend
3
- module Base
3
+
4
+ class Simple
4
5
 
5
6
  def localize_with_numbers(locale, object, format = :default, options = {})
6
- # options.symbolize_keys!
7
- if object.respond_to?(:abs)
7
+
8
+ if object.respond_to?(:strftime)
9
+ return localize_without_numbers(locale, object, format, options)
10
+ elsif object.respond_to?(:abs)
8
11
  if currency = options[:currency]
9
12
  raise I18n::InvalidCurrency.new("Currency #{currency.to_s} does not exist.") unless I18nComplements::Numisma[currency.to_s]
10
13
  return I18nComplements::Numisma[currency.to_s].localize(object, :locale=>locale)
@@ -48,15 +51,13 @@ module I18n
48
51
  return format.gsub(/%n/, value).gsub(/%s/, "\u{00A0}")
49
52
  end
50
53
  end
51
- elsif object.respond_to?(:strftime)
52
- return localize_without_numbers(locale, object, format, options)
53
54
  else
54
- raise ArgumentError, "Object must be a Numeric, Date, DateTime or Time object. #{object.inspect} given."
55
+ raise ArgumentError, "Object must be a Numeric, Date, DateTime or Time object. #{object.class.name}:#{object.inspect} given."
55
56
  end
56
57
  end
57
58
 
58
- alias :localize_without_numbers :localize
59
- alias :localize :localize_with_numbers
59
+ alias_method(:localize_without_numbers, :localize)
60
+ alias_method(:localize, :localize_with_numbers)
60
61
 
61
62
  end
62
63
  end
@@ -61,7 +61,7 @@ module I18nComplements
61
61
  end
62
62
 
63
63
 
64
- module I18n
64
+ module ::I18n
65
65
 
66
66
  class << self
67
67
 
@@ -77,6 +77,14 @@ module I18n
77
77
  I18nComplements::Numisma.currencies
78
78
  end
79
79
 
80
+ def currency_label(currency_code)
81
+ if currency = I18nComplements::Numisma.currencies[currency_code.to_s]
82
+ currency.label
83
+ else
84
+ return "Unknown currency: #{currency_code}"
85
+ end
86
+ end
87
+
80
88
  end
81
89
 
82
90
  end
data/test/locales/eng.yml CHANGED
@@ -16,4 +16,4 @@ eng:
16
16
  precision: 2
17
17
  my:
18
18
  example: My example is short
19
- my_example: My example is short
19
+ my_example: My example is so short
@@ -5,15 +5,15 @@ class TestCurrencies < Test::Unit::TestCase
5
5
 
6
6
  def test_localization_with_currency
7
7
  assert_nothing_raised do
8
- I18n.localize(14.5, :currency => :JPY)
8
+ ::I18n.localize(14.5, :currency => :JPY)
9
9
  end
10
10
 
11
11
  assert_nothing_raised do
12
- I18n.localize(14.5, :currency => "JPY")
12
+ ::I18n.localize(14.5, :currency => "JPY")
13
13
  end
14
14
 
15
15
  assert_raise(I18n::InvalidCurrency) do
16
- I18n.localize(14.5, :currency => "jPY")
16
+ ::I18n.localize(14.5, :currency => "jPY")
17
17
  end
18
18
  end
19
19
 
@@ -45,15 +45,15 @@ class TestCurrencies < Test::Unit::TestCase
45
45
 
46
46
  def test_number_formatting_with_currency
47
47
  number = 413500
48
- assert_equal "¥413,500", I18n.localize(number, :locale => :eng, :currency=>"JPY")
49
- assert_equal "413\u{00A0}500\u{00A0}¥", I18n.localize(number, :locale => :fra, :currency=>"JPY")
50
- assert_equal "413,500円", I18n.localize(number, :locale => :jpn, :currency=>"JPY")
48
+ assert_equal "¥413,500", ::I18n.localize(number, :locale => :eng, :currency=>"JPY")
49
+ assert_equal "413\u{00A0}500\u{00A0}¥", ::I18n.localize(number, :locale => :fra, :currency=>"JPY")
50
+ assert_equal "413,500円", ::I18n.localize(number, :locale => :jpn, :currency=>"JPY")
51
51
  end
52
52
 
53
53
  def test_number_formatting_with_currency_with_core_extensions
54
54
  for locale in [:eng, :fra, :jpn]
55
55
  for money in [[413500, "JPY"], [1425.23, "USD"], [0.96, "EUR"]]
56
- assert_equal(money[0].l(:locale => money[1]), I18n.localize(money[0], :locale => money[1]))
56
+ assert_equal(money[0].l(:locale => money[1]), ::I18n.localize(money[0], :locale => money[1]))
57
57
  end
58
58
  end
59
59
  end
@@ -61,25 +61,30 @@ class TestCurrencies < Test::Unit::TestCase
61
61
 
62
62
  def test_listing_of_currencies
63
63
  assert_nothing_raised do
64
- I18n.active_currencies
64
+ ::I18n.active_currencies
65
65
  end
66
66
 
67
67
  assert_nothing_raised do
68
- I18n.available_currencies
68
+ ::I18n.available_currencies
69
69
  end
70
70
 
71
- assert I18n.active_currencies.size <= I18n.available_currencies.size, "Available currencies cannot be less numerous than active currencies"
71
+ assert ::I18n.active_currencies.size <= ::I18n.available_currencies.size, "Available currencies cannot be less numerous than active currencies"
72
72
  end
73
73
 
74
74
  def test_currency_properties
75
- assert !I18n.currencies(:JPY).nil?
76
- assert !I18n.currencies("JPY").nil?
77
- assert I18n.currencies("JPy").nil?
75
+ assert !::I18n.currencies(:JPY).nil?
76
+ assert !::I18n.currencies("JPY").nil?
77
+ assert ::I18n.currencies("JPy").nil?
78
78
 
79
- assert !I18n.currencies("USD").nil?
80
- assert !I18n.currencies("EUR").nil?
79
+ assert !::I18n.currencies("USD").nil?
80
+ assert !::I18n.currencies("EUR").nil?
81
81
 
82
- assert I18n.currencies("JPYXX").nil?
82
+ assert ::I18n.currencies("JPYXX").nil?
83
+
84
+ assert_nothing_raised do
85
+ ::I18n.currency_label("JPY")
86
+ end
87
+ assert !::I18n.currency_label("JPY").match(/Unknown/)
83
88
  end
84
89
 
85
90
  def test_currency_properties_with_core_extensions
@@ -92,4 +97,5 @@ class TestCurrencies < Test::Unit::TestCase
92
97
  end
93
98
  end
94
99
 
100
+
95
101
  end
@@ -8,7 +8,7 @@ class TestExtensions < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_string_translation
11
- assert_equal "My example is short", I18n.translate("my_example")
11
+ assert_equal "My example is so short", I18n.translate("my_example")
12
12
  assert_equal I18n.translate("my_example"), "my_example".translate
13
13
  assert_equal I18n.translate("my_example"), "my_example".t
14
14
 
@@ -18,7 +18,7 @@ class TestExtensions < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  def test_symbol_translation
21
- assert_equal "My example is short", I18n.translate(:my_example)
21
+ assert_equal "My example is so short", I18n.translate(:my_example)
22
22
  assert_equal I18n.translate(:my_example), :my_example.translate
23
23
  assert_equal I18n.translate(:my_example), :my_example.t
24
24
  end
@@ -27,6 +27,8 @@ class TestExtensions < Test::Unit::TestCase
27
27
  def test_date_localization
28
28
  date = Date.civil(1999, 12, 31)
29
29
 
30
+ assert_equal Date, date.class
31
+
30
32
  assert_nothing_raised do
31
33
  date.localize
32
34
  end
@@ -41,6 +43,8 @@ class TestExtensions < Test::Unit::TestCase
41
43
  def test_datetime_localization
42
44
  datetime = DateTime.civil(1999, 12, 31, 23, 59, 59)
43
45
 
46
+ assert_equal DateTime, datetime.class
47
+
44
48
  assert_nothing_raised do
45
49
  datetime.localize
46
50
  end
@@ -55,6 +59,8 @@ class TestExtensions < Test::Unit::TestCase
55
59
  def test_time_localization
56
60
  time = DateTime.civil(1999, 12, 31, 23, 59, 59).to_time
57
61
 
62
+ assert_equal Time, time.class
63
+
58
64
  assert_nothing_raised do
59
65
  time.localize
60
66
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-complements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: !binary |-
5
+ MC4wLjM=
5
6
  prerelease:
6
7
  platform: ruby
7
8
  authors:
@@ -9,11 +10,11 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-05-11 00:00:00.000000000Z
13
+ date: 2012-07-23 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: i18n
16
- requirement: &9099980 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
@@ -21,7 +22,12 @@ dependencies:
21
22
  version: '0.6'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *9099980
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0.6'
25
31
  description:
26
32
  email: burisu@oneiros.fr
27
33
  executables: []
@@ -67,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
73
  version: '0'
68
74
  requirements: []
69
75
  rubyforge_project:
70
- rubygems_version: 1.8.11
76
+ rubygems_version: 1.8.23
71
77
  signing_key:
72
78
  specification_version: 3
73
79
  summary: I18n missing functionnalities
@@ -75,4 +81,3 @@ test_files:
75
81
  - test/test_currencies.rb
76
82
  - test/test_extensions.rb
77
83
  - test/test_numbers.rb
78
- has_rdoc: