lib/spiderfw/i18n/cldr.rb in spiderfw-0.5.7 vs lib/spiderfw/i18n/cldr.rb in spiderfw-0.5.9
- old
+ new
@@ -10,11 +10,11 @@
@locale = locale
@cldr = ::CLDR::Object.new(:locale => locale.to_cldr)
end
- def localize_date_time(locale, object, format = :default, options={})
+ def localize_date_time(object, format = :default, options={})
options[:calendar] ||= 'gregorian'
if (format == :default)
format = @cldr.calendar.dateformat_defaults[options[:calendar]]
end
@@ -62,11 +62,11 @@
end
object.strftime(format_string)
end
# FIXME: add extended format handling like in localize
- def parse_dt(locale, string, format = :default, options = {})
+ def parse_dt(string, format = :default, options = {})
options[:calendar] ||= 'gregorian'
if (format == :default)
format = @cldr.calendar.dateformat_defaults[options[:calendar]]
end
@@ -98,16 +98,66 @@
def prepare_format_string(obj, string)
end
-
def mgsub(string, key_value_pairs)
regexp_fragments = key_value_pairs.collect { |k,v| k }
string.gsub(
Regexp.union(*regexp_fragments)) do |match|
key_value_pairs.detect{|k,v| k =~ match}[1]
end
+ end
+
+ def day_names(format = :wide, calendar = self.default_calendar)
+ begin
+ 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, calendar = self.default_calendar)
+ months = []
+ begin
+ @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"
+ end
+ months
+ end
+
+ def week_start(calendar = self.default_calendar)
+ wdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
+ wdays.index @cldr.calendar.week_firstdays[calendar.to_s]
+ end
+
+ def weekend_start(calendar = self.default_calendar)
+ wdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
+ wdays.index @cldr.calendar.weekend_starts[calendar.to_s]
+ end
+
+ def weekend_end(calendar = self.default_calendar)
+ wdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
+ wdays.index @cldr.calendar.weekend_ends[calendar.to_s]
+ end
+
+ def localize_number(object, precision=nil, options={})
+ delimiter = @cldr.number.symbol_group
+ separator = @cldr.number.symbol_decimal
+ Spider::I18n.do_localize_number(object, delimiter, separator, precision, options)
+ end
+
+ def parse_number(string, options={})
+ delimiter = @cldr.number.symbol_group
+ separator = @cldr.number.symbol_decimal
+ Spider::I18n.do_parse_number(string, delimiter, separator, options)
end
end
end; end
\ No newline at end of file