From b314486133668d40723ea47895cc969d78e8c945 Mon Sep 17 00:00:00 2001 From: VietDzung Date: Fri, 27 Oct 2023 10:26:04 +0700 Subject: [PATCH] Support multi language at compile time, user select via Unit settings. --- main/config.h | 42 +++- main/html_common.h | 2 +- main/html_init.h | 2 +- main/html_menu.h | 2 +- main/html_metrics.h | 2 +- main/html_pages.h | 9 +- main/javascript_common.h | 117 ++++++++- main/language_translations.h | 216 ++++++++++++++++ main/language_util.h | 101 ++++++++ main/languages/da-DA.h | 254 +++++++++---------- main/languages/de-DE.h | 224 +++++++++-------- main/languages/en-GB.h | 308 +++++++++++++---------- main/languages/es-ES.h | 254 +++++++++---------- main/languages/fr-FR.h | 224 +++++++++-------- main/languages/it-IT.h | 253 +++++++++---------- main/languages/ja-JP.h | 253 +++++++++---------- main/languages/vi-VN.h | 196 +++++++++++++++ main/languages/zh-CN.h | 10 +- main/main.cpp | 472 ++++++++++++++++++++++++----------- 19 files changed, 1926 insertions(+), 1015 deletions(-) create mode 100644 main/language_translations.h create mode 100644 main/language_util.h create mode 100644 main/languages/vi-VN.h diff --git a/main/config.h b/main/config.h index 0c05238..3ee13d1 100644 --- a/main/config.h +++ b/main/config.h @@ -1,6 +1,6 @@ /* mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant. - Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. + Copyright (c) 2023 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -14,8 +14,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/*#define MY_LANGUAGE fr-FR // define your language*/ - const PROGMEM char* m2mqtt_version = "2023.8.0"; //Define global variables for files @@ -111,3 +109,41 @@ const PROGMEM uint32_t HP_MAX_RETRIES = 10; // Double the interval between retri bool useFahrenheit = false; // support heat mode settings, some model do not support heat mode bool supportHeatMode = true; + +// Multi language support, all store in the flash, just change in the Unit settings +byte system_language_index = 0; // default language index 0:en +// #define MITSU2MQTT_EN_ONLY 1 // un comment to enable English only for debug +#include "language_util.h" // Multi languages support + +// Languages supported. Note: the order is important and must match locale_translations.h +#if defined(MITSU2MQTT_TEST) || defined(MITSU2MQTT_EN_ONLY) +// in Debug mode use one language (en) to save flash memory needed for the tests +const char *const languages[] = {MITSU2MQTT_LOCALE_EN}; +const char *const language_names[] = {"English"}; +#elif defined(MITSU2MQTT_VI_ONLY) +const char *const languages[] = {MITSU2MQTT_LOCALE_VI}; +const char *const language_names[] = {"Tiếng Việt"}; +#else +const char *const languages[] = { + MITSU2MQTT_LOCALE_EN, + MITSU2MQTT_LOCALE_VI, + // MITSU2MQTT_LOCALE_DE, + // MITSU2MQTT_LOCALE_ES, + // MITSU2MQTT_LOCALE_FR, + // MITSU2MQTT_LOCALE_IT, + // MITSU2MQTT_LOCALE_JA, + // MITSU2MQTT_LOCALE_ZH +}; +const char *const language_names[] = { + "English", + "Tiếng Việt", + // "Deutsch", + // "Español", + // "Français", + // "Italiano", + // "日本語", + // "中文" +}; +#endif + +static constexpr uint8_t NUM_LANGUAGES = sizeof(languages) / sizeof(const char *); diff --git a/main/html_common.h b/main/html_common.h index 17db9b3..b540450 100644 --- a/main/html_common.h +++ b/main/html_common.h @@ -1,6 +1,6 @@ /* mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant. - Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. + Copyright (c) 2023 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either diff --git a/main/html_init.h b/main/html_init.h index 73e13f2..bec0fe3 100644 --- a/main/html_init.h +++ b/main/html_init.h @@ -1,6 +1,6 @@ /* mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant. - Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. + Copyright (c) 2023 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either diff --git a/main/html_menu.h b/main/html_menu.h index b0f3d0d..33949e0 100644 --- a/main/html_menu.h +++ b/main/html_menu.h @@ -1,6 +1,6 @@ /* mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant. - Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. + Copyright (c) 2023 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either diff --git a/main/html_metrics.h b/main/html_metrics.h index d6894d8..e09ec5e 100644 --- a/main/html_metrics.h +++ b/main/html_metrics.h @@ -1,6 +1,6 @@ /* mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant. - Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. + Copyright (c) 2023 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either diff --git a/main/html_pages.h b/main/html_pages.h index 87253da..aae1ed5 100644 --- a/main/html_pages.h +++ b/main/html_pages.h @@ -1,6 +1,6 @@ /* mitsubishi2mqtt - Mitsubishi Heat Pump to MQTT control for Home Assistant. - Copyright (c) 2022 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. + Copyright (c) 2023 gysmo38, dzungpv, shampeon, endeavour, jascdk, chrdavis, alekslyse. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -290,6 +290,13 @@ const char html_page_unit[] PROGMEM = "
" "  _TXT_UNIT_TITLE_  " "
" + "

" + "_TXT_UNIT_LANGUAGE_" + "
" + "" + "

" "

" "_TXT_UNIT_TEMP_" "