diff --git a/lang.go b/lang.go index f260d0f..7aef139 100644 --- a/lang.go +++ b/lang.go @@ -73,46 +73,47 @@ func Bundle() *i18n.Bundle { return bundle } -func GetLocalizer(locale discordgo.Locale) (*Localizer, bool) { +func GetLocalizer(locale discordgo.Locale) *Localizer { if l, ok := locales[locale]; ok { - return l, true + return l } // Use default locale. - return locales[supportedLocales[0]], false + return locales[supportedLocales[0]] } func Localize(locale discordgo.Locale, id string) string { - l, _ := GetLocalizer(locale) - return l.Localize(id) + return GetLocalizer(locale).Localize(id) } func LocalizeWithData(locale discordgo.Locale, id string, data Data) string { - l, _ := GetLocalizer(locale) - return l.LocalizeWithData(id, data) + return GetLocalizer(locale).LocalizeWithData(id, data) } func LocalizePlural(locale discordgo.Locale, id string, count any) string { - l, _ := GetLocalizer(locale) - return l.LocalizePlural(id, count) + return GetLocalizer(locale).LocalizePlural(id, count) } func LocalizePluralWithData(locale discordgo.Locale, id string, count any, data Data) string { - l, _ := GetLocalizer(locale) - return l.LocalizePluralWithData(id, count, data) + return GetLocalizer(locale).LocalizePluralWithData(id, count, data) } type Localizer struct { *i18n.Localizer + prefix string } func newLocalizer(locale discordgo.Locale) *Localizer { return &Localizer{Localizer: i18n.NewLocalizer(bundle, string(locale))} } +func (l *Localizer) Section(name string) *Localizer { + return &Localizer{Localizer: l.Localizer, prefix: name + "."} +} + func (l *Localizer) Localize(id string) string { s, err := l.Localizer.Localize(&i18n.LocalizeConfig{ - MessageID: id, + MessageID: l.prefix + id, }) if s == "" && err != nil { return id @@ -122,7 +123,7 @@ func (l *Localizer) Localize(id string) string { func (l *Localizer) LocalizeWithData(id string, data Data) string { s, err := l.Localizer.Localize(&i18n.LocalizeConfig{ - MessageID: id, + MessageID: l.prefix + id, TemplateData: data, }) if s == "" && err != nil { @@ -133,7 +134,7 @@ func (l *Localizer) LocalizeWithData(id string, data Data) string { func (l *Localizer) LocalizePlural(id string, count any) string { s, err := l.Localizer.Localize(&i18n.LocalizeConfig{ - MessageID: id, + MessageID: l.prefix + id, PluralCount: count, }) if s == "" && err != nil { @@ -144,7 +145,7 @@ func (l *Localizer) LocalizePlural(id string, count any) string { func (l *Localizer) LocalizePluralWithData(id string, count any, data Data) string { s, err := l.Localizer.Localize(&i18n.LocalizeConfig{ - MessageID: id, + MessageID: l.prefix + id, TemplateData: data, PluralCount: count, }) diff --git a/locales/en-GB.toml b/locales/en-GB.toml index 30e3c0b..7ecbd7e 100644 --- a/locales/en-GB.toml +++ b/locales/en-GB.toml @@ -16,3 +16,18 @@ creation-welcome = """ Thank you for creating a ticket. A support team member will be available to assist you shortly. \ While you wait, please provide as much information as possible.\ """ + +[command.info] +title = "Information" +version-title = "Version" +version = """ +Axolotl v{{.axolotlVersion}} ({{.goVersion}}) +Locales v{{.axolotlLangVersion}} +""" +status-title = "Status" +status = """ +Uptime: `{{.uptime}}` +Last heartbeat: `{{.lastHeartbeat}}` +""" +supported-locales-title = "Supported Locales" +supported-locale-line = "{{.locale}} by {{.authors}}" diff --git a/locales/ja.toml b/locales/ja.toml index 5ead74a..ed435d9 100644 --- a/locales/ja.toml +++ b/locales/ja.toml @@ -23,3 +23,18 @@ creation-welcome = """ チケットを作成していただきありがとうございます。まもなくサポートチームメンバーが対応させていただきます。\ お待ちいただく間、できるだけ多くの情報をご提供ください。\ """ + +[command.info] +title = "情報" +version-title = "バージョン" +version = """ +Axolotl v{{.axolotlVersion}} ({{.goVersion}}) +Locales v{{.axolotlLangVersion}} +""" +status-title = "現状" +status = """ +アップタイム: `{{.uptime}}` +最後のハートビート: `{{.lastHeartbeat}}` +""" +supported-locales-title = "対応言語" +supported-locale-line = "{{.locale}}:{{.authors}}"