Skip to content

Translations

m.T

m.T(key, default) returns the translated string for key, or default when no translation exists.

go
return msg.Answer(m.T("no_city", "❌ <b>Which city?</b>"))

The default is not a placeholder — it is the shipped English text. A module with no translation files works perfectly; translations are an enhancement.

Always pass a real default

m.T("no_city", "") renders an empty message when the key is missing. Write the sentence you actually want.

Declaring strings

Strings is the catalogue of what your module can say:

go
func (m *Weather) Strings() map[string]string {
	return map[string]string{
		"name":             "Weather",
		"_cls_doc":         "Current weather for a city",
		"_cmd_doc_weather": "[city] — show the weather",
		"no_city":          "❌ <b>Which city?</b>",
		"not_found":        "❌ <b>City not found</b>",
	}
}
PrefixShown in
nameModule name in .help
_cls_docModule description
_cmd_doc_<cmd>That command's help line
_cfg_<key>That setting's description
anything elseWherever you call m.T

How a key is resolved

m.T("no_city", ...) looks for goroku.modules.<module>.no_city, trying your module name as written, lowercased, and snake_cased. Weather therefore matches weather, and APILimiter matches api_limiter.

Legacy names

If your translations live under a name that does not derive from Name(), say so explicitly:

go
func (m *APIProtection) Name() string { return "APILimiter" }

func (m *APIProtection) TranslationAliases() []string {
	return []string{"api_protection"}
}

Aliases are tried after the derived names.

Interpolation

m.T returns the string; formatting is yours:

go
tpl := m.T("found", "🌤 <b>{}</b>: {}°C")
return msg.Answer(strings.Replace(strings.Replace(tpl, "{}", city, 1), "{}", temp, 1))

Prefer named placeholders for anything with more than one value — translators reorder text, and positional {} breaks when they do:

go
tpl := m.T("found", "🌤 <b>{city}</b>: {temp}°C")
out := strings.NewReplacer("{city}", city, "{temp}", temp).Replace(tpl)
return msg.Answer(out)

Escaping

Translated text is Telegram HTML. Escape anything interpolated from users:

go
import "goroku/goroku/utils"

out := strings.Replace(tpl, "{city}", utils.EscapeHTML(city), 1)

Released under the GNU AGPL v3 License.