diff --git a/src/fonts/language.c b/src/fonts/language.c new file mode 100644 index 00000000..54f39191 --- /dev/null +++ b/src/fonts/language.c @@ -0,0 +1,44 @@ +#include "language.h" + +lang_e LANGUAGE = lang_simplified_chinese; + +translate_t simplified_chinese[] = { + {"Scan Now", "扫频"}, + {"Source", "信号源"}, + {"Image Setting", "图像设置"}, + {"OSD", "OSD"}, + {"Power", "电源"}, + {"Fans", "风扇"}, + {"Record Option", "录像设置"}, + {"Auto Scan", "自动扫频"}, + {"ELRS", "ELRS"}, + {"WiFi Module", "WiFi模块"}, + {"Head Tracker", "头部追踪"}, + {"Playback", "录像回放"}, + {"Storage", "存储"}, + {"Firmware ", "固件"}, + {"Focus Chart", "焦点图"}, + {"Clock", "时间"}, + {"Input", "按键"}, + {"Go Sleep!", "睡眠"}, +}; + +char *translate_string(const char *str, lang_e lang) { + int i; + int string_num = sizeof(simplified_chinese) / sizeof(translate_t); + + if (lang == 0) + return (char *)str; + else { + for (i = 0; i < string_num; i++) { + if (strcmp(str, simplified_chinese[i].in_english) == 0) + return simplified_chinese[i].translate; + } + return (char *)str; + } +} + +void lv_label_set_text_lang(lv_obj_t *obj, const char *text, lang_e lang) { + char *text_lang = _str(text, lang); + lv_label_set_text(obj, text_lang); +} \ No newline at end of file diff --git a/src/fonts/language.h b/src/fonts/language.h new file mode 100644 index 00000000..418dc0c8 --- /dev/null +++ b/src/fonts/language.h @@ -0,0 +1,23 @@ +#ifndef _LANGUAGE_H_ +#define _LANGUAGE_H_ + +#include + +typedef enum { + lang_english = 0, + lang_simplified_chinese = 1, +} lang_e; + +typedef struct { + char *in_english; + char *translate; +} translate_t; + +char *translate_string(const char *str, lang_e lang); + +#define _str(string, lang) translate_string(string, lang) + +void lv_label_set_text_lang(lv_obj_t *obj, const char *text, lang_e lang); + +extern lang_e LANGUAGE; +#endif \ No newline at end of file diff --git a/src/ui/ui_main_menu.c b/src/ui/ui_main_menu.c index 2c50c3f3..1e93452c 100644 --- a/src/ui/ui_main_menu.c +++ b/src/ui/ui_main_menu.c @@ -10,6 +10,7 @@ #include "driver/hardware.h" #include "driver/mcp3021.h" #include "driver/oled.h" +#include "fonts/language.h" #include "ui/page_autoscan.h" #include "ui/page_clock.h" #include "ui/page_common.h" @@ -67,7 +68,7 @@ static page_pack_t *page_packs[] = { #define PAGE_COUNT (sizeof(page_packs) / sizeof(page_packs[0])) -static page_pack_t* post_bootup_actions[PAGE_COUNT + 1]; +static page_pack_t *post_bootup_actions[PAGE_COUNT + 1]; static page_pack_t *find_pp(lv_obj_t *page) { for (uint32_t i = 0; i < PAGE_COUNT; i++) { @@ -78,15 +79,15 @@ static page_pack_t *find_pp(lv_obj_t *page) { return NULL; } -static void select_menu_tab(page_pack_t* pp) { +static void select_menu_tab(page_pack_t *pp) { lv_obj_clear_flag(pp->icon, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_style_bg_opa(((lv_menu_t*)menu)->selected_tab, LV_OPA_50, LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(((lv_menu_t *)menu)->selected_tab, LV_OPA_50, LV_STATE_CHECKED); } -static void deselect_menu_tab(page_pack_t* pp) { +static void deselect_menu_tab(page_pack_t *pp) { // LV_OPA_20 is the default for pressed menu // see lv_theme_default.c styles->menu_pressed - lv_obj_set_style_bg_opa(((lv_menu_t*)menu)->selected_tab, LV_OPA_20, LV_STATE_CHECKED); + lv_obj_set_style_bg_opa(((lv_menu_t *)menu)->selected_tab, LV_OPA_20, LV_STATE_CHECKED); lv_obj_add_flag(pp->icon, LV_OBJ_FLAG_HIDDEN); } @@ -100,7 +101,8 @@ void submenu_enter(void) { if (pp->p_arr.max) { // if we have selectable entries, select the first selectable one - for (pp->p_arr.cur = 0; !lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE); ++pp->p_arr.cur); + for (pp->p_arr.cur = 0; !lv_obj_has_flag(pp->p_arr.panel[pp->p_arr.cur], FLAG_SELECTABLE); ++pp->p_arr.cur) + ; set_select_item(&pp->p_arr, pp->p_arr.cur); } @@ -270,7 +272,7 @@ static void main_menu_create_entry(lv_obj_t *menu, lv_obj_t *section, page_pack_ lv_obj_t *cont = lv_menu_cont_create(section); pp->label = lv_label_create(cont); - lv_label_set_text(pp->label, pp->name); + lv_label_set_text_lang(pp->label, pp->name, LANGUAGE); lv_obj_set_style_text_font(pp->label, &lv_font_montserrat_26, 0); lv_label_set_long_mode(pp->label, LV_LABEL_LONG_SCROLL_CIRCULAR); @@ -319,7 +321,7 @@ void main_menu_init(void) { post_bootup_actions[PAGE_COUNT] = post_bootup_actions[i]; post_bootup_actions[i] = post_bootup_actions[j]; post_bootup_actions[j] = post_bootup_actions[PAGE_COUNT]; - } + } } } } @@ -371,7 +373,7 @@ void main_menu_update() { ++last_bootup_action; } } else { // Thread invokation - if (post_bootup_actions[i]->post_bootup_run_function){ + if (post_bootup_actions[i]->post_bootup_run_function) { post_bootup_actions[i]->post_bootup_run_function(); post_bootup_actions[i]->post_bootup_run_function = NULL; } else if (post_bootup_actions[i]->post_bootup_run_complete()) { diff --git a/src/ui/ui_main_menu.h b/src/ui/ui_main_menu.h index 73f2da1f..0183bd0a 100644 --- a/src/ui/ui_main_menu.h +++ b/src/ui/ui_main_menu.h @@ -12,7 +12,7 @@ extern "C" { #include "ui/page_common.h" typedef struct { - const char *name; + char *name; panel_arr_t p_arr; lv_obj_t *page; @@ -29,8 +29,8 @@ typedef struct { void (*on_right_button)(bool is_short); int32_t post_bootup_run_priority; - void(*post_bootup_run_function)(); - bool(*post_bootup_run_complete)(); + void (*post_bootup_run_function)(); + bool (*post_bootup_run_complete)(); } page_pack_t; typedef struct {