Skip to content
Permalink
Browse files

Fix i18n project vs theme order

Fixes #6134
  • Loading branch information...
bep committed Jul 29, 2019
1 parent e5f9602 commit 00a238e32c82b0651e4145e306840cffa46e535d
Showing with 16 additions and 10 deletions.
  1. +9 −5 hugolib/hugo_modules_test.go
  2. +7 −5 langs/i18n/translationProvider.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",
)
@@ -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
}
}

0 comments on commit 00a238e

Please sign in to comment.
You can’t perform that action at this time.