Skip to content

Commit 97aa9ae

Browse files
committed
feat: add command.info translations
1 parent 1c328fa commit 97aa9ae

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

lang.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,46 +73,47 @@ func Bundle() *i18n.Bundle {
7373
return bundle
7474
}
7575

76-
func GetLocalizer(locale discordgo.Locale) (*Localizer, bool) {
76+
func GetLocalizer(locale discordgo.Locale) *Localizer {
7777
if l, ok := locales[locale]; ok {
78-
return l, true
78+
return l
7979
}
8080

8181
// Use default locale.
82-
return locales[supportedLocales[0]], false
82+
return locales[supportedLocales[0]]
8383
}
8484

8585
func Localize(locale discordgo.Locale, id string) string {
86-
l, _ := GetLocalizer(locale)
87-
return l.Localize(id)
86+
return GetLocalizer(locale).Localize(id)
8887
}
8988

9089
func LocalizeWithData(locale discordgo.Locale, id string, data Data) string {
91-
l, _ := GetLocalizer(locale)
92-
return l.LocalizeWithData(id, data)
90+
return GetLocalizer(locale).LocalizeWithData(id, data)
9391
}
9492

9593
func LocalizePlural(locale discordgo.Locale, id string, count any) string {
96-
l, _ := GetLocalizer(locale)
97-
return l.LocalizePlural(id, count)
94+
return GetLocalizer(locale).LocalizePlural(id, count)
9895
}
9996

10097
func LocalizePluralWithData(locale discordgo.Locale, id string, count any, data Data) string {
101-
l, _ := GetLocalizer(locale)
102-
return l.LocalizePluralWithData(id, count, data)
98+
return GetLocalizer(locale).LocalizePluralWithData(id, count, data)
10399
}
104100

105101
type Localizer struct {
106102
*i18n.Localizer
103+
prefix string
107104
}
108105

109106
func newLocalizer(locale discordgo.Locale) *Localizer {
110107
return &Localizer{Localizer: i18n.NewLocalizer(bundle, string(locale))}
111108
}
112109

110+
func (l *Localizer) Section(name string) *Localizer {
111+
return &Localizer{Localizer: l.Localizer, prefix: name + "."}
112+
}
113+
113114
func (l *Localizer) Localize(id string) string {
114115
s, err := l.Localizer.Localize(&i18n.LocalizeConfig{
115-
MessageID: id,
116+
MessageID: l.prefix + id,
116117
})
117118
if s == "" && err != nil {
118119
return id
@@ -122,7 +123,7 @@ func (l *Localizer) Localize(id string) string {
122123

123124
func (l *Localizer) LocalizeWithData(id string, data Data) string {
124125
s, err := l.Localizer.Localize(&i18n.LocalizeConfig{
125-
MessageID: id,
126+
MessageID: l.prefix + id,
126127
TemplateData: data,
127128
})
128129
if s == "" && err != nil {
@@ -133,7 +134,7 @@ func (l *Localizer) LocalizeWithData(id string, data Data) string {
133134

134135
func (l *Localizer) LocalizePlural(id string, count any) string {
135136
s, err := l.Localizer.Localize(&i18n.LocalizeConfig{
136-
MessageID: id,
137+
MessageID: l.prefix + id,
137138
PluralCount: count,
138139
})
139140
if s == "" && err != nil {
@@ -144,7 +145,7 @@ func (l *Localizer) LocalizePlural(id string, count any) string {
144145

145146
func (l *Localizer) LocalizePluralWithData(id string, count any, data Data) string {
146147
s, err := l.Localizer.Localize(&i18n.LocalizeConfig{
147-
MessageID: id,
148+
MessageID: l.prefix + id,
148149
TemplateData: data,
149150
PluralCount: count,
150151
})

locales/en-GB.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,18 @@ creation-welcome = """
1616
Thank you for creating a ticket. A support team member will be available to assist you shortly. \
1717
While you wait, please provide as much information as possible.\
1818
"""
19+
20+
[command.info]
21+
title = "Information"
22+
version-title = "Version"
23+
version = """
24+
Axolotl v{{.axolotlVersion}} ({{.goVersion}})
25+
Locales v{{.axolotlLangVersion}}
26+
"""
27+
status-title = "Status"
28+
status = """
29+
Uptime: `{{.uptime}}`
30+
Last heartbeat: `{{.lastHeartbeat}}`
31+
"""
32+
supported-locales-title = "Supported Locales"
33+
supported-locale-line = "{{.locale}} by {{.authors}}"

locales/ja.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ creation-welcome = """
2323
チケットを作成していただきありがとうございます。まもなくサポートチームメンバーが対応させていただきます。\
2424
お待ちいただく間、できるだけ多くの情報をご提供ください。\
2525
"""
26+
27+
[command.info]
28+
title = "情報"
29+
version-title = "バージョン"
30+
version = """
31+
Axolotl v{{.axolotlVersion}} ({{.goVersion}})
32+
Locales v{{.axolotlLangVersion}}
33+
"""
34+
status-title = "現状"
35+
status = """
36+
アップタイム: `{{.uptime}}`
37+
最後のハートビート: `{{.lastHeartbeat}}`
38+
"""
39+
supported-locales-title = "対応言語"
40+
supported-locale-line = "{{.locale}}:{{.authors}}"

0 commit comments

Comments
 (0)