Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'langs/i18n')
-rw-r--r--langs/i18n/i18n_test.go13
-rw-r--r--langs/i18n/translationProvider.go56
2 files changed, 43 insertions, 26 deletions
diff --git a/langs/i18n/i18n_test.go b/langs/i18n/i18n_test.go
index b67cabc55..e08210848 100644
--- a/langs/i18n/i18n_test.go
+++ b/langs/i18n/i18n_test.go
@@ -17,11 +17,13 @@ import (
"path/filepath"
"testing"
+ "github.com/gohugoio/hugo/modules"
+
"github.com/gohugoio/hugo/tpl/tplimpl"
"github.com/gohugoio/hugo/common/loggers"
- "github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/langs"
+ "github.com/gohugoio/hugo/resources/page"
"github.com/spf13/afero"
"github.com/spf13/viper"
@@ -199,7 +201,7 @@ func newDepsConfig(tp *TranslationProvider, cfg config.Provider, fs *hugofs.Fs)
l.Set("i18nDir", "i18n")
return deps.DepsCfg{
Language: l,
- Site: htesting.NewTestHugoSite(),
+ Site: page.NewDummyHugoSite(cfg),
Cfg: cfg,
Fs: fs,
Logger: logger,
@@ -219,6 +221,13 @@ func getConfig() *viper.Viper {
v.Set("assetDir", "assets")
v.Set("resourceDir", "resources")
v.Set("publishDir", "public")
+ langs.LoadLanguageSettings(v, nil)
+ mod, err := modules.CreateProjectModule(v)
+ if err != nil {
+ panic(err)
+ }
+ v.Set("allModules", modules.Modules{mod})
+
return v
}
diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go
index 74e144007..c7b4839ee 100644
--- a/langs/i18n/translationProvider.go
+++ b/langs/i18n/translationProvider.go
@@ -40,8 +40,7 @@ func NewTranslationProvider() *TranslationProvider {
// Update updates the i18n func in the provided Deps.
func (tp *TranslationProvider) Update(d *deps.Deps) error {
- sp := source.NewSourceSpec(d.PathSpec, d.BaseFs.SourceFilesystems.I18n.Fs)
- src := sp.NewFilesystem("")
+ spec := source.NewSourceSpec(d.PathSpec, nil)
i18nBundle := bundle.New()
@@ -51,25 +50,33 @@ func (tp *TranslationProvider) Update(d *deps.Deps) error {
}
var newLangs []string
- for _, r := range src.Files() {
- currentSpec := language.GetPluralSpec(r.BaseFileName())
- if currentSpec == nil {
- // This may is a language code not supported by go-i18n, it may be
- // Klingon or ... not even a fake language. Make sure it works.
- newLangs = append(newLangs, r.BaseFileName())
+ for _, dir := range d.BaseFs.I18n.Dirs {
+ src := spec.NewFilesystemFromFileMetaInfo(dir)
+
+ files, err := src.Files()
+ if err != nil {
+ return err
}
- }
- if len(newLangs) > 0 {
- language.RegisterPluralSpec(newLangs, en)
- }
+ for _, r := range files {
+ currentSpec := language.GetPluralSpec(r.BaseFileName())
+ if currentSpec == nil {
+ // This may is a language code not supported by go-i18n, it may be
+ // Klingon or ... not even a fake language. Make sure it works.
+ newLangs = append(newLangs, r.BaseFileName())
+ }
+ }
- // 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.
- files := src.Files()
- for i := len(files) - 1; i >= 0; i-- {
- if err := addTranslationFile(i18nBundle, files[i]); err != nil {
- return err
+ if len(newLangs) > 0 {
+ 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 {
+ return err
+ }
}
}
@@ -81,8 +88,8 @@ func (tp *TranslationProvider) Update(d *deps.Deps) error {
}
-func addTranslationFile(bundle *bundle.Bundle, r source.ReadableFile) error {
- f, err := r.Open()
+func addTranslationFile(bundle *bundle.Bundle, r source.File) error {
+ f, err := r.FileInfo().Meta().Open()
if err != nil {
return _errors.Wrapf(err, "failed to open translations file %q:", r.LogicalName())
}
@@ -101,14 +108,15 @@ func (tp *TranslationProvider) Clone(d *deps.Deps) error {
return nil
}
-func errWithFileContext(inerr error, r source.ReadableFile) error {
- rfi, ok := r.FileInfo().(hugofs.RealFilenameInfo)
+func errWithFileContext(inerr error, r source.File) error {
+ fim, ok := r.FileInfo().(hugofs.FileMetaInfo)
if !ok {
return inerr
}
- realFilename := rfi.RealFilename()
- f, err := r.Open()
+ meta := fim.Meta()
+ realFilename := meta.Filename()
+ f, err := meta.Open()
if err != nil {
return inerr
}