maix::i18n
maix.i18n module
This is
maix::i18n
module of MaixCDK.
All of these elements are in namespacemaix::i18n
.For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!
Module
No module
Enum
Variable
locales
i18n locales list
item | description |
---|---|
value | { "en", "zh", "zh-tw", "ja"} |
readonly | False |
C++ defination code:
static std::vector<std::string> locales = { "en", "zh", "zh-tw", "ja"}
names
i18n language names list
item | description |
---|---|
value | { "English", "简体中文", "繁體中文", "日本語"} |
readonly | True |
C++ defination code:
const static std::vector<std::string> names = { "English", "简体中文", "繁體中文", "日本語"}
Function
get_locale
Get system config of locale.
item | description |
---|---|
return | language locale, e.g. en, zh, zh_CN, zh_TW, etc. |
C++ defination code:
string get_locale()
get_language_name
Get system config of language name.
item | description |
---|---|
return | language name, e.g. English, 简体中文, 繁體中文, etc. |
C++ defination code:
string get_language_name()
load_trans_yaml
Load translations from yaml files.
item | description |
---|---|
param | locales_dir: translation yaml files directory. |
return | A dict contains all translations, e.g. {"zh":{"hello": "你好"}, "en":{"hello": "hello"}}, you should delete it after use in C++. |
C++ defination code:
const std::map<string, std::map<string, string>> *load_trans_yaml(const std::string &locales_dir)
load_trans_yaml (overload 1)
Load translations from yaml files.
item | description |
---|---|
param | locales_dir: translation yaml files directory. dict: dict to store key values. A dict contains all translations, e.g. {"zh":{"hello": "你好"}, "en":{"hello": "hello"}}, you should delete it after use in C++. |
return | err::ERR |
C++ defination code:
err::Err load_trans_yaml(const std::string &locales_dir, std::map<string, std::map<string, string>> &dict)
Class
Trans
Translate helper class.
C++ defination code:
class Trans
Trans
Translate helper class constructor.\nBy default locale is get by i18n.get_locale()
function which set by system settings.\nBut you can also manually set by set_locale
function temporarily.
item | description |
---|---|
type | func |
param | locales_dict: locales dict, e.g. {"zh": {"Confirm": "确认", "OK": "好的"}, "en": {"Confirm": "Confirm", "OK": "OK"}} |
static | False |
C++ defination code:
Trans(const std::map<string, const std::map<string, string>> &locales_dict = std::map<string, const std::map<string, string>>())
load
Load translation from yaml files generated by maixtool i18n
command.
item | description |
---|---|
type | func |
param | locales_dir: the translation files directory. |
return | err.Err type, no error will return err.Err.ERR_NONE. |
static | False |
C++ defination code:
err::Err load(const std::string &locales_dir)
update_dict
Update translation dict.
item | description |
---|---|
type | func |
param | dict: the new translation dict. |
return | err.Err type, no error will return err.Err.ERR_NONE. |
static | False |
C++ defination code:
err::Err update_dict(const std::map<std::string, const std::map<std::string, std::string>> &dict)
tr
Translate string by key.
item | description |
---|---|
type | func |
param | key: string key, e.g. "Confirm" locale: locale name, if not assign, use default locale set by system settings or set_locale function. |
return | translated string, if find translation, return it, or return key, e.g. "确认", "Confirm", etc. |
static | False |
C++ defination code:
string tr(const string &key, const string locale = "")
set_locale
Set locale temporarily, will not affect system settings.
item | description |
---|---|
type | func |
param | locale: locale name, e.g. "zh", "en", etc. @see maix.i18n.locales |
static | False |
C++ defination code:
void set_locale(const string &locale)
get_locale
Get current locale.
item | description |
---|---|
type | func |
return | locale name, e.g. "zh", "en", etc. @see maix.i18n.locales |
static | False |
C++ defination code:
string get_locale()