i18n-complements 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +15 -0
- data/VERSION +1 -0
- data/lib/i18n-complements/localize_numbers.rb +65 -0
- data/lib/i18n-complements/numisma/currencies.yml +1002 -0
- data/lib/i18n-complements/numisma/currency.rb +78 -0
- data/lib/i18n-complements/numisma.rb +61 -0
- data/lib/i18n-complements.rb +10 -0
- data/test/helper.rb +11 -0
- data/test/locales/eng.yml +10 -0
- data/test/locales/fra.yml +10 -0
- data/test/locales/jpn.yml +13 -0
- data/test/test_currencies.rb +12 -0
- data/test/test_numbers.rb +84 -0
- metadata +86 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2012 Brice Texier
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
I18nComplements
|
2
|
+
===============
|
3
|
+
|
4
|
+
I18n complements provides:
|
5
|
+
* Numbers localization
|
6
|
+
* Moneys localization (through ISO4217 codes)
|
7
|
+
|
8
|
+
TODO
|
9
|
+
----
|
10
|
+
|
11
|
+
* Add String/Symbol :t methods
|
12
|
+
* Add Date/Datetime/Time/Number :l methods
|
13
|
+
* Enhances number localization using bases (10, 20...) and characters
|
14
|
+
of the language. Ex: Roman (Ⅰ, Ⅱ, Ⅲ, Ⅳ...), traditionnal chinese/japanese
|
15
|
+
numbers (一, 二, 三, 四...)
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module I18n
|
2
|
+
module Backend
|
3
|
+
module Base
|
4
|
+
|
5
|
+
def localize_with_numbers(locale, object, format = :default, options = {})
|
6
|
+
# options.symbolize_keys!
|
7
|
+
if object.respond_to?(:abs)
|
8
|
+
if currency = options[:currency]
|
9
|
+
raise I18nComplements::InvalidCurrency.new("Currency #{currency.to_s} does not exist.") unless I18nComplements::Numisma[currency.to_s]
|
10
|
+
return I18nComplements::Numisma[currency.to_s].localize(object, :locale=>locale)
|
11
|
+
else
|
12
|
+
formatter = I18n.translate('number.format'.to_sym, :locale => locale, :default => {})
|
13
|
+
if formatter.is_a?(Proc)
|
14
|
+
return formatter[object]
|
15
|
+
elsif formatter.is_a?(Hash)
|
16
|
+
formatter = {:format => "%n", :separator=>'.', :delimiter=>'', :precision=>3}.merge(formatter).merge(options)
|
17
|
+
format = formatter[:format]
|
18
|
+
negative_format = formatter[:negative_format] || "-" + format
|
19
|
+
|
20
|
+
if object.to_f < 0
|
21
|
+
format = negative_format
|
22
|
+
object = object.abs
|
23
|
+
end
|
24
|
+
|
25
|
+
value = object.to_s.split(/\./)
|
26
|
+
integrals, decimals = value[0].to_s, value[1].to_s
|
27
|
+
value = integrals.gsub(/^0+[1-9]+/, '').gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{formatter[:delimiter]}")
|
28
|
+
decimals = "0" if decimals.to_s.match(/^\s*$/) and object.is_a?(Float)
|
29
|
+
unless decimals.to_s.match(/^\s*$/)
|
30
|
+
# decimals = decimals.gsub(/0+$/, '').ljust(formatter[:precision], '0').reverse.split(/(?=\d{3})/).reverse.collect{|x| x.reverse}.join(formatter[:delimiter])
|
31
|
+
value << formatter[:separator]
|
32
|
+
|
33
|
+
i = 0
|
34
|
+
decimals.gsub(/0+$/, '').ljust(formatter[:precision], '0').each_char do |c|
|
35
|
+
if i == 3
|
36
|
+
value << formatter[:delimiter]
|
37
|
+
i = 0
|
38
|
+
end
|
39
|
+
value << c
|
40
|
+
i += 1
|
41
|
+
end
|
42
|
+
# .reverse.split(/(?=\d{3})/).reverse.collect{|x| x.reverse}.join(formatter[:delimiter])
|
43
|
+
# value << decimals
|
44
|
+
end
|
45
|
+
|
46
|
+
# decimals = decimals.gsub(/0+$/, '').ljust(formatter[:precision], '0').reverse.split(/(?=\d{3})/).reverse.collect{|x| x.reverse}.join(formatter[:delimiter])
|
47
|
+
# value += formatter[:separator] + decimals unless decimals.to_s.match(/^\s*$/)
|
48
|
+
return format.gsub(/%n/, value).gsub(/%s/, "\u{00A0}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
elsif object.respond_to?(:strftime)
|
52
|
+
return localize_without_numbers(locale, object, format, options)
|
53
|
+
else
|
54
|
+
raise ArgumentError, "Object must be a Numeric, Date, DateTime or Time object. #{object.inspect} given."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
alias :localize_without_numbers :localize
|
59
|
+
alias :localize :localize_with_numbers
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# I18n::Backend::Base.send(:include, I18nComplements::Backend::Base)
|