Multi-language support
In the chapter where we introduced internationalization and localization, we developed the go-i18n
library. In this section, we will see how this library is integrated into the Beego framework, and how it enables our Beego applications to support both internationalization and localization.
I18n integration
Beego first sets some global variables:
A multi-language initialization function is defined:
In order to facilitate multi-language calls in the template package directly, we designed three functions for handling multi-language responses:
Multi-language development
Setting the language and location of the language pack, then initialize i18n objects:
Designing a multi-language package
Above, we talked about how to initialize a multi-language package. Now, let's look at how to design one. Multi-language packages are typically JSON files, as you've already seen in Chapter 10. We must provide translation files for languages we wish to support on our
LangPath
, such as the following:Using language packages
We can call the controller to get the translated response in the desired language, like so:
We can also directly interpolate translated responses in our templates:
Links
Last updated
Was this helpful?