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/text
are 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/text
packages to manage translations in your application. Specifically:
- How to use the
golang.org/x/text/language
andgolang.org/x/text/message
packages to print translated messages from your Go code.- How to use the
gotext
tool to automatically extract messages for translation from your code into JSON files.- How to use
gotext
to 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.