Skip to content

Commit 7dc87cd

Browse files
committed
refactor i18n yaml to prevent overwriting parent non-English YAML with local English file: metanorma/isodoc#549
1 parent 1148843 commit 7dc87cd

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

lib/isodoc/iso/i18n.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module IsoDoc
22
module Iso
33
class I18n < IsoDoc::I18n
44
def load_file(fname)
5-
YAML.load_file(File.join(File.dirname(__FILE__), fname)) ||
6-
{}
5+
f = File.join(File.dirname(__FILE__), fname)
6+
File.exist?(f) ? YAML.load_file(f) : {}
77
end
88

99
def load_yaml1(lang, script)

lib/isodoc/iso/presentation_bibdata.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def bibdata_i18n(bib)
7373
def bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n)
7474
return unless stage
7575

76-
i18n.get["stage_dict"][stage.text].is_a?(Hash) or
76+
i18n.get.dig("stage_dict", stage.text).is_a?(Hash) or
7777
return hash_translate(bib, i18n.get["stage_dict"],
7878
"./status/stage", lang)
79-
stagetype = i18n.get["stage_dict"][stage.text][type&.text] and
79+
stagetype = i18n.get.dig("stage_dict", stage.text, type&.text) and
8080
tag_translate(stage, lang, stagetype)
8181
end
8282
end

spec/isodoc/i18n_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -549,17 +549,15 @@
549549
<bibdata>
550550
<status>
551551
<stage abbreviation='IS' language=''>60</stage>
552-
<stage abbreviation='IS' language='tlh'>International Standard</stage>
553552
</status>
554553
<language current='true'>tlh</language>
555554
<ext>
556555
<doctype language=''>international-standard</doctype>
557-
<doctype language='tlh'>International Standard</doctype>
558556
</ext>
559557
</bibdata>
560558
<preface>
561559
<clause type="toc" id="_" displayorder="1">
562-
<title depth="1">Contents</title>
560+
<title depth="1">Table of contents</title>
563561
</clause>
564562
<foreword obligation="informative" displayorder='2'>
565563
<title>Foreword</title>

0 commit comments

Comments
 (0)