From 00a238e32c82b0651e4145e306840cffa46e535d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 29 Jul 2019 17:23:10 +0200 Subject: [PATCH] Fix i18n project vs theme order Fixes #6134 --- hugolib/hugo_modules_test.go | 14 +++++++++----- langs/i18n/translationProvider.go | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 171bbb34..73a3d2db 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -204,7 +204,7 @@ Data C: {{ $data.c.value }} Data D: {{ $data.d.value }} All Data: {{ $data }} -i18n hello: {{ i18n "hello" . }} +i18n hello1: {{ i18n "hello1" . }} i18n theme: {{ i18n "theme" . }} i18n theme2: {{ i18n "theme2" . }} `) @@ -238,9 +238,13 @@ other = %q b.WithSourceFile("themes/d/data/d.toml", `value="Hugo Rodks!"`) // i18n files - b.WithSourceFile("i18n/en.toml", i18nContent("hello", "Project")) - b.WithSourceFile("themes/c/en.toml", i18nContent("hello", "Theme C")) - b.WithSourceFile("themes/c/i18n/en.toml", i18nContent("theme", "Theme C")) + b.WithSourceFile("i18n/en.toml", i18nContent("hello1", "Project")) + b.WithSourceFile("themes/c/i18n/en.toml", ` +[hello1] +other="Theme C Hello" +[theme] +other="Theme C" +`) b.WithSourceFile("themes/d/i18n/en.toml", i18nContent("theme", "Theme D")) b.WithSourceFile("themes/d/i18n/en.toml", i18nContent("theme2", "Theme2 D")) @@ -261,7 +265,7 @@ other = %q // i18n b.AssertFileContent("public/index.html", - "i18n hello: Project", + "i18n hello1: Project", "i18n theme: Theme C", "i18n theme2: Theme2 D", ) diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go index c7b4839e..4ce9b59f 100644 --- a/langs/i18n/translationProvider.go +++ b/langs/i18n/translationProvider.go @@ -50,7 +50,11 @@ func (tp *TranslationProvider) Update(d *deps.Deps) error { } var newLangs []string - for _, dir := range d.BaseFs.I18n.Dirs { + // The source dirs are ordered so the most important comes first. Since this is a + // last key win situation, we have to reverse the iteration order. + dirs := d.BaseFs.I18n.Dirs + for i := len(dirs) - 1; i >= 0; i-- { + dir := dirs[i] src := spec.NewFilesystemFromFileMetaInfo(dir) files, err := src.Files() @@ -71,10 +75,8 @@ func (tp *TranslationProvider) Update(d *deps.Deps) error { language.RegisterPluralSpec(newLangs, en) } - // The source files are ordered so the most important comes first. Since this is a - // last key win situation, we have to reverse the iteration order. - for i := len(files) - 1; i >= 0; i-- { - if err := addTranslationFile(i18nBundle, files[i]); err != nil { + for _, file := range files { + if err := addTranslationFile(i18nBundle, file); err != nil { return err } } -- 2.30.2