ref: 00a238e32c82b0651e4145e306840cffa46e535d
parent: e5f960245938d8d8b4e99f312e9907f8d3aebf7a
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Mon Jul 29 13:23:10 EDT 2019
Fix i18n project vs theme order Fixes #6134
--- a/hugolib/hugo_modules_test.go
+++ b/hugolib/hugo_modules_test.go
@@ -204,7 +204,7 @@
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 @@
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 @@
// i18n
b.AssertFileContent("public/index.html",
- "i18n hello: Project",
+ "i18n hello1: Project",
"i18n theme: Theme C",
"i18n theme2: Theme2 D",
)
--- a/langs/i18n/translationProvider.go
+++ b/langs/i18n/translationProvider.go
@@ -50,7 +50,11 @@
}
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 @@
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
}
}