From 3448186354276bf4bdf7e6aa538a3264d15fb98c Mon Sep 17 00:00:00 2001 From: Luca Ritossa Date: Sun, 22 Oct 2023 22:16:37 +0200 Subject: [PATCH] #25 Translation with php array files https://github.com/moneymanagerex/web-money-manager-ex/issues/25 --- WebApp/_btn_back.php | 2 +- WebApp/_btn_logout.php | 2 +- WebApp/_common.php | 2 +- WebApp/functions.php | 5 ++ WebApp/functions_costant.php | 6 ++ WebApp/functions_design.php | 95 ++++++++++++++++++------ WebApp/functions_various.php | 11 +-- WebApp/guide.php | 10 +-- WebApp/index.php | 12 ++-- WebApp/insert.php | 12 ++-- WebApp/languages/en.php | 96 +++++++++++++++++++++++++ WebApp/languages/it.php | 96 +++++++++++++++++++++++++ WebApp/new_transaction.php | 18 ++--- WebApp/res/app/functions-1.2.0.js | 8 +-- WebApp/res/app/new_transaction-1.0.4.js | 4 +- WebApp/settings.php | 54 ++++++++------ WebApp/show.php | 4 +- 17 files changed, 356 insertions(+), 81 deletions(-) create mode 100644 WebApp/languages/en.php create mode 100644 WebApp/languages/it.php diff --git a/WebApp/_btn_back.php b/WebApp/_btn_back.php index 47ce9b4..1edc1fd 100644 --- a/WebApp/_btn_back.php +++ b/WebApp/_btn_back.php @@ -1,3 +1,3 @@
- Ritorna al menu +
diff --git a/WebApp/_btn_logout.php b/WebApp/_btn_logout.php index 7a6d653..1130fd6 100644 --- a/WebApp/_btn_logout.php +++ b/WebApp/_btn_logout.php @@ -1,3 +1,3 @@
- Esci +
diff --git a/WebApp/_common.php b/WebApp/_common.php index c765f30..91375ae 100644 --- a/WebApp/_common.php +++ b/WebApp/_common.php @@ -20,4 +20,4 @@ if (!isset($b_debug)) { $b_debug = false; -} +} \ No newline at end of file diff --git a/WebApp/functions.php b/WebApp/functions.php index 2a2c607..c2f5118 100644 --- a/WebApp/functions.php +++ b/WebApp/functions.php @@ -6,6 +6,11 @@ require_once 'configuration_user.php'; } +require_once 'languages/en.php'; + +if (isset($language) && $language != 'en' && file_exists('languages/'.$language.'.php')) + include_once 'languages/'.$language.'.php'; + require_once 'functions_design.php'; require_once 'functions_database.php'; require_once 'functions_security.php'; diff --git a/WebApp/functions_costant.php b/WebApp/functions_costant.php index ead576b..7f53336 100644 --- a/WebApp/functions_costant.php +++ b/WebApp/functions_costant.php @@ -103,4 +103,10 @@ public static function current_page_url () {$pageURL .= ':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];} return $pageURL; } + + public static function language () + { + global $language; + return $language; + } } diff --git a/WebApp/functions_design.php b/WebApp/functions_design.php index 34efc73..7b98fb1 100644 --- a/WebApp/functions_design.php +++ b/WebApp/functions_design.php @@ -8,8 +8,10 @@ class design //Create date input element public static function input_date ($TrDateDefault) { + global $lang; + echo "
"; - echo ""; + echo ""; echo ""; echo ""; echo "
\n"; @@ -20,11 +22,20 @@ public static function input_date ($TrDateDefault) //Create status input element public static function input_status ($TrStatusDefault) { - $StatusArrayDesc = array ("Non Riconciliata", "Riconciliata", "Nulla", "Da Monitorare", "Duplicata"); + global $lang; + + $StatusArrayDesc = array ( + $lang["trans.status.none"], + $lang["trans.status.reconciled"], + $lang["trans.status.void"], + $lang["trans.status.follow-up"], + $lang["trans.status.duplicate"] + ); + $StatusArrayDB = array ("", "R", "V", "F", "D"); echo "
"; - echo ""; + echo ""; echo "'; $on_change = 'onchange="enable_element(\'ToAccount\',\'Type\',\'Transfer\'); disable_element(\'Payee\',\'Type\',\'Transfer\')"'; for ($i = 0; $i < sizeof($TypeArrayCode); $i++) @@ -73,12 +90,14 @@ public static function input_type ($TrTypeDefault) //Create account input element public static function input_account ($TrAccountDefault) { + global $lang; + $AccountArrayDesc = db_function::bankaccount_select_all(); if (sizeof($AccountArrayDesc) == 0) {$AccountArrayDesc[0] = "None";} echo "
"; - echo ""; + echo ""; echo ""; for ($i = 0; $i < sizeof($ToAccountArrayDesc); $i++) { @@ -118,12 +139,14 @@ public static function input_toaccount ($TrToAccountDefault) //Create payee input element public static function input_payee ($TrPayeeDefault) { + global $lang; + $PayeeArrayDesc = db_function::payee_select_all_name(); array_unshift($PayeeArrayDesc,"None"); echo "
"; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo "
\n"; @@ -139,12 +162,14 @@ public static function input_payee ($TrPayeeDefault) //Create category input element public static function input_category ($TrCategoryDefault) { + global $lang; + $CategoryArrayDesc = db_function::category_select_distinct(); array_unshift($CategoryArrayDesc,"None"); echo "
"; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo "
\n"; @@ -160,9 +185,11 @@ public static function input_category ($TrCategoryDefault) //Create subcategory input element public static function input_subcategory ($TrSubCategoryDefault) { + global $lang; + echo "
"; - echo ""; - echo ""; + echo ""; + echo ""; echo ""; echo "
\n"; @@ -176,15 +203,17 @@ public static function input_subcategory ($TrSubCategoryDefault) //Create amount input element public static function input_amount ($TrAmountDefault) { + global $lang; + echo "
"; - echo ""; + echo ""; if ($TrAmountDefault <> 0) { - echo ""; + echo ""; } else { - echo ""; + echo ""; } echo ""; echo "
\n"; @@ -195,15 +224,17 @@ public static function input_amount ($TrAmountDefault) //Create notes input element public static function input_notes ($TrNotesDefault) { + global $lang; + echo "
"; - echo ""; + echo ""; if ($TrNotesDefault <> "Empty") { - echo ""; + echo ""; } else { - echo ""; + echo ""; } echo ""; echo "
\n"; @@ -282,12 +313,14 @@ public static function settings_password ($VarName,$PlaceHolder,$Required,$Label //Design setting default account public static function settings_default_account ($TrAccountDefault) { + global $lang; + $AccountArrayDesc = db_function::bankaccount_select_all(); if (sizeof($AccountArrayDesc) == 0) {$AccountArrayDesc[0] = "None";} echo "
"; - echo ""; + echo ""; echo ""; + for ($i = 0; $i < sizeof($AvailableLanguages); $i++) + { + if ($AvailableLanguages[$i] == $Language) + {echo "";} + else + {echo "";} + } + echo ""; + echo ""; + echo "
\n"; + } } diff --git a/WebApp/functions_various.php b/WebApp/functions_various.php index 4849d13..ee6bb5c 100644 --- a/WebApp/functions_various.php +++ b/WebApp/functions_various.php @@ -99,12 +99,13 @@ public static function getPageUrl() : String */ public static function getPagesList() : Array { + global $lang; $pages_list = [ - 'new_transaction' => 'Nuova operazione', - 'show' => 'Lista operazioni', - 'settings' => 'Impostazioni', - 'guide' => 'Guida', - 'about' => 'About', + 'new_transaction' => $lang["page.new-transaction"], + 'show' => $lang["page.show-transactions"], + 'settings' => $lang["page.settings"], + 'guide' => $lang["page.guide"], + 'about' => $lang["page.about"] ]; return $pages_list; } diff --git a/WebApp/guide.php b/WebApp/guide.php index 8794919..0a5e927 100644 --- a/WebApp/guide.php +++ b/WebApp/guide.php @@ -13,20 +13,20 @@

  1. - Copia le informazioni qui sotto e incollale nell'applicazione desktop. +
  2. - Riapri l'applicazione desktop per sincronizzare i conti, i beneficiari, etc. sulla WebApp. +
  3. - Inizia ad usare la WebApp. +

- WebApp URL: +

@@ -35,7 +35,7 @@


- Desktop GUID: +

diff --git a/WebApp/index.php b/WebApp/index.php index c69754d..aed6138 100644 --- a/WebApp/index.php +++ b/WebApp/index.php @@ -11,7 +11,7 @@ $upgrade_result = db_upgrade::upgrade_db(); if ($upgrade_result == 'update_done') { - various::send_alert_and_redirect('Database aggiornato con successo alla versione '.costant::app_version(), 'index.php'); + various::send_alert_and_redirect($lang["db_successfully_updated_to_version"].costant::app_version(), 'index.php'); } } $username = null; @@ -71,17 +71,17 @@

