Path: | lib/features/localized_date_and_time.rb |
Last Update: | Mon Oct 15 19:43:41 +0200 2007 |
This feature will overwrite the month and day name constants of the Date class with the proper names from the language file. Here silence_warnings gets used to prevent const reassignment warnings. We know we‘re doing something bad…
Also updates the date formates of the Date class with the ones from the language file.
Next on the Time class is localized. More specifically it‘s strftime method. This is based on the quick‘n dirty localization from Patrick Lenz: poocs.net/articles/2005/10/04/localization-for-rubys-time-strftime. It‘s a bit modified to respect the ’%%’ escape sequence.
As done with the date formats of the Date class the time formats of the Time class will be updated, too. Again with ones from the language file.
The necessary localized strings are read from the dates section of the language file:
dates: monthnames: [January, February, March, April, May, June, July, August, September, October, November, December] daynames: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday] abbr_monthnames: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec] abbr_daynames: [Sun, Mon, Tue, Wed, Thu, Fri, Sat] date_formats: short: '%e %b' long: '%B %e, %Y' time_formats: short: '%d %b %H:%M' long: '%B %d, %Y %H:%M'
The monthnames, daynames, abbr_monthnames and abbr_daynames entries will overwrite the corresponding constants of the Date class. The date_formats and time_formats entries are used to update the formats available to the to_formatted_s method of the Date and Time classes.
ABBR_DAYNAMES | = | ArkanisDevelopment::SimpleLocalization::CachedLangSectionProxy.new :sections => [:dates, :abbr_daynames] |
MONTHS | = | ArkanisDevelopment::SimpleLocalization::CachedLangSectionProxy.new :sections => [:dates, :monthnames] do |localized_data| ArkanisDevelopment::SimpleLocalization::LocalizedDateAndTime.convert_to_name_indexed_hash localized_data, 1 |