Module: Duration::Localizations

Defined in:
lib/duration/localizations.rb,
lib/duration/localizations/korean.rb,
lib/duration/localizations/english.rb

Overview

Contains localizations for the time formatters. Standard locales cannot be used because they don’t define time units.

Defined Under Namespace

Modules: English, Korean

Constant Summary collapse

DEFAULT_LOCALE =

Default locale

:english
@@locales =
{}

Class Method Summary collapse

Class Method Details

.load_allObject

Load all locales. This is invoked automatically upon loading Duration.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/duration/localizations.rb', line 14

def Localizations.load_all
  locales = []
  constants.each do |constant|
    mod = const_get(constant)
    next unless mod.kind_of?(Module) and mod.const_defined?('LOCALE')
    
    locale    = mod.const_get('LOCALE').to_sym  # Locale name
    plurals   = mod.const_defined?('PLURALS') ? mod.const_get('PLURALS') : DEFAULT_LOCALE # Unit plurals
    singulars = mod.const_defined?('SINGULARS') ? mod.const_get('SINGULARS') : DEFAULT_LOCALE # Unit singulars
    
    if mod.const_defined? 'FORMAT'
      format = mod.const_get 'FORMAT'
      format = format.kind_of?(Proc) ? format : proc { |duration| duration.format(format.to_s) }
    end
    
    # Add valid locale to the collection.
    @@locales[locale] = Locale.new(locale, plurals, singulars, format)
  end
end

.localesObject

Collection of locales



35
36
37
# File 'lib/duration/localizations.rb', line 35

def Localizations.locales
  @@locales
end