mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-17 13:07:16 +02:00
* Add Russian translation * turn on ru.toml * load gently Co-authored-by: Filiph Protsenko <filprocenko@gmail.com> Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package i18n
|
|
|
|
import (
|
|
"github.com/BurntSushi/toml"
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
log "github.com/sirupsen/logrus"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
var Bundle *i18n.Bundle
|
|
|
|
func init() {
|
|
Bundle = RegisterLanguages()
|
|
}
|
|
|
|
func RegisterLanguages() *i18n.Bundle {
|
|
bundle := i18n.NewBundle(language.English)
|
|
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
|
bundle.MustLoadMessageFile("translations/en.toml")
|
|
bundle.LoadMessageFile("translations/de.toml")
|
|
bundle.LoadMessageFile("translations/it.toml")
|
|
bundle.LoadMessageFile("translations/es.toml")
|
|
bundle.LoadMessageFile("translations/nl.toml")
|
|
bundle.LoadMessageFile("translations/fr.toml")
|
|
bundle.LoadMessageFile("translations/pt-br.toml")
|
|
bundle.LoadMessageFile("translations/tr.toml")
|
|
bundle.LoadMessageFile("translations/id.toml")
|
|
bundle.LoadMessageFile("translations/ru.toml")
|
|
return bundle
|
|
}
|
|
func Translate(languageCode string, MessgeID string) string {
|
|
str, err := i18n.NewLocalizer(Bundle, languageCode).Localize(&i18n.LocalizeConfig{MessageID: MessgeID})
|
|
if err != nil {
|
|
log.Warnf("Error translating message %s: %s", MessgeID, err)
|
|
}
|
|
return str
|
|
}
|