- - + + "" autofocus required />
- - + + " required />

- +

- con successo +



- Aggiungi altra operazione +
- Lista operazioni +
diff --git a/WebApp/languages/en.php b/WebApp/languages/en.php new file mode 100644 index 0000000..dd72acc --- /dev/null +++ b/WebApp/languages/en.php @@ -0,0 +1,96 @@ +"; - echo '
'; + echo "
"; echo ""; echo ""; echo "
\n"; @@ -133,7 +135,7 @@ echo "populate_sub_category(false);"; echo ""; } - echo ""; + echo ""; echo ""; echo "\n"; diff --git a/WebApp/res/app/functions-1.2.0.js b/WebApp/res/app/functions-1.2.0.js index 4dd4df3..470c3ea 100644 --- a/WebApp/res/app/functions-1.2.0.js +++ b/WebApp/res/app/functions-1.2.0.js @@ -14,7 +14,7 @@ function test_html5 () //|| !Modernizr.input.step //Used but not prerequisite ) { - alert("Seems that the browser doesn't fully supports HTML5" + '\n' + '\n' + "Please make attention because it doesn't validate fields!"); + alert($lang["browser_not_support_html5"]); //close(); } } @@ -149,7 +149,7 @@ function check_passwor_error() function check_password_match_and_submit (Password1,Password2,formid) { if (document.getElementById(Password1).value !== document.getElementById(Password2).value) - {alert("La password non corrisponde!");} + {alert($lang["sec.password_not_matching"]);} else {document.getElementById(formid).submit();} } @@ -232,12 +232,12 @@ function attachment_uploadComplete(evt) function attachment_uploadFailed(evt) { - alert("Si è verificato un errore al caricamento del file."); + alert($lang["attachment.upload_failed"]); } function attachment_uploadCanceled(evt) { - alert("Il caricamento è stato annullato dall'utente o il browser ha interrotto la connessione."); + alert($lang["attachment.upload_canceled"]); } function attachment_delete(FileName,TrID) diff --git a/WebApp/res/app/new_transaction-1.0.4.js b/WebApp/res/app/new_transaction-1.0.4.js index 838ab3c..16aaba7 100644 --- a/WebApp/res/app/new_transaction-1.0.4.js +++ b/WebApp/res/app/new_transaction-1.0.4.js @@ -49,12 +49,12 @@ var transactions = { submit_form = true; }else{ form.find(':invalid').first().focus(); - alert('Alcuni campi non sono validi'); + alert($lang["trans.msg.not_all_fields_are_valid"]); } // Confirm add new payee if(submit_form){ - if(app.confirmIfNotPresentInDatalist('Payee', PayeeList, "Confermi la creazione del nuovo beneficiario")){ + if(app.confirmIfNotPresentInDatalist('Payee', PayeeList, $lang["trans.msg.do_you_want_to_add_new_payee"])){ submit_form = true; }else{ $('#Payee').focus(); diff --git a/WebApp/settings.php b/WebApp/settings.php index 11649a0..a5b1ba3 100644 --- a/WebApp/settings.php +++ b/WebApp/settings.php @@ -5,7 +5,12 @@ include_once '_common.php'; if ($_SERVER["REQUEST_METHOD"] == "POST") - { + { + if (isset ($_POST["Language"])) + {$language = $_POST["Language"];} + else + {$language = "en";} + if (isset ($_POST["Set_Disable_authentication"])) {$disable_authentication = $_POST["Set_Disable_authentication"];} else @@ -42,6 +47,7 @@ $parameterarray = array ( + "language" => $language, "disable_authentication"=> $disable_authentication, "user_username" => $username, "user_password" => $password, @@ -65,11 +71,11 @@ $is_edit = (isset($const_username) AND isset($const_password)); -$s_page_title = 'Impostazioni'; +$s_page_title = $lang["page.settings"]; if (!$is_edit) { - $s_page_title = 'Nuove impostazioni'; + $s_page_title = $lang["page.settings.new"]; $b_page_logo = true; } @@ -81,13 +87,14 @@ -

