From c2167edecb4114bb0bb8597865c118c9b80f1b71 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 30 Nov 2023 01:22:07 +1100 Subject: [PATCH 1/2] refactor i18n yaml to prevent overwriting parent non-English YAML with local English file: https://github.com/metanorma/isodoc/issues/549 --- Gemfile.devel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.devel b/Gemfile.devel index 4d0eb15..e3a37c0 100644 --- a/Gemfile.devel +++ b/Gemfile.devel @@ -1 +1 @@ -gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/recursive-prefix-container" +gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/i18n-yaml-inheritance" From 243fd0ce748d49df25ee04011ff5290c21d4706d Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 30 Nov 2023 01:22:21 +1100 Subject: [PATCH 2/2] refactor i18n yaml to prevent overwriting parent non-English YAML with local English file: https://github.com/metanorma/isodoc/issues/549 --- lib/isodoc/ieee/i18n.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/isodoc/ieee/i18n.rb b/lib/isodoc/ieee/i18n.rb index ad438fd..e5ab63a 100644 --- a/lib/isodoc/ieee/i18n.rb +++ b/lib/isodoc/ieee/i18n.rb @@ -1,18 +1,14 @@ module IsoDoc module IEEE class I18n < IsoDoc::I18n - def load_yaml2x(str) - ::YAML.load_file(File.join(File.dirname(__FILE__), - "i18n-#{str}.yaml")) + def load_file(fname) + f = File.join(File.dirname(__FILE__), fname) + File.exist?(f) ? YAML.load_file(f) : {} end def load_yaml1(lang, script) - y = case lang - when "en" - load_yaml2x(lang) - else load_yaml2x("en") - end - super.deep_merge(y) + y = load_file("i18n-#{yaml_lang(lang, script)}.yaml") + y.empty? ? load_file("i18n-en.yaml").merge(super) : super.deep_merge(y) end end end