Skip to content

Commit

Permalink
create lang folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ligenxxxx committed Nov 6, 2024
1 parent 83440ae commit 095ef4a
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ file(GLOB SRC_FILES_BMI "src/bmi270/*.c" "src/bmi270/*.h")
file(GLOB SRC_FILES_UTIL "src/util/*.c" "src/util/*.h")
file(GLOB SRC_FILES_PLAYER "src/player/*.c" "src/player/*.h")
file(GLOB SRC_FILES_EMULATOR "src/emulator/*.c" "src/emulator/*.h")
file(GLOB SRC_FILES_LANG "src/lang/*.c" "src/lang/*.h")

set(SRC_FILES
${SRC_FILES_CORE}
Expand All @@ -79,6 +80,7 @@ set(SRC_FILES
${SRC_FILES_UI}
${SRC_FILES_BMI}
${SRC_FILES_UTIL}
${SRC_FILES_LANG}
)
if(EMULATOR_BUILD)
list(APPEND SRC_FILES ${SRC_FILES_EMULATOR})
Expand Down
44 changes: 0 additions & 44 deletions src/fonts/language.c

This file was deleted.

23 changes: 23 additions & 0 deletions src/lang/english.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#include "english.h"

translate_t translate_english[TRANSLATE_STRING_NUM] = {
{"Scan Now", "Scan Now"},
{"Source", "Source"},
{"Image Setting", "Image Setting"},
{"OSD", "OSD"},
{"Power", "Power"},
{"Fans", "Fans"},
{"Record Option", "Record Option"},
{"Auto Scan", "Auto Scan"},
{"ELRS", "ELRS"},
{"WiFi Module", "WiFi Module"},
{"Head Tracker", "Head Tracker"},
{"Playback", "Playback"},
{"Storage", "Storage"},
{"Firmware ", "Firmware "},
{"Focus Chart", "Focus Chart"},
{"Clock", "Clock"},
{"Input", "Input"},
{"Go Sleep!", "Go Sleep!"},
};
8 changes: 8 additions & 0 deletions src/lang/english.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#ifndef _ENGLISH_H_
#define _ENGLISH_H_

#include "language.h"

extern translate_t translate_english[TRANSLATE_STRING_NUM];
#endif
40 changes: 40 additions & 0 deletions src/lang/language.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "language.h"
#include "english.h"
#include "simplified_chinese.h"
#include <log/log.h>

lang_e LANGUAGE = lang_simplified_chinese;

translate_t *translate_list[] = {
translate_english,
translate_simplified_chinese,
};

char *translate_string(const char *str, lang_e lang) {
int i, j;

// search language
i = 0;
while (i != LANGUAGE) {
if (i < lang_end)
i++;
}

// if language is undefined
if (i != LANGUAGE)
return (char *)str;

// search str translate
for (j = 0; j < TRANSLATE_STRING_NUM; j++) {
if (strcmp(str, translate_list[i][j].in_english) == 0)
return translate_list[i][j].translate;
}

// if str is undefined
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);
}
5 changes: 4 additions & 1 deletion src/fonts/language.h → src/lang/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

#include <lvgl/lvgl.h>

#define TRANSLATE_STRING_NUM 18

typedef enum {
lang_english = 0,
lang_simplified_chinese = 1,
lang_simplified_chinese,
lang_end,
} lang_e;

typedef struct {
Expand Down
23 changes: 23 additions & 0 deletions src/lang/simplified_chinese.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#include "simplified_chinese.h"

translate_t translate_simplified_chinese[TRANSLATE_STRING_NUM] = {
{"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!", "睡眠"},
};
8 changes: 8 additions & 0 deletions src/lang/simplified_chinese.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#ifndef _SIMPLIFIED_CHINESE_H_
#define _SIMPLIFIED_CHINESE_H_

#include "language.h"

extern translate_t translate_simplified_chinese[TRANSLATE_STRING_NUM];
#endif
2 changes: 1 addition & 1 deletion src/ui/ui_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "driver/hardware.h"
#include "driver/mcp3021.h"
#include "driver/oled.h"
#include "fonts/language.h"
#include "lang/language.h"
#include "ui/page_autoscan.h"
#include "ui/page_clock.h"
#include "ui/page_common.h"
Expand Down

0 comments on commit 095ef4a

Please sign in to comment.