lv_translation.h
API reference for lv_translation.h
Functions
lv_translation_set_language
Select the current language The LV_EVENT_TRANSLATION_LANGUAGE_CHANGED event will be sent to every widget
void lv_translation_set_language(const char *lang)| Name | Type | Description |
|---|---|---|
lang | const char * | a string from the defined languages. E.g. "en" or "de" |
lv_translation_set_tag_translation
Add a translation to a tag in a dynamic translation pack
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)| Name | Type | Description |
|---|---|---|
pack | lv_translation_pack_t * | pointer to a dynamic translation pack |
tag | lv_translation_tag_dsc_t * | return value of lv_translation_add_tag |
lang_idx | uint32_t | index of the language for which translation should be set |
trans | const char * | the translation on the given language |
Returns: lv_result_t — LV_RESULT_OK: success, LV_RESULT_INVALID: failed
lv_translation_get_language
Get the current selected language
const char * lv_translation_get_language(void)Returns: const char * — the current selected language
lv_translation_get
Get the translated version of a tag on the selected language
const char * lv_translation_get(const char *tag)| Name | Type | Description |
|---|---|---|
tag | const char * | the tag to translate |
Returns: const char * — the translation
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
lv_translation_get_language_index
Get the index of a language in a pack.
int32_t lv_translation_get_language_index(lv_translation_pack_t *pack, const char *lang_name)| Name | Type | Description |
|---|---|---|
pack | lv_translation_pack_t * | pointer to a static or dynamic language pack |
lang_name | const char * | name of the language to find |
Returns: int32_t — index of the language or -1 if not found.
lv_translation_init
Initialize the translation module
void lv_translation_init(void)lv_translation_deinit
De-initialize the translation module and free all allocated translations
void lv_translation_deinit(void)lv_translation_add_static
Register a translation pack from static arrays. All the pointers need to be static, that is to live while they are used
lv_translation_pack_t * lv_translation_add_static(const char *const languages[], const char *const tags[], const char *const translations[])| Name | Type | Description |
|---|---|---|
languages | const char *const | List of languages. E.g. {"en", "de", NULL} |
tags | const char *const | Tags that are using in the UI. E.g. {"dog", "cat", NULL} |
translations | const char *const | List of translations. E.g. {"Dog", "Cat", "Hund", "Katze"} |
Returns: lv_translation_pack_t * — The created pack
lv_translation_add_dynamic
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 having lv_translation_tag_dsc_t items In each array element tag is a malloced string, translations is a malloc-ed array with malloc-ed array for each element.
lv_translation_pack_t * lv_translation_add_dynamic(void)Returns: lv_translation_pack_t * — the created pack to which data can be added manually.
lv_tr
Shorthand of lv_translation_get
const char * lv_tr(const char *tag)| Name | Type | Description |
|---|---|---|
tag | const char * | the tag to translate |
Returns: const char * — the translation
lv_translation_add_language
Add a new language to a dynamic language pack. All languages should be added before adding tags
lv_result_t lv_translation_add_language(lv_translation_pack_t *pack, const char *lang)| Name | Type | Description |
|---|---|---|
pack | lv_translation_pack_t * | pointer to a dynamic translation pack |
lang | const char * | language to add, e.g. "en", or "de" |
Returns: lv_result_t — LV_RESULT_OK: success, LV_RESULT_INVALID: failed
lv_translation_add_tag
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
lv_translation_tag_dsc_t * lv_translation_add_tag(lv_translation_pack_t *pack, const char *tag_name)| Name | Type | Description |
|---|---|---|
pack | lv_translation_pack_t * | pointer to a dynamic translation pack |
tag_name | const char * | name of the tag, e.g. "dog", or "house" |
Returns: lv_translation_tag_dsc_t * — pointer to the allocated tag descriptor
Dependencies
Last updated on