Skip to content

Commit

Permalink
Support multi language at compile time, user select via Unit settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungpv committed Oct 27, 2023
1 parent 7810798 commit b314486
Show file tree
Hide file tree
Showing 19 changed files with 1,926 additions and 1,015 deletions.
42 changes: 39 additions & 3 deletions main/config.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 *);
2 changes: 1 addition & 1 deletion main/html_common.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main/html_init.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main/html_menu.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main/html_metrics.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion main/html_pages.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -290,6 +290,13 @@ const char html_page_unit[] PROGMEM =
"<fieldset>"
"<legend><b>&nbsp; _TXT_UNIT_TITLE_ &nbsp;</b></legend>"
"<form method='post'>"
"<p>"
"<b>_TXT_UNIT_LANGUAGE_</b>"
"<br/>"
"<select id='language' name='language' onchange=\"sendLanguage(this)\">"
"_LANGUAGE_OPTIONS_"
"</select>"
"</p>"
"<p>"
"<b>_TXT_UNIT_TEMP_</b>"
"<select name='tu'>"
Expand Down
117 changes: 114 additions & 3 deletions main/javascript_common.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@

const char count_down_script[] PROGMEM =
"<script>"
"var count = 10;"
"var count = 30;"
"(function countDown() {"
"document.getElementById('count').innerHTML = count + 's';"
"setTimeout(function() {"
Expand All @@ -29,4 +29,115 @@ const char count_down_script[] PROGMEM =
"}, 1000);"
"})();"
"</script>"
;
;
const char count_down_script_init[] PROGMEM =
"<script>"
"var count = 30;"
"(function countDown() {"
"document.getElementById('count').innerHTML = count + 's';"
"setTimeout(function() {"
"if(count > 0) {"
"count --;"
"return countDown();"
"} else {"
"window.location.href = 'http://_HOST_NAME_/status';"
"}"
"}, 1000);"
"})();"
"</script>"
;


const char fw_check_script_events[] PROGMEM =
"<script>"
"if (!!window.EventSource) {"
"var source = new EventSource('/events');"
"source.addEventListener('open', function(e) {"
"console.log('Events Connected');"
"}, false);"
"source.addEventListener('error', function(e) {"
"if (e.target.readyState != EventSource.OPEN) {"
"console.log('Events Disconnected');"
"}"
"}, false);"
"source.addEventListener('message', function(e) {"
"console.log('message', e.data);"
"}, false);"
"source.addEventListener('fw_check_status', function(e) {"
"console.log('fw_check_status', e.data);"
"document.getElementById('status').innerHTML = e.data;"
"}, false);"
"source.addEventListener('wifiOptions', function(e) {"
"console.log('wifiOptions', e.data);"
"document.getElementById('network').innerHTML = e.data;"
"}, false);"
"source.addEventListener('fw_check_reboot', function(e) {"
"console.log('fw_check_status', e.data);"
"document.getElementById('status').innerHTML = e.data;"
"var count = 20;"
"(function countDown() {"
"document.getElementById('count').innerHTML = count + 's';"
"setTimeout(function() {"
"if(count > 0) {"
"count --;"
"return countDown();"
"} else {"
"window.location.href = '/status';"
"}"
"}, 1000);"
"})();"
"}, false);"
"}"
"</script>";

const char unit_script_ws[] PROGMEM =
"<script>"
"var websocket;"
"function initWebSocket() {"
"console.log('Trying to open a WebSocket connection...');"
"var gateway = 'ws://${window.location.hostname}/ws';"
"websocket = new WebSocket(\"ws://\" + location.host + \"/ws\");"
"websocket.onopen = onOpen;"
"websocket.onclose = onClose;"
"websocket.onmessage = onMessage;"
"}"

"function onOpen(event) {"
"console.log('Connection opened');"
"}"

"function onClose(event) {"
"console.log('Connection closed');"
"setTimeout(initWebSocket, 4000);"
"}"

"function onMessage(event) {"
"console.log('onMessage: ' + event.data);"
"if (event.data == 'REFRESH'){"
"location.reload();"
"}"
"}"
"window.addEventListener('load', onLoad);"

"function onLoad(event) {"
"initWebSocket();"
"}"

"function sendLanguage(obj){"
"var lang_index = document.getElementById('language').value;"
"console.log('send language: ' + lang_index);"
"websocket.send('language;'+lang_index);"
"}"

"function matchPassword() {"
"var pw1 = document.getElementById('lpw').value;"
"var pw2 = document.getElementById('lpwc').value;"
"if(pw1 != pw2)"
"{"
"document.getElementById('message_not_match').innerHTML = '_TXT_UNIT_PASSWORD_NOT_MATCH_';"
"return false;"
"}"
"document.getElementById('message_not_match').innerHTML = '';"
"return true;"
"}"
"</script>";
Loading

0 comments on commit b314486

Please sign in to comment.