The i18n module provides tools for implementing i18n and m17n features.

Enabling the i18n module

To enable the i18n module, update your uvproj.yaml so that the i18n key under enabled-modules is set to true like this:

name: "MyProject"
version: "1.0.0.0"
engine-version: "1.0.0.0"
enabled-modules:
  i18n: true

Then, regenerate the modules cache by running the following command:

user $ https://madladsquad.com/UVKBuildTool --generate <project directory>

After that, refresh your CMake project with cmake ..!


Next, in your source file, include the Modules.hpp header in your components like this:

#include <Modules/Modules.hpp>

Event safety

The entire module is flagged as event safe at any time.

Using the module

Defining your strings for translation

The module is based on the UntitledI18N library. You can find out more about the translation format here.

All translations are stored under the Config/Translations/ directory. When the module is enabled, translations are loaded automatically with the default locale being set to en_US.

Interacting with the module interface

The i18n module is under the I18N class. It looks like this:

class I18N
{
public:
    static void setCurrentLocale(UI18N::LanguageCodes locale) noexcept;

    static ui18nstring get(const char* id, const std::vector<ui18nstring>& positionalArgs = {}, const ui18nmap<ui18nstring, ui18nstring>& args = {}) noexcept;
    static void pushVariable(const ui18nstring& name, const ui18nstring& val) noexcept;

    static const std::vector<UI18N::LanguageCodes>& getExistingLocales() noexcept;

    static UI18N::TranslationEngine& getEngine() noexcept;
};

The functions are almost identical to the ones provided by the TranslationEngine class in the underlying UntitledI18N library. More info here.

We also provide a C API that looks like this:

const char* UImGui_I18N_get(const char* id, char** pargv, size_t pargc, UI18N_Pair* argv, size_t argc);
void UImGui_I18N_pushVariable(const char* name, const char* val);
void UImGui_I18N_setCurrentLocale(UI18N_LanguageCodes locale);
const UI18N_LanguageCodes* UImGui_I18N_getExistingLocales(size_t* size);

The functions are also identical to the C version of the TranslationEngine API. More info here.

Checking for the module

To check for the module at compile time, use the UIMGUI_I18N_MODULE_ENABLED macro.

Runtime checking can be done using the i18n member of the ModuleSettings struct. More info can be found here.