aboutsummaryrefslogtreecommitdiffhomepage
path: root/locale/catalog.go
blob: 926298cbabac0422769a5af4ea52ab304f45d2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}