Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# encoding: utf-8 | ||
$:.unshift '/Volumes/Users/sven/Development/projects/i18n/cldr/lib' | ||
This comment has been minimized.
Sorry, something went wrong. |
||
require 'cldr' | ||
|
||
module I18n | ||
module Backend | ||
module Cldr | ||
include ::Cldr::Format | ||
|
||
def localize(locale, object, format = :default, options = {}) | ||
case object | ||
when ::Numeric | ||
format(locale, object, { :as => :number }.merge(options)) | ||
else | ||
super | ||
end | ||
end | ||
|
||
protected | ||
|
||
def lookup_number_format(locale, type, format) | ||
I18n.t(:"numbers.formats.#{type}.#{format || :default}.pattern", :locale => locale) | ||
end | ||
|
||
def lookup_number_symbols(locale) | ||
I18n.t(:'numbers.symbols', :locale => locale) | ||
end | ||
|
||
def lookup_currency(locale, currency, count) | ||
I18n.t(:"currencies.#{currency}", :locale => locale, :count => count) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# encoding: utf-8 | ||
|
||
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper') | ||
require 'i18n/backend/cldr' | ||
|
||
class I18nBackendCldrTest < Test::Unit::TestCase | ||
class Backend | ||
include I18n::Backend::Base | ||
include I18n::Backend::Cldr | ||
end | ||
|
||
def setup | ||
I18n.backend = Backend.new | ||
I18n.locale = :de | ||
I18n.load_path += Dir[locales_dir + '/cldr/**/*.{yml,rb}'] | ||
super | ||
end | ||
|
||
define_method :"test: format_number" do | ||
assert_equal '123.456,78', I18n.l(123456.78) | ||
end | ||
|
||
define_method :"test: format_currency" do | ||
assert_equal '123.456,78 EUR', I18n.l(123456.78, :currency => 'EUR') | ||
end | ||
|
||
# hu? does this actually make any sense? | ||
define_method :"test: format_currency translating currency names" do | ||
assert_equal '1,00 Irisches Pfund', I18n.l(1, :currency => :IEP) | ||
assert_equal '2,00 Irische Pfund', I18n.l(2, :currency => :IEP) | ||
end | ||
|
||
# this is odd but the cldr percent format does not include a fraction | ||
define_method :"test: format_percent" do | ||
assert_equal '123.457 %', I18n.l(123456.78, :as => :percent) | ||
end | ||
|
||
# so we can pass a precision manually | ||
define_method :"test: format_percent w/ precision" do | ||
assert_equal '123.456,70 %', I18n.l(123456.7, :as => :percent, :precision => 2) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
de: | ||
currencies: | ||
EUR: | ||
one: Euro | ||
other: Euro | ||
IEP: | ||
one: "Irisches Pfund" | ||
other: "Irische Pfund" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
de: | ||
numbers: | ||
formats: | ||
currency: | ||
default: | ||
pattern: "#,##0.00 ¤" | ||
unit: | ||
one: "{0} {1}" | ||
other: "{0} {1}" | ||
decimal: | ||
default: | ||
pattern: "#,##0.###" | ||
percent: | ||
default: | ||
pattern: "#,##0 %" | ||
scientific: | ||
default: | ||
pattern: "#E0" | ||
symbols: | ||
decimal: "," | ||
exponential: E | ||
group: "." | ||
infinity: ∞ | ||
list: ; | ||
minus_sign: "-" | ||
nan: NaN | ||
native_zero_digit: 0 | ||
pattern_digit: "#" | ||
per_mille: ‰ | ||
percent_sign: "%" | ||
plus_sign: + |
7 comments
on commit 860eadf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personal project load path whoops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at the line, does not look like it belogs to library master :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHOOPS :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus it just came out you're using Mac. I couldn't decide which one is more embarassing ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, not using Microsoft Windows is so immature and unprofessional of y'all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, I almost trolled successfully ;)
whoops.