Module: IceCube::NullI18n

Defined in:
lib/ice_cube/null_i18n.rb

Class Method Summary collapse

Class Method Details

.configObject



24
25
26
# File 'lib/ice_cube/null_i18n.rb', line 24

def self.config
  @config ||= YAML.load(File.read(File.join(File.dirname(__FILE__), '..', '..', 'config', 'locales', 'en.yml')))['en']
end

.l(date_or_time, options = {}) ⇒ Object



19
20
21
22
# File 'lib/ice_cube/null_i18n.rb', line 19

def self.l(date_or_time, options = {})
  return date_or_time.strftime(options[:format]) if options[:format]
  date_or_time.strftime(t('ice_cube.date.formats.default'))
end

.t(key, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ice_cube/null_i18n.rb', line 5

def self.t(key, options = {})
  base = key.to_s.split('.').reduce(config) { |hash, current_key| hash[current_key] }

  base = base[options[:count] == 1 ? "one" : "other"] if options[:count]

  if base.is_a?(Hash)
    return base.each_with_object({}) do |(key, value), hash|
      hash[key.is_a?(String) ? key.to_sym : key] = value
    end
  end

  options.reduce(base) { |result, (find, replace)| result.gsub("%{#{find}}", "#{replace}") }
end