👔 Search translated versions of current page in Page use case
This commit is contained in:
parent
fdaf5be031
commit
61cc8075db
|
@ -3,7 +3,9 @@ package usecase
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
|
@ -49,7 +51,38 @@ func (ucase *pageUseCase) Do(ctx context.Context, lang language.Tag, p string) (
|
|||
continue
|
||||
}
|
||||
|
||||
out.Resources, _, _ = ucase.statics.Fetch(ctx, out.File.Dir()+"*")
|
||||
if out.Resources, _, err = ucase.statics.Fetch(ctx, out.File.Dir()+"*"); err != nil {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
for _, res := range out.Resources.GetType(domain.ResourceTypePage) {
|
||||
// TODO(toby3d): simplify this, it's awful
|
||||
resName := path.Base(res.Key())
|
||||
resExt := path.Ext(resName)
|
||||
resParts := strings.Split(resName[:len(resName)-len(resExt)], ".")
|
||||
|
||||
translationBaseName := strings.Join(resParts[:len(resParts)-1], ".")
|
||||
if translationBaseName != out.File.TranslationBaseName() {
|
||||
continue
|
||||
}
|
||||
|
||||
resLang := language.Make(resParts[len(resParts)-1])
|
||||
if resLang == language.Und {
|
||||
continue
|
||||
}
|
||||
|
||||
translation, err := ucase.pages.Get(ctx, resLang, targets[i])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
out.Translations = append(out.Translations, translation)
|
||||
}
|
||||
|
||||
translations := make([]string, 0)
|
||||
for i := range out.Translations {
|
||||
translations = append(translations, out.Translations[i].Language.String())
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue