lv_translation.h¶
Functions
-
void lv_translation_init(void)¶
Initialize the translation module
-
void lv_translation_deinit(void)¶
De-initialize the translation module and free all allocated translations
-
lv_translation_pack_t *lv_translation_add_static(const char *languages[], const char *tags[], const char *translations[])¶
Register a translation pack from static arrays. All the pointers need to be static, that is to live while they are used
- Parameters:
languages – List of languages. E.g.
{"en", "de", NULL}
tags – Tags that are using in the UI. E.g.
{"dog", "cat", NULL}
translations – List of translations. E.g.
{"Dog", "Cat", "Hund", "Katze"}
- Returns:
The created pack
-
lv_translation_pack_t *lv_translation_add_dynamic(void)¶
Add a pack to which translations can be added dynamically.
pack->languages
needs to be a malloc-ed array where each language is also malloc-ed as an element.pack->translation_array
stores the translation havinglv_translation_tag_dsc_t
items In each array elementtag
is a malloced string,translations
is a malloc-ed array with malloc-ed array for each element.- Returns:
the created pack to which data can be added manually.
-
void lv_translation_set_language(const char *lang)¶
Select the current language
- Parameters:
lang – a string from the defined languages. E.g. "en" or "de"
-
const char *lv_translation_get(const char *tag)¶
Get the translated version of a tag on the selected language
Note
fallback rules:
if the tag is found on the selected language return it
if the tag is not found on the selected language, use the fist language
if the tag is not found on the first language, return the tag
- Parameters:
tag – the tag to translate
- Returns:
the translation
-
static inline const char *lv_tr(const char *tag)¶
Shorthand of lv_translation_set_language
- Parameters:
tag – the tag to translate
- Returns:
the translation
-
lv_result_t lv_translation_add_language(lv_translation_pack_t *pack, const char *lang)¶
Add a new language to a dynamic language pack. All languages should be added before adding tags
- Parameters:
pack – pointer to a dynamic translation pack
lang – language to add, e.g. "en", or "de"
- Returns:
LV_RESULT_OK: success, LV_RESULT_INVALID: failed
-
int32_t lv_translation_get_language_index(lv_translation_pack_t *pack, const char *lang_name)¶
Get the index of a language in a pack.
- Parameters:
pack – pointer to a static or dynamic language pack
lang_name – name of the language to find
- Returns:
index of the language or -1 if not found.
-
lv_translation_tag_dsc_t *lv_translation_add_tag(lv_translation_pack_t *pack, const char *tag_name)¶
Add a new tag to a dynamic language pack. Once the tag is added the translations for each language can be added too by using
lv_translation_set_tag_translation
- Parameters:
pack – pointer to a dynamic translation pack
tag_name – name of the tag, e.g. "dog", or "house"
- Returns:
pointer to the allocated tag descriptor
-
lv_result_t lv_translation_set_tag_translation(lv_translation_pack_t *pack, lv_translation_tag_dsc_t *tag, uint32_t lang_idx, const char *trans)¶
Add a translation to a tag in a dynamic translation pack
- Parameters:
pack – pointer to a dynamic translation pack
tag – return value of
lv_translation_add_tag
lang_idx – index of the language for which translation should be set
trans – the translation on the given language
- Returns:
LV_RESULT_OK: success, LV_RESULT_INVALID: failed