mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Simplify locale package usage (refactoring)
This commit is contained in:
parent
aae9b4eb83
commit
b1e8f534ef
26 changed files with 443 additions and 299 deletions
36
locale/catalog.go
Normal file
36
locale/catalog.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue