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



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/isodoc/jis/i18n.rb', line 22

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



35
36
37
38
39
40
41
# File 'lib/isodoc/jis/i18n.rb', line 35

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 StandardError
  time.year.to_s
end

#jis_load_file(fname) ⇒ Object



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

def jis_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
16
17
18
19
# File 'lib/isodoc/jis/i18n.rb', line 12

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