Home

Serve multiple languages with Go templates

There are several methods to make an Go web app "multilingual". In this exmple I have chosen to store the translations in .po files. One language per file.

Next step was to find out how to make this translations on-the-fly without any noticeable delay. This concept builds on calling a function from within a Go template.

Finally the personal setting could be stored in a cookie for the server to select the desired language.

From this...

{{trans "Company"}}

...to this

Company


Note that only menu items are translated. Content will still be in English.