mirror of
https://github.com/gohugoio/hugo.git
synced 2025-01-14 23:12:25 +00:00
Revert "i18n: Allow custom language codes"
This reverts commit bb04010cbf
.
This commit is contained in:
parent
b3443b3d0c
commit
b88a105a7c
2 changed files with 0 additions and 41 deletions
|
@ -23,11 +23,9 @@ import (
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
"github.com/nicksnyder/go-i18n/i18n/bundle"
|
"github.com/nicksnyder/go-i18n/i18n/bundle"
|
||||||
"github.com/nicksnyder/go-i18n/i18n/language"
|
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = jww.NewNotepad(jww.LevelError, jww.LevelError, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)
|
var logger = jww.NewNotepad(jww.LevelError, jww.LevelError, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)
|
||||||
|
@ -139,29 +137,10 @@ var i18nTests = []i18nTest{
|
||||||
expected: "hello",
|
expected: "hello",
|
||||||
expectedFlag: "[i18n] hello",
|
expectedFlag: "[i18n] hello",
|
||||||
},
|
},
|
||||||
// Non Unicode CLDR language code
|
|
||||||
{
|
|
||||||
data: map[string][]byte{
|
|
||||||
"dk.toml": []byte("[hello]\nother = \"hej\""),
|
|
||||||
},
|
|
||||||
args: nil,
|
|
||||||
lang: "dk",
|
|
||||||
id: "hello",
|
|
||||||
expected: "hej",
|
|
||||||
expectedFlag: "hej",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestI18nTranslate(t *testing.T, test i18nTest, cfg config.Provider) string {
|
func doTestI18nTranslate(t *testing.T, test i18nTest, cfg config.Provider) string {
|
||||||
i18nBundle := bundle.New()
|
i18nBundle := bundle.New()
|
||||||
ids := []string{}
|
|
||||||
|
|
||||||
for file := range test.data {
|
|
||||||
id := strings.TrimSuffix(file, ".toml")
|
|
||||||
ids = append(ids, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
language.RegisterPluralSpec(ids, &language.PluralSpec{})
|
|
||||||
|
|
||||||
for file, content := range test.data {
|
for file, content := range test.data {
|
||||||
err := i18nBundle.ParseTranslationFileBytes(file, content)
|
err := i18nBundle.ParseTranslationFileBytes(file, content)
|
||||||
|
|
|
@ -15,18 +15,12 @@ package i18n
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/deps"
|
"github.com/gohugoio/hugo/deps"
|
||||||
"github.com/gohugoio/hugo/source"
|
"github.com/gohugoio/hugo/source"
|
||||||
"github.com/nicksnyder/go-i18n/i18n/bundle"
|
"github.com/nicksnyder/go-i18n/i18n/bundle"
|
||||||
"github.com/nicksnyder/go-i18n/i18n/language"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unfortunately this needs to be global, see
|
|
||||||
// https://github.com/nicksnyder/go-i18n/issues/82
|
|
||||||
var tpMu sync.Mutex
|
|
||||||
|
|
||||||
// TranslationProvider provides translation handling, i.e. loading
|
// TranslationProvider provides translation handling, i.e. loading
|
||||||
// of bundles etc.
|
// of bundles etc.
|
||||||
type TranslationProvider struct {
|
type TranslationProvider struct {
|
||||||
|
@ -40,9 +34,6 @@ func NewTranslationProvider() *TranslationProvider {
|
||||||
|
|
||||||
// Update updates the i18n func in the provided Deps.
|
// Update updates the i18n func in the provided Deps.
|
||||||
func (tp *TranslationProvider) Update(d *deps.Deps) error {
|
func (tp *TranslationProvider) Update(d *deps.Deps) error {
|
||||||
tpMu.Lock()
|
|
||||||
defer tpMu.Unlock()
|
|
||||||
|
|
||||||
dir := d.PathSpec.AbsPathify(d.Cfg.GetString("i18nDir"))
|
dir := d.PathSpec.AbsPathify(d.Cfg.GetString("i18nDir"))
|
||||||
sp := source.NewSourceSpec(d.Cfg, d.Fs)
|
sp := source.NewSourceSpec(d.Cfg, d.Fs)
|
||||||
sources := []source.Input{sp.NewFilesystem(dir)}
|
sources := []source.Input{sp.NewFilesystem(dir)}
|
||||||
|
@ -57,17 +48,6 @@ func (tp *TranslationProvider) Update(d *deps.Deps) error {
|
||||||
|
|
||||||
i18nBundle := bundle.New()
|
i18nBundle := bundle.New()
|
||||||
|
|
||||||
langs := []string{}
|
|
||||||
for _, currentSource := range sources {
|
|
||||||
for _, r := range currentSource.Files() {
|
|
||||||
langs = append(langs, r.BaseFileName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// We need to register all language codes as "plural spec" to prevent errors with unknown language codes.
|
|
||||||
// see https://github.com/gohugoio/hugo/issues/3564
|
|
||||||
ps := &language.PluralSpec{}
|
|
||||||
language.RegisterPluralSpec(langs, ps)
|
|
||||||
|
|
||||||
for _, currentSource := range sources {
|
for _, currentSource := range sources {
|
||||||
for _, r := range currentSource.Files() {
|
for _, r := range currentSource.Files() {
|
||||||
err := i18nBundle.ParseTranslationFileBytes(r.LogicalName(), r.Bytes())
|
err := i18nBundle.ParseTranslationFileBytes(r.LogicalName(), r.Bytes())
|
||||||
|
|
Loading…
Reference in a new issue