Skip to main content
Version: 2.8.x(Latest)

As one of the core components of the framework, inheriting the consistent convenience design philosophy of goframe, the configuration management of the I18N internationalization component is very simple.

File Formats

The gi18n internationalization component supports five common configuration file formats: xml/ini/yaml/toml/json/properties (for a more detailed list of file supports, please refer to the configuration management section: Configuration). Similarly, like the configuration management module, the framework recommends using the toml file format.

Reading Path

By default, gi18n will automatically look for and read the following directories under the source root directory of the current project (or the current PWD run directory):

  • manifest/i18n
  • i18n

The found directory is used as the storage directory for international translation files by default. Developers can also customize the storage directory path of i18n files through the SetPath method.

File Storage

In the i18n directory, you can directly name files according to internationalization names such as en.toml/ja.toml/zh-CN.toml; you can also give a directory with the internationalization name and freely customize configuration files under that directory, such as en/editor.toml/en/user.toml, zh-CN/editor.toml/zh-CN/user.toml. You can manage with pure file management or add an additional directory level, and gi18n can intelligently recognize and load.

tip

Internationalized file/directory names can be defined and maintained by developers, primarily for settings and use in the program. It is recommended to name them according to standardized international regional language codes. For more details, refer to WIKI: https://zh.wikipedia.org/wiki/ISO_639-1

For example, the following i18n directory structure and file format are supported.

Distinguish different languages through separate i18n files

└── i18n
├── en.toml
├── ja.toml
├── ru.toml
├── zh-CN.toml
└── zh-TW.toml

Distinguish different languages through different directory names

└── i18n
├── en
│ ├── hello.toml
│ └── world.toml
├── ja
│ ├── hello.yaml
│ └── world.yaml
├── ru
│ ├── hello.ini
│ └── world.ini
├── zh-CN
│ ├── hello.json
│ └── world.json
└── zh-TW
├── hello.xml
└── world.xml

Different languages can have different file formats

└── i18n
├── en.toml
├── ja.yaml
├── ru.ini
├── zh-CN.json
└── zh-TW.xml

Resource Manager

gi18n supports the resource manager by default (for more details, refer to the section: Resource). By default, it will retrieve the manifest/i18n and i18n directories from the gres configuration manager, or the i18n directory path set by the developer.