From 320660945c0bb6a1bc93b486c2fcc293033f70af Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Thu, 10 Aug 2023 07:13:04 +1000 Subject: [PATCH] Work on lang #332 --- front/js/pialert_common.js | 11 +++++++++++ front/php/templates/language/lang.php | 15 +++++++++++++-- pialert/conf.py | 1 - pialert/device.py | 1 + pialert/initialise.py | 2 -- pialert/logger.py | 3 --- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 313f8f29..b75f7d45 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -193,6 +193,11 @@ function getString (key) { } result = getCache(`pia_lang_${key}_${lang_code}`, true); + if(isEmpty(result)) + { + result = getCache(`pia_lang_${key}_en_us`, true); + } + return result; } @@ -476,6 +481,12 @@ function navigateToDeviceWithIp (ip) { }); } +// ----------------------------------------------------------------------------- +function isEmpty(value) +{ + return emptyArr.includes(value) +} + // initialize cacheSettings() cacheStrings() diff --git a/front/php/templates/language/lang.php b/front/php/templates/language/lang.php index 46b83f9a..8d640c83 100755 --- a/front/php/templates/language/lang.php +++ b/front/php/templates/language/lang.php @@ -73,9 +73,20 @@ function lang($key) // Merge JSON data with SQL data $mergedLanguageData = mergeLanguageData($languageData, $sqlLanguageData); - $result = $mergedLanguageData[$pia_lang_selected][$key] ?? "String Not found for key ".$key; + // Check if the key exists in the selected language + if (isset($mergedLanguageData[$pia_lang_selected][$key])) { + $result = $mergedLanguageData[$pia_lang_selected][$key]; + } else { + // If key not found in selected language, use "en_us" as fallback + if (isset($mergedLanguageData['en_us'][$key])) { + $result = $mergedLanguageData['en_us'][$key]; + } else { + // If key not found in "en_us" either, use a default string + $result = "String Not found for key " . $key; + } + } return $result; -}; +} diff --git a/pialert/conf.py b/pialert/conf.py index a85c5085..4f670c70 100755 --- a/pialert/conf.py +++ b/pialert/conf.py @@ -26,7 +26,6 @@ last_cleanup = '' last_update_vendors = '' last_version_check = '' check_report = [] -log_timestamp = 0 arpscan_devices = [] # for MQTT diff --git a/pialert/device.py b/pialert/device.py index af3ae17e..8f896a4b 100755 --- a/pialert/device.py +++ b/pialert/device.py @@ -2,6 +2,7 @@ import subprocess import conf +import re from helper import timeNowTZ, get_setting, get_setting_value from scanners.internet import check_IP_format, get_internet_IP from logger import mylog, print_log diff --git a/pialert/initialise.py b/pialert/initialise.py index 43c60593..875db542 100755 --- a/pialert/initialise.py +++ b/pialert/initialise.py @@ -183,8 +183,6 @@ def importConfigs (db): conf.check_report = [1, "internet_IP", "update_vendors_silent"] conf.plugins_once_run = False - # to be deleted if not used - conf.log_timestamp = conf.time_started #cron_instance = Cron() # timestamps of last execution times diff --git a/pialert/logger.py b/pialert/logger.py index fd0da4cb..36f0ee64 100755 --- a/pialert/logger.py +++ b/pialert/logger.py @@ -64,10 +64,7 @@ def print_log (pText): # log_timestamp2, ' ', log_timestamp2.strftime ('%H:%M:%S'), ' ', pText) - - # Save current time to calculate elapsed time until next log - conf.log_timestamp = log_timestamp2 return pText