miniflux/locale/translator.go

32 lines
899 B
Go
Raw Normal View History

2017-11-20 06:10:04 +01:00
// Copyright 2017 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.
2018-08-25 06:51:50 +02:00
package locale // import "miniflux.app/locale"
2017-11-20 06:10:04 +01:00
// Translator manage supported locales.
2017-11-20 06:10:04 +01:00
type Translator struct {
locales catalog
2017-11-20 06:10:04 +01:00
}
// AddLanguage loads a new language into the system.
func (t *Translator) AddLanguage(language, data string) (err error) {
t.locales[language], err = parseCatalogMessages(data)
return err
2017-11-20 06:10:04 +01:00
}
// GetLanguage returns the given language handler.
2017-11-20 06:10:04 +01:00
func (t *Translator) GetLanguage(language string) *Language {
translations, found := t.locales[language]
2017-11-20 06:10:04 +01:00
if !found {
return &Language{language: language}
}
return &Language{language: language, translations: translations}
}
// NewTranslator creates a new Translator.
2017-11-20 06:10:04 +01:00
func NewTranslator() *Translator {
return &Translator{locales: make(catalog)}
2017-11-20 06:10:04 +01:00
}