lib/spiderfw/i18n/cldr.rb in spiderfw-0.6.23 vs lib/spiderfw/i18n/cldr.rb in spiderfw-0.6.24

- old
+ new

@@ -12,11 +12,10 @@ @cldr = ::CLDR::Object.new(:locale => locale.to_cldr) end def localize_date_time(object, format = 'medium', options={}) - raise "Localize format is nil" unless format options[:calendar] ||= 'gregorian' format = 'medium' if format == :default time_format = nil date_format = nil @@ -39,12 +38,12 @@ end # FIXME: handle more efficiently d = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'] obj_d = d[object.wday] - days = @cldr.calendar.days[options[:calendar].to_sym][:format] || @cldr.calendar.days[options[:calendar].to_sym] - months = @cldr.calendar.months[options[:calendar].to_sym][:format] || @cldr.calendar.months[options[:calendar].to_sym] + days = @cldr.calendar.days[options[:calendar].to_sym] + months = @cldr.calendar.months[options[:calendar].to_sym] replacements = [ [/y{1,4}/, '%Y'], # year don't use two digits year, they cause confusion [/y{1,2}/, '%y'] [/M{5}/, months[:narrow][object.month.to_s]], [/M{4}/, months[:wide][object.month.to_s]], #month [/M{3}/, months[:abbreviated][object.month.to_s]], [/M{1,2}/, '%m'], [/L{5}/, months[:narrow][object.month.to_s]], [/L{4}/, months[:wide][object.month.to_s]], #month @@ -114,26 +113,24 @@ Regexp.union(*regexp_fragments)) do |match| key_value_pairs.detect{|k,v| k =~ match}[1] end end - def day_names(format = :wide, context = :stand_alone, calendar = self.default_calendar) + def day_names(format = :wide, calendar = self.default_calendar) begin - days = @cldr.calendar.days[calendar][format] || @cldr.calendar.days[calendar][context][format] + days = @cldr.calendar.days[calendar][format] return [days['sun'], days['mon'], days['tue'], days['wed'], days['thu'], days['fri'], days['sat']] rescue NoMethodError raise ArgumentError, "Calendar #{calendar} not found" unless @cldr.days[calendar] raise ArgumentError, "Format #{format} not found" end end - def month_names(format = :wide, context = :stand_alone, calendar = self.default_calendar) + def month_names(format = :wide, calendar = self.default_calendar) months = [] begin - # CLDR 1 doesn't have context, CLDR 2 does - months = @cldr.calendar.months[calendar][format] || @cldr.calendar.months[calendar][context][format] - months.each do |k, v| + @cldr.calendar.months[calendar][format].each do |k, v| months[k.to_i] = v end rescue NoMethodError raise ArgumentError, "Calendar #{calendar} not found" unless @cldr.months[calendar] raise ArgumentError, "Format #{format} not found"