I18n in Go: Managing Translations
Recently I've been building a fully internationalized (i18n) and localized (l10n) web application for the first time with Go's golang.org/x/text packages. I've found that the packages and tools that live under
golang.org/x/textare really effective and well designed, although it's been a bit of a challenge to figure out how to put it all together in a real application.In this tutorial I want to explain how you can use
golang.org/x/textpackages to manage translations in your application. Specifically:
- How to use the
golang.org/x/text/languageandgolang.org/x/text/messagepackages to print translated messages from your Go code.- How to use the
gotexttool to automatically extract messages for translation from your code into JSON files.- How to use
gotextto parse translated JSON files and create a catalog containing translated messages.- How to manage variables in messages and provided pluralized versions of translations.
Source: I18n in Go: Managing Translations, an article by Alex Edwards.