diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-09-22 15:04:55 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-09-22 15:04:55 -0700 |
commit | b1e8f534eff7569dc2e8dab4dee851d1b709f71b (patch) | |
tree | ec9d5cbebc78704727c9ce959f442b3df5cc7d76 /locale/catalog.go | |
parent | aae9b4eb835c72c0b7ecd8fa6565eacce3963d00 (diff) |
Simplify locale package usage (refactoring)
Diffstat (limited to 'locale/catalog.go')
-rw-r--r-- | locale/catalog.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/locale/catalog.go b/locale/catalog.go new file mode 100644 index 0000000..926298c --- /dev/null +++ b/locale/catalog.go @@ -0,0 +1,36 @@ +// Copyright 2018 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package locale // import "miniflux.app/locale" + +import ( + "encoding/json" + "fmt" +) + +type translationDict map[string]interface{} +type catalog map[string]translationDict + +var defaultCatalog catalog + +func init() { + defaultCatalog = make(catalog) + + for language, data := range translations { + messages, err := parseTranslationDict(data) + if err != nil { + panic(err) + } + + defaultCatalog[language] = messages + } +} + +func parseTranslationDict(data string) (translationDict, error) { + var translations translationDict + if err := json.Unmarshal([]byte(data), &translations); err != nil { + return nil, fmt.Errorf("invalid translation file: %v", err) + } + return translations, nil +} |