mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
i18n: minor API updates
This commit is contained in:
parent
b9ed89a976
commit
408ba8d574
@ -28,7 +28,7 @@ static const void * lv_i18n_get_text_core(lv_i18n_trans_t * trans, const char *
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
static const lv_i18n_lang_t ** languages;
|
static const lv_i18n_lang_pack_t * languages;
|
||||||
static const lv_i18n_lang_t * local_lang;
|
static const lv_i18n_lang_t * local_lang;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
@ -42,32 +42,36 @@ static const lv_i18n_lang_t * local_lang;
|
|||||||
/**
|
/**
|
||||||
* Set the languages for internationalization
|
* Set the languages for internationalization
|
||||||
* @param langs pointer to the array of languages. (Last element has to be `NULL`)
|
* @param langs pointer to the array of languages. (Last element has to be `NULL`)
|
||||||
|
* @return 0: no error; < 0: error
|
||||||
*/
|
*/
|
||||||
void lv_i18n_init(const lv_i18n_lang_t ** langs)
|
int lv_i18n_init(const lv_i18n_lang_pack_t * langs)
|
||||||
{
|
{
|
||||||
if(langs == NULL) {
|
if(langs == NULL) {
|
||||||
LV_LOG_WARN("lv_i18n_init: `langs` can't be NULL");
|
LV_LOG_WARN("lv_i18n_init: `langs` can't be NULL");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(langs[0] == NULL) {
|
if(langs[0] == NULL) {
|
||||||
LV_LOG_WARN("lv_i18n_init: `langs` need to contain at lest one translation");
|
LV_LOG_WARN("lv_i18n_init: `langs` need to contain at least one translation");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
languages = langs;
|
languages = langs;
|
||||||
local_lang = langs[0]; /*Automatically select the first language*/
|
local_lang = langs[0]; /*Automatically select the first language*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the localization (language)
|
* Change the localization (language)
|
||||||
* @param lang_code name of the translation to use. E.g. "en_GB"
|
* @param lang_code name of the translation to use. E.g. "en_GB"
|
||||||
|
* @return 0: no error; < 0: error
|
||||||
*/
|
*/
|
||||||
void lv_i18n_set_local(const char * lang_code)
|
int lv_i18n_set_local(const char * lang_code)
|
||||||
{
|
{
|
||||||
if(languages == NULL) {
|
if(languages == NULL) {
|
||||||
LV_LOG_WARN("lv_i18n_set_local: The languages are not set with lv_i18n_init() yet");
|
LV_LOG_WARN("lv_i18n_set_local: The languages are not set with lv_i18n_init() yet");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
@ -78,12 +82,14 @@ void lv_i18n_set_local(const char * lang_code)
|
|||||||
/*The language wasn't found*/
|
/*The language wasn't found*/
|
||||||
if(languages[i] == NULL) {
|
if(languages[i] == NULL) {
|
||||||
LV_LOG_WARN("lv_i18n_set_local: The selected language doesn't found");
|
LV_LOG_WARN("lv_i18n_set_local: The selected language doesn't found");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
local_lang = languages[i];
|
local_lang = languages[i];
|
||||||
|
|
||||||
LV_LOG_INFO("lv_i18n_set_local: new local selected")
|
LV_LOG_INFO("lv_i18n_set_local: new local selected")
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +54,8 @@ typedef struct {
|
|||||||
uint8_t (*plural_rule)(int32_t num); /*Function pointer to get the correct plural form for a number*/
|
uint8_t (*plural_rule)(int32_t num); /*Function pointer to get the correct plural form for a number*/
|
||||||
}lv_i18n_lang_t;
|
}lv_i18n_lang_t;
|
||||||
|
|
||||||
|
typedef lv_i18n_lang_t * lv_i18n_lang_pack_t;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
@ -61,14 +63,16 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* Set the languages for internationalization
|
* Set the languages for internationalization
|
||||||
* @param langs pointer to the array of languages. (Last element has to be `NULL`)
|
* @param langs pointer to the array of languages. (Last element has to be `NULL`)
|
||||||
|
* @return 0: no error; < 0: error
|
||||||
*/
|
*/
|
||||||
void lv_i18n_init(const lv_i18n_lang_t ** langs);
|
int lv_i18n_init(const lv_i18n_lang_pack_t * langs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the localization (language)
|
* Change the localization (language)
|
||||||
* @param lang_code name of the translation to use. E.g. "en_GB"
|
* @param lang_code name of the translation to use. E.g. "en_GB"
|
||||||
|
* @return 0: no error; < 0: error
|
||||||
*/
|
*/
|
||||||
void lv_i18n_set_local(const char * lang_code);
|
int lv_i18n_set_local(const char * lang_code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the translation from a message ID
|
* Get the translation from a message ID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user