Module: Jekyll::Locale::DateTimeHandler

Extended by:
Forwardable
Defined in:
lib/jekyll/locale/date_time_handler.rb

Constant Summary collapse

DATETIME_DEFAULTS =
{
  :date => {
    :day_names        => Date::DAYNAMES,
    :month_names      => Date::MONTHNAMES,
    :abbr_day_names   => Date::ABBR_DAYNAMES,
    :abbr_month_names => Date::ABBR_MONTHNAMES,
  },
  :time => {
    :am      => "am",
    :pm      => "pm",
    :formats => {
      :default => "%B %d, %Y %l:%M:%S %p %z",
    },
  },
}.freeze

Class Method Summary collapse

Class Method Details

.bootstrap(handler) ⇒ Object



27
28
29
30
# File 'lib/jekyll/locale/date_time_handler.rb', line 27

def bootstrap(handler)
  @handler = handler
  config.available_locales = @handler.available_locales
end

.localize(input, format) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/jekyll/locale/date_time_handler.rb', line 32

def localize(input, format)
  object = date_cache(input)
  locale = @handler.current_locale.to_sym
  data   = @handler.locale_dates[locale.to_s] || {}
  store_translations(locale, data) unless translations.key?(locale)
  backend.localize(locale, object, format)
end

.store_translations(locale, data) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/jekyll/locale/date_time_handler.rb', line 40

def store_translations(locale, data)
  backend.store_translations(
    locale,
    Utils.deep_merge_hashes(
      DATETIME_DEFAULTS, Utils.recursive_symbolize_hash_keys(data)
    )
  )
end