diff --git a/.gitignore b/.gitignore index 9309c351..c7768c2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .DS_Store test/rails/fixtures nbproject/ -vendor/cldr +vendor/**/* *.swp pkg .bundle diff --git a/ci/Gemfile.all b/ci/Gemfile.all index c12d84ac..a6d87a86 100644 --- a/ci/Gemfile.all +++ b/ci/Gemfile.all @@ -5,7 +5,4 @@ gem 'sqlite3-ruby' gem 'mocha' gem 'rufus-tokyo' gem 'ffi' -gem 'ruby-cldr' -gem 'ruby2ruby' -gem 'ParseTree' gem 'test_declarative' diff --git a/ci/Gemfile.all.lock b/ci/Gemfile.all.lock index db5d6ad1..0cfdfd6b 100644 --- a/ci/Gemfile.all.lock +++ b/ci/Gemfile.all.lock @@ -1,26 +1,13 @@ GEM remote: http://rubygems.org/ specs: - ParseTree (3.0.6) - RubyInline (>= 3.7.0) - sexp_processor (>= 3.0.0) - RubyInline (3.8.6) - ZenTest (~> 4.3) - ZenTest (4.4.0) activesupport (3.0.1) ffi (0.6.3) rake (>= 0.8.7) mocha (0.9.9) rake rake (0.8.7) - ruby-cldr (0.0.1) - ruby2ruby (1.2.5) - ruby_parser (~> 2.0) - sexp_processor (~> 3.0) - ruby_parser (2.0.5) - sexp_processor (~> 3.0) rufus-tokyo (1.0.7) - sexp_processor (3.0.5) sqlite3-ruby (1.3.2) test_declarative (0.0.4) @@ -28,12 +15,9 @@ PLATFORMS ruby DEPENDENCIES - ParseTree activesupport (~> 3.0.0) ffi mocha - ruby-cldr - ruby2ruby rufus-tokyo sqlite3-ruby test_declarative diff --git a/lib/i18n/backend.rb b/lib/i18n/backend.rb index a0f49ed0..46ef054b 100644 --- a/lib/i18n/backend.rb +++ b/lib/i18n/backend.rb @@ -5,7 +5,6 @@ module Backend autoload :Cache, 'i18n/backend/cache' autoload :Cascade, 'i18n/backend/cascade' autoload :Chain, 'i18n/backend/chain' - autoload :Cldr, 'i18n/backend/cldr' autoload :Fallbacks, 'i18n/backend/fallbacks' autoload :Flatten, 'i18n/backend/flatten' autoload :Gettext, 'i18n/backend/gettext' diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 55d738fc..c0faa47e 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -2,7 +2,6 @@ require 'i18n/core_ext/hash' require 'i18n/core_ext/kernel/surpress_warnings' - module I18n module Backend module Base diff --git a/lib/i18n/backend/cldr.rb b/lib/i18n/backend/cldr.rb deleted file mode 100644 index 0ae36c70..00000000 --- a/lib/i18n/backend/cldr.rb +++ /dev/null @@ -1,99 +0,0 @@ -require 'cldr' - -module I18n - module Backend - module Cldr - include ::Cldr::Format - - def localize(locale, object, format = :default, options = {}) - options[:as] ||= detect_type(object, options) - send(:"format_#{options[:as]}", locale, object, format, options) - end - - def format_decimal(locale, object, format = :default, options = {}) - formatter(locale, :decimal, format).apply(object, options) - end - - def format_integer(locale, object, format = :default, options = {}) - format_object(number, options.merge(:precision => 0)) - end - - def format_currency(locale, object, format = :default, options = {}) - options.merge!(:currency => lookup_currency(locale, options[:currency], object)) if options[:currency].is_a?(Symbol) - formatter(locale, :currency, format).apply(object, options) - end - - def format_percent(locale, object, format = :default, options = {}) - formatter(locale, :percent, format).apply(object, options) - end - - def format_date(locale, object, format = :default, options = {}) - formatter(locale, :date, format).apply(object, options) - end - - def format_time(locale, object, format = :default, options = {}) - formatter(locale, :time, format).apply(object, options) - end - - def format_datetime(locale, object, format = :default, options = {}) - key = :"calendars.gregorian.formats.datetime.#{format}.pattern" - date = I18n.l(object, :format => options[:date_format] || format, :locale => locale, :as => :date) - time = I18n.l(object, :format => options[:time_format] || format, :locale => locale, :as => :time) - I18n.t(key, :date => date, :time => time, :locale => locale, :raise => true) - end - - protected - - def detect_type(object, options) - options.has_key?(:currency) ? :currency : case object - when ::Numeric - :decimal - when ::Date, ::DateTime, ::Time - object.class.name.downcase.to_sym - else - raise_unspecified_format_type! - end - end - - def formatter(locale, type, format) - (@formatters ||= {})[:"#{locale}.#{type}.#{format}"] ||= begin - format = lookup_format(locale, type, format) - data = lookup_format_data(locale, type) - ::Cldr::Format.const_get(type.to_s.camelize).new(format, data) - end - end - - def lookup_format(locale, type, format) - key = case type - when :date, :time, :datetime - :"calendars.gregorian.formats.#{type}.#{format}.pattern" - else - :"numbers.formats.#{type}.patterns.#{format || :default}" - end - I18n.t(key, :locale => locale, :raise => true) - end - - def lookup_format_data(locale, type) - key = case type - when :date, :time, :datetime - :'calendars.gregorian' - else - :'numbers.symbols' - end - I18n.t(key, :locale => locale, :raise => true) - end - - def lookup_currency(locale, currency, count) - I18n.t(:"currencies.#{currency}", :locale => locale, :count => count) - end - - def raise_unspecified_format_type! - raise ArgumentError.new("You have to specify a format type, e.g. :as => :number.") - end - - def raise_unspecified_currency! - raise ArgumentError.new("You have to specify a currency, e.g. :currency => 'EUR'.") - end - end - end -end diff --git a/test/backend/cldr_test.rb b/test/backend/cldr_test.rb deleted file mode 100644 index 7338f0a9..00000000 --- a/test/backend/cldr_test.rb +++ /dev/null @@ -1,144 +0,0 @@ -# :coding: utf-8 -require 'test_helper' - -if defined?(Cldr) - require 'test_helper' - require 'i18n/backend/cldr' - require 'date' - - class I18nBackendCldrTest < Test::Unit::TestCase - class Backend < I18n::Backend::Simple - 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 - - # NUMBER - - test "format_number" do - assert_equal '123.456,78', I18n.l(123456.78) - end - - # CURRENCY - - test "format_currency" do - assert_equal '123.456,78 EUR', I18n.l(123456.78, :currency => 'EUR') - end - - # hu? does this actually make any sense? - 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 - - # PERCENT - - # this is odd but the cldr percent format does not include a fraction - test "format_percent" do - assert_equal '123.457 %', I18n.l(123456.78, :as => :percent) - end - - # so we can pass a precision manually - test "format_percent w/ precision" do - assert_equal '123.456,70 %', I18n.l(123456.7, :as => :percent, :precision => 2) - end - - # DATE - - def date - Date.new(2010, 1, 1) - end - - test "format_date :full" do - assert_equal 'Freitag, 1. Januar 2010', I18n.l(date, :format => :full) - end - - test "format_date :long" do - assert_equal '1. Januar 2010', I18n.l(date, :format => :long) - end - - test "format_date :medium" do - assert_equal '01.01.2010', I18n.l(date) - end - - test "format_date :short" do - assert_equal '01.01.10', I18n.l(date, :format => :short) - end - - # TIME - - def time - Time.utc(2010, 1, 1, 13, 15, 17) - end - - # TODO cldr export lacks localized timezone data - # test "format_time :full" do - # assert_equal 'Freitag, 1. Januar 2010', I18n.l(time, :format => :full) - # end - - test "format_time :long" do - assert_equal '13:15:17 UTC', I18n.l(time, :format => :long) - end - - test "format_time :medium" do - assert_equal '13:15:17', I18n.l(time) - end - - test "format_time :short" do - assert_equal '13:15', I18n.l(time, :format => :short) - end - - # DATETIME - - def datetime - DateTime.new(2010, 11, 12, 13, 14, 15) - end - - # TODO cldr export lacks localized timezone data - # test "format_datetime :full" do - # assert_equal 'Thursday, 12. November 2010 13:14:15', I18n.l(datetime, :format => :full) - # end - - test "format_datetime :long" do - assert_equal '12. November 2010 13:14:15 +00:00', I18n.l(datetime, :format => :long) - end - - test "format_datetime :medium" do - assert_equal '12.11.2010 13:14:15', I18n.l(datetime) - end - - test "format_datetime :short" do - assert_equal '12.11.10 13:14', I18n.l(datetime, :format => :short) - end - - test "format_datetime mixed :long + :short" do - assert_equal '12. November 2010 13:14', I18n.l(datetime, :date_format => :long, :time_format => :short) - end - - test "format_datetime mixed :short + :long" do - assert_equal '12.11.10 13:14:15 +00:00', I18n.l(datetime, :date_format => :short, :time_format => :long) - end - - # CUSTOM FORMATS - - test "can deal with customized formats data" do - store_translations :de, :numbers => { - :formats => { - :decimal => { - :patterns => { - :default => "#,##0.###", - :stupid => "#" - } - } - } - } - assert_equal '123.456,78', I18n.l(123456.78) - assert_equal '123457', I18n.l(123456.78, :format => :stupid) - end - end -end diff --git a/test/test_data/locales/cldr/de/calendars.yml b/test/test_data/locales/cldr/de/calendars.yml deleted file mode 100644 index 7ec740b5..00000000 --- a/test/test_data/locales/cldr/de/calendars.yml +++ /dev/null @@ -1,152 +0,0 @@ -de: - calendars: - gregorian: - days: - format: - abbreviated: - fri: Fr. - mon: Mo. - sat: Sa. - sun: So. - thu: Do. - tue: Di. - wed: Mi. - narrow: :"calendars.gregorian.days.stand-alone.narrow" - wide: - fri: Freitag - mon: Montag - sat: Samstag - sun: Sonntag - thu: Donnerstag - tue: Dienstag - wed: Mittwoch - stand-alone: - abbreviated: :"calendars.gregorian.days.format.abbreviated" - narrow: - fri: F - mon: M - sat: S - sun: S - thu: D - tue: D - wed: M - wide: :"calendars.gregorian.days.format.wide" - fields: - day: Tag - dayperiod: Tageshälfte - era: Epoche - hour: Stunde - minute: Minute - month: Monat - second: Sekunde - week: Woche - weekday: Wochentag - year: Jahr - zone: Zone - formats: - date: - default: :"calendars.gregorian.formats.date.medium" - full: - pattern: "EEEE, d. MMMM y" - long: - pattern: "d. MMMM y" - medium: - pattern: dd.MM.yyyy - short: - pattern: dd.MM.yy - datetime: - default: :"calendars.gregorian.formats.datetime.medium" - full: - pattern: "%{date} %{time}" - long: - pattern: "%{date} %{time}" - medium: - pattern: "%{date} %{time}" - short: - pattern: "%{date} %{time}" - time: - default: :"calendars.gregorian.formats.time.medium" - full: - pattern: "HH:mm:ss zzzz" - long: - pattern: "HH:mm:ss z" - medium: - pattern: "HH:mm:ss" - short: - pattern: "HH:mm" - months: - format: - abbreviated: - 1: Jan - 10: Okt - 11: Nov - 12: Dez - 2: Feb - 3: Mär - 4: Apr - 5: Mai - 6: Jun - 7: Jul - 8: Aug - 9: Sep - narrow: :"calendars.gregorian.months.stand-alone.narrow" - wide: - 1: Januar - 10: Oktober - 11: November - 12: Dezember - 2: Februar - 3: März - 4: April - 5: Mai - 6: Juni - 7: Juli - 8: August - 9: September - stand-alone: - abbreviated: - 10: Okt - 11: Nov - 12: Dez - 3: Mär - 7: Jul - 8: Aug - 9: Sep - narrow: - 1: J - 10: O - 11: N - 12: D - 2: F - 3: M - 4: A - 5: M - 6: J - 7: J - 8: A - 9: S - wide: :"calendars.gregorian.months.format.wide" - periods: - am: vorm. - pm: nachm. - quarters: - format: - abbreviated: - 1: Q1 - 2: Q2 - 3: Q3 - 4: Q4 - narrow: :"calendars.gregorian.quarters.stand-alone.narrow" - wide: - 1: "1. Quartal" - 2: "2. Quartal" - 3: "3. Quartal" - 4: "4. Quartal" - stand-alone: - abbreviated: :"calendars.gregorian.quarters.format.abbreviated" - narrow: - 1: 1 - 2: 2 - 3: 3 - 4: 4 - wide: :"calendars.gregorian.quarters.format.wide" \ No newline at end of file diff --git a/test/test_data/locales/cldr/de/currencies.yml b/test/test_data/locales/cldr/de/currencies.yml deleted file mode 100644 index 40f477dd..00000000 --- a/test/test_data/locales/cldr/de/currencies.yml +++ /dev/null @@ -1,8 +0,0 @@ -de: - currencies: - EUR: - one: Euro - other: Euro - IEP: - one: "Irisches Pfund" - other: "Irische Pfund" \ No newline at end of file diff --git a/test/test_data/locales/cldr/de/numbers.yml b/test/test_data/locales/cldr/de/numbers.yml deleted file mode 100644 index fac4d6cb..00000000 --- a/test/test_data/locales/cldr/de/numbers.yml +++ /dev/null @@ -1,31 +0,0 @@ -de: - numbers: - formats: - currency: - patterns: - default: "#,##0.00 ¤" - unit: - one: "{0} {1}" - other: "{0} {1}" - decimal: - patterns: - default: "#,##0.###" - percent: - patterns: - default: "#,##0 %" - scientific: - patterns: - default: "#E0" - symbols: - decimal: "," - exponential: E - group: "." - infinity: ∞ - list: ; - minus_sign: "-" - nan: NaN - native_zero_digit: 0 - pattern_digit: "#" - per_mille: ‰ - percent_sign: "%" - plus_sign: + \ No newline at end of file