Internationalization and localization

The framework comes with a basic localization functionality.


Before using the locale, you must configure the app with the translation map:

lang := map[string]map[string]string{
	"Hello": {
		"en-US": "Hello",
		"fr-FR": "Bonjour",
	"Please try again": {
		"en-US": "Please try again",
		"fr-FR": "Veuillez réessayer",
	"oranges": {
		"en-US": "There is one orange|There are many oranges",
		"fr-FR": "Il y a une orange|Il y a beaucoup d'oranges",

app := gotuna.App{
	Locale: gotuna.NewLocale(lang),

The current locale is usually stored in user’s session:

app.Session.SetLocale(w, r, "en-US")
locale := app.Session.GetLocale(r)

Translating text

You can translate strings in your html templates using the t (translate) or tp (translate plural) helper:

<label class="label">{{t "Hello"}}</label>
<label class="label">{{tp "oranges" 5}}</label>

You can also translate strings in the rest of the app:

tryAgain := app.Locale.T(app.Session.GetUserLocale(r), "Please try again"))
oranges := app.Locale.TP("fr-FR", "oranges", 5))

Edit this page on GitHub