Fornisci le nuove impostazioni per iniziare ad usare Money Manager EX

+


"; + //SECTION AUTHENTICATION - design::section_legened("Autenticazione"); + design::section_legened($lang["settings.authentication.section"]); if ($const_disable_authentication == True) - {design::settings_checkbox("Set_Disable_authentication",True,"Disattiva l'autenticazione (NON RACCOMANDATO)");} + {design::settings_checkbox("Set_Disable_authentication",True,$lang["settings.authentication.disable"]);} else - {design::settings_checkbox("Set_Disable_authentication",False,"Disattiva l'autenticazione (NON RACCOMANDATO)");} + {design::settings_checkbox("Set_Disable_authentication",False,$lang["settings.authentication.disable"]);} if (isset($const_username) && $const_disable_authentication == False) {design::settings("Username",$const_username,"","Text",True);} else - {design::settings("Username","","Insert a new username","Text",True);} + {design::settings("Username","",$lang["sec.username.placeholder"] ,"Text",True);} if (isset($const_password) && $const_disable_authentication == False) - {design::settings_password("Password","Inserisci una nuova password per cambiarla",False,"Password");} + {design::settings_password("Password",$lang["settings.authentication.password.update.placeholder"],False,"Password");} else - {design::settings_password("Password","Inserisci una password",True,"Password");} + {design::settings_password("Password",$lang["settings.authentication.password.new.placeholder"],True,"Password");} - design::settings_password("Confirm_Password","Conferma la nuova password",False,"Conferma Password"); + design::settings_password("Confirm_Password",$lang["settings.authentication.password.confirm.placeholder"],False,"Conferma Password"); echo "
"; //SECTION NEW TRANSACTIONS - design::section_legened("Nuove operazioni"); + design::section_legened($lang["settings.new-trans.section"]); if ($const_disable_payee == True) - {design::settings_checkbox("Set_Disable_payee",True,"Disattiva la richiesta del beneficiario");} + {design::settings_checkbox("Set_Disable_payee",True,$lang["settings.new-trans.disable-payee.placeholder"]);} else - {design::settings_checkbox("Set_Disable_payee",False,"Disattiva la richiesta del beneficiario");} + {design::settings_checkbox("Set_Disable_payee",False,$lang["settings.new-trans.disable-payee.placeholder"]);} if ($const_disable_category == True) - {design::settings_checkbox("Set_Disable_category",True,"Disattiva la richiesta della categoria");} + {design::settings_checkbox("Set_Disable_category",True,$lang["settings.new-trans.disable-category.placeholder"]);} else - {design::settings_checkbox("Set_Disable_category",False,"Disattiva la richiesta della categoria");} + {design::settings_checkbox("Set_Disable_category",False,$lang["settings.new-trans.disable-category.placeholder"]);} if (isset($const_defaultaccountname)) {design::settings_default_account($const_defaultaccountname);} @@ -135,7 +149,7 @@ echo "
"; //SECTION DESKTOP INTEGRATION - design::section_legened("Integrazione Desktop"); + design::section_legened($lang["settings.new-trans.section"]); if (isset($const_desktop_guid)) {design::settings("Guid",$const_desktop_guid,"","Text",True);} else @@ -172,13 +186,13 @@ function Disable_Authentication() Salva'); + echo (''); echo '
'; - echo ('Ritorna al menu'); + echo (''.$lang['return_to_menu'].''); } else { - echo (''); + echo (''); } echo '
'; echo '
'; diff --git a/WebApp/show.php b/WebApp/show.php index 308f142..733938d 100644 --- a/WebApp/show.php +++ b/WebApp/show.php @@ -7,7 +7,7 @@ include_once '_common.php'; -$s_page_title = "Lista operazioni"; +$s_page_title = $lang["page.show-transactions"]; include_once '_header.php'; function drawRecordRow(Array $a_transaction, String $s_date) : void @@ -103,7 +103,7 @@ function drawRecordRow(Array $a_transaction, String $s_date) : void $resultarray = db_function::transaction_select_all_order_by_date('DESC'); echo '
'; - echo '

' . (count($resultarray) == 0 ? 'No' : 'Attuali'). ' operazioni in sospeso'. '

'; + echo '

' . (count($resultarray) == 0 ? $lang["show.no-pending-trans"] : $lang["show.current-pending-trans"]). '

'; echo '
'; echo '
';