Class: IsoDoc::JIS::I18n

Inherits:
Iso::I18n
  • Object
show all
Defined in:
lib/isodoc/jis/i18n.rb

Instance Method Summary collapse

Instance Method Details

#japanese_date(date) ⇒ Object

use Japanese ordinals for era years



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/isodoc/jis/i18n.rb', line 18

def japanese_date(date)
  date.nil? and return date
  d = date.split(/-/).map(&:to_i)
  time = Date.new(*d)
  yr = japanese_year(time)
  case d.size
  when 1 then yr
  when 2 then yr + time.strftime("%-m月")
  when 3 then yr + time.strftime("%-m月%-d日")
  else date
  end
end

#japanese_year(time) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/isodoc/jis/i18n.rb', line 31

def japanese_year(time)
  era_yr = time.era_year.to_i.localize(:ja)
    .to_rbnf_s("SpelloutRules", "spellout-numbering-year")
  "#{time.strftime('%JN')}#{era_yr}"
rescue
  time.year.to_s
end

#load_file(fname) ⇒ Object



7
8
9
10
# File 'lib/isodoc/jis/i18n.rb', line 7

def load_file(fname)
  f = File.join(File.dirname(__FILE__), fname)
  File.exist?(f) ? YAML.load_file(f) : {}
end

#load_yaml1(lang, script) ⇒ Object



12
13
14
15
# File 'lib/isodoc/jis/i18n.rb', line 12

def load_yaml1(lang, script)
  y = load_file("i18n-#{yaml_lang(lang, script)}.yaml")
  y.empty? ? load_file("i18n-en.yaml").merge(super) : super.deep_merge(y)
end