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
|
|
|
|
2017-11-26 00:56:44 +01:00
|
|
|
// Translator manage supported locales.
|
2017-11-20 06:10:04 +01:00
|
|
|
type Translator struct {
|
2018-09-22 03:53:29 +02:00
|
|
|
locales catalog
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
2017-11-26 00:56:44 +01:00
|
|
|
// AddLanguage loads a new language into the system.
|
2018-09-22 03:53:29 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-26 00:56:44 +01:00
|
|
|
// GetLanguage returns the given language handler.
|
2017-11-20 06:10:04 +01:00
|
|
|
func (t *Translator) GetLanguage(language string) *Language {
|
2017-11-26 00:56:44 +01:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2017-11-26 00:56:44 +01:00
|
|
|
// NewTranslator creates a new Translator.
|
2017-11-20 06:10:04 +01:00
|
|
|
func NewTranslator() *Translator {
|
2018-09-22 03:53:29 +02:00
|
|
|
return &Translator{locales: make(catalog)}
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|