i18n-complements 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,6 +3,8 @@
3
3
  I18n complements provides:
4
4
  * Numbers localization
5
5
  * Moneys localization (through ISO4217 codes)
6
+ * Boolean localization
7
+ * String localization (do nothing but permits to generalize use of localization)
6
8
 
7
9
  == Localize numbers
8
10
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.6
@@ -8,6 +8,11 @@ class ::String
8
8
  end
9
9
  alias :t :translate
10
10
 
11
+ def localize(options = {})
12
+ I18n.translate(self, options)
13
+ end
14
+ alias :l :localize
15
+
11
16
  def to_currency
12
17
  I18n.currencies(self)
13
18
  end
@@ -26,6 +31,20 @@ end
26
31
 
27
32
  # Localization
28
33
 
34
+ class ::TrueClass
35
+ def localize(options = {})
36
+ I18n.localize(self, options)
37
+ end
38
+ alias :l :localize
39
+ end
40
+
41
+ class ::FalseClass
42
+ def localize(options = {})
43
+ I18n.localize(self, options)
44
+ end
45
+ alias :l :localize
46
+ end
47
+
29
48
  class ::Numeric
30
49
  def localize(options = {})
31
50
  I18n.localize(self, options)
@@ -3,10 +3,10 @@ module I18n
3
3
 
4
4
  class Simple
5
5
 
6
- def localize_with_numbers(locale, object, format = :default, options = {})
6
+ def localize_with_complements(locale, object, format = :default, options = {})
7
7
 
8
8
  if object.respond_to?(:strftime)
9
- return localize_without_numbers(locale, object, format, options)
9
+ return localize_without_complements(locale, object, format, options)
10
10
  elsif object.respond_to?(:abs)
11
11
  if currency = options[:currency]
12
12
  raise I18n::InvalidCurrency.new("Currency #{currency.to_s} does not exist.") unless I18nComplements::Numisma[currency.to_s]
@@ -51,13 +51,17 @@ module I18n
51
51
  return format.gsub(/%n/, value).gsub(/%s/, "\u{00A0}")
52
52
  end
53
53
  end
54
+ elsif object.is_a?(TrueClass) or object.is_a?(FalseClass)
55
+ return I18n.translate("boolean.formats.#{format}.#{object.to_s}")
56
+ elsif object.is_a?(String)
57
+ return object
54
58
  else
55
- raise ArgumentError, "Object must be a Numeric, Date, DateTime or Time object. #{object.class.name}:#{object.inspect} given."
59
+ raise ArgumentError, "Object must be a Numeric, TrueClass, FalseClass, String, Date, DateTime or Time object. #{object.class.name}:#{object.inspect} given."
56
60
  end
57
61
  end
58
62
 
59
- alias_method(:localize_without_numbers, :localize)
60
- alias_method(:localize, :localize_with_numbers)
63
+ alias_method(:localize_without_complements, :localize)
64
+ alias_method(:localize, :localize_with_complements)
61
65
 
62
66
  end
63
67
  end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestBooleans < Test::Unit::TestCase
5
+
6
+ def test_localization
7
+ assert_nothing_raised do
8
+ I18n.localize(true)
9
+ end
10
+
11
+ assert_nothing_raised do
12
+ I18n.localize(false)
13
+ end
14
+ end
15
+
16
+ def test_localization_with_core_extensions
17
+ assert_nothing_raised do
18
+ true.localize
19
+ end
20
+
21
+ assert_nothing_raised do
22
+ false.localize
23
+ end
24
+
25
+ assert_nothing_raised do
26
+ true.l
27
+ end
28
+
29
+ assert_nothing_raised do
30
+ false.l
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestStrings < Test::Unit::TestCase
5
+
6
+ def test_localization
7
+ assert_nothing_raised do
8
+ I18n.localize("This is a test sentence")
9
+ end
10
+
11
+ assert_nothing_raised do
12
+ I18n.localize("C'est une phrase d'exemple axée sur les caractères spéciaux")
13
+ end
14
+ end
15
+
16
+ def test_localization_with_core_extensions
17
+ assert_nothing_raised do
18
+ "This is a test sentence".localize
19
+ end
20
+
21
+ assert_nothing_raised do
22
+ "C'est une phrase d'exemple axée sur les caractères spéciaux".localize
23
+ end
24
+
25
+ assert_nothing_raised do
26
+ "This is a test sentence".l
27
+ end
28
+
29
+ assert_nothing_raised do
30
+ "C'est une phrase d'exemple axée sur les caractères spéciaux".l
31
+ end
32
+ end
33
+
34
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: i18n-complements
3
3
  version: !ruby/object:Gem::Version
4
4
  version: !binary |-
5
- MC4wLjQ=
5
+ MC4wLjY=
6
6
  prerelease:
7
7
  platform: ruby
8
8
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-25 00:00:00.000000000 Z
13
+ date: 2012-12-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n
@@ -49,9 +49,11 @@ files:
49
49
  - test/locales/eng.yml
50
50
  - test/locales/fra.yml
51
51
  - test/locales/jpn.yml
52
+ - test/test_booleans.rb
52
53
  - test/test_currencies.rb
53
54
  - test/test_extensions.rb
54
55
  - test/test_numbers.rb
56
+ - test/test_strings.rb
55
57
  homepage: http://github.com/burisu/i18n-complements
56
58
  licenses:
57
59
  - MIT
@@ -78,6 +80,8 @@ signing_key:
78
80
  specification_version: 3
79
81
  summary: I18n missing functionnalities
80
82
  test_files:
83
+ - test/test_booleans.rb
81
84
  - test/test_currencies.rb
82
85
  - test/test_extensions.rb
83
86
  - test/test_numbers.rb
87
+ - test/test_strings.rb