Skip to content

Commit

Permalink
moneymanagerex#25 Translation with php array files
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaritossa committed Oct 23, 2023
1 parent 3448186 commit 848ab95
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 80 deletions.
8 changes: 7 additions & 1 deletion WebApp/functions_costant.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,15 @@ public static function current_page_url ()
return $pageURL;
}

public static function language ()
public static function uiLanguage ()
{
global $language;
return $language;
}

public static function lang ($Key)
{
global $lang;
return $lang[$Key];
}
}
78 changes: 27 additions & 51 deletions WebApp/functions_design.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class design
//Create date input element
public static function input_date ($TrDateDefault)
{
global $lang;

echo "<div class='form-group'>";
echo "<label for='Date'>{$lang["trans.date"]}</label>";
echo '<label for="Date">'.costant::lang("trans.date").'</label>';
echo "<input id = 'Date' type='date' name='Date' class='form-control' value = '${TrDateDefault}'/>";
echo "<span class='help-block'></span>";
echo "</div>\n";
Expand All @@ -22,20 +20,18 @@ public static function input_date ($TrDateDefault)
//Create status input element
public static function input_status ($TrStatusDefault)
{
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"]
costant::lang("trans.status.none"),
costant::lang("trans.status.reconciled"),
costant::lang("trans.status.void"),
costant::lang("trans.status.follow-up"),
costant::lang("trans.status.duplicate")
);

$StatusArrayDB = array ("", "R", "V", "F", "D");

echo "<div class='form-group'>";
echo "<label for='Status'>{$lang["trans.status"]}</label>";
echo '<label for="Status">'.costant::lang("trans.status").'</label>';
echo "<select id ='Status' name='Status' class='form-control'>";
for ($i = 0; $i < sizeof($StatusArrayDesc); $i++)
{
Expand All @@ -53,17 +49,15 @@ public static function input_status ($TrStatusDefault)
//Create type input element
public static function input_type ($TrTypeDefault)
{
global $lang;

$TypeArrayDesc = array (
$lang["trans.type.withdrawal"],
$lang["trans.type.deposit"],
$lang["trans.type.transfer"]
costant::lang("trans.type.withdrawal"),
costant::lang("trans.type.deposit"),
costant::lang("trans.type.transfer")
);
$TypeArrayCode = array ('Withdrawal', 'Deposit', 'Transfer');

echo '<div class="form-group">';
echo "<label for='Type'>{$lang["trans.type"]}</label>";
echo '<label for="Type">'.costant::lang("trans.type").'</label>';
# echo '<select id="Type" name="Type" class="form-control" onchange="enable_element(\'ToAccount\',\'Type\',\'Transfer\'); disable_element(\'Payee\',\'Type\',\'Transfer\')">';
$on_change = 'onchange="enable_element(\'ToAccount\',\'Type\',\'Transfer\'); disable_element(\'Payee\',\'Type\',\'Transfer\')"';
for ($i = 0; $i < sizeof($TypeArrayCode); $i++)
Expand All @@ -90,14 +84,12 @@ 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 "<div class='form-group'>";
echo "<label for='Account'>{$lang["trans.account"]}</label>";
echo '<label for="Account">'.costant::lang("trans.account").'</label>';
echo "<select id ='Account' name='Account' class='form-control'>";
for ($i = 0; $i < sizeof($AccountArrayDesc); $i++)
{
Expand All @@ -115,13 +107,11 @@ public static function input_account ($TrAccountDefault)
//Create toaccount input element
public static function input_toaccount ($TrToAccountDefault)
{
global $lang;

$ToAccountArrayDesc = db_function::bankaccount_select_all();
array_unshift($ToAccountArrayDesc,"None");

echo "<div class='form-group'>";
echo "<label for='ToAccount'>{$lang["trans.to-account"]}</label>";
echo '<label for="ToAccount">'.costant::lang("trans.to-account").'</label>';
echo "<select id ='ToAccount' name='ToAccount' class='form-control'>";
for ($i = 0; $i < sizeof($ToAccountArrayDesc); $i++)
{
Expand All @@ -139,14 +129,12 @@ 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 "<div class='form-group'>";
echo "<label for='Payee'>{$lang["trans.payee"]}</label>";
echo "<input id='Payee' type='text' name='Payee' class='form-control' placeholder='{$lang["trans.payee.placeholder"]}' autocomplete = 'off' required />";
echo '<label for="Payee">'.costant::lang("trans.payee").'</label>';
echo '<input id="Payee" type="text" name="Payee" class="form-control" placeholder="'.costant::lang("trans.payee.placeholder").'" autocomplete = "off" required />';
echo "<span class='help-block'></span>";
echo "</div>\n";

Expand All @@ -162,14 +150,12 @@ 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 "<div class='form-group'>";
echo "<label for='Category'>{$lang["trans.category"]}</label>";
echo "<input id='Category' type='text' name='Category' class='form-control' placeholder='{$lang["trans.category.placeholder"]}' autocomplete = 'off' required />";
echo '<label for="Category">'.costant::lang("trans.category").'</label>';
echo '<input id="Category" type="text" name="Category" class="form-control" placeholder="'.costant::lang("trans.category.placeholder").'" autocomplete = "off" required />';
echo "<span class='help-block'></span>";
echo "</div>\n";

Expand All @@ -185,11 +171,9 @@ public static function input_category ($TrCategoryDefault)
//Create subcategory input element
public static function input_subcategory ($TrSubCategoryDefault)
{
global $lang;

echo "<div class='form-group'>";
echo "<label for='SubCategory'>{$lang["trans.sub-category"]}</label>";
echo "<input id='SubCategory' type='text' name='SubCategory' class='form-control' placeholder='{$lang["trans.sub-category.placeholder"]}' autocomplete='off' />";
echo '<label for="SubCategory">'.costant::lang("trans.sub-category").'</label>';
echo '<input id="SubCategory" type="text" name="SubCategory" class="form-control" placeholder="'.costant::lang("trans.sub-category.placeholder").'" autocomplete="off" />';
echo "<span class='help-block'></span>";
echo "</div>\n";

Expand All @@ -203,17 +187,15 @@ public static function input_subcategory ($TrSubCategoryDefault)
//Create amount input element
public static function input_amount ($TrAmountDefault)
{
global $lang;

echo "<div class='form-group'>";
echo "<label for='Amount'>{$lang["trans.amount"]}</label>";
echo '<label for="Amount">'.costant::lang("trans.amount").'</label>';
if ($TrAmountDefault <> 0)
{
echo "<input id='Amount' type='number' name='Amount' class='form-control' placeholder='{$lang["trans.amount.placeholder"]}' min='0.01' step ='0.01' value='${TrAmountDefault}' required />";
echo "<input id='Amount' type='number' name='Amount' class='form-control' placeholder='".costant::lang("trans.amount.placeholder")."' min='0.01' step ='0.01' value='{$TrAmountDefault}' required />";
}
else
{
echo "<input id='Amount' type='number' name='Amount' class='form-control' placeholder='{$lang["trans.amount.placeholder"]}' min='0.01' step ='0.01' required />";
echo "<input id='Amount' type='number' name='Amount' class='form-control' placeholder='".costant::lang("trans.amount.placeholder")."' min='0.01' step ='0.01' required />";
}
echo "<span class='help-block'></span>";
echo "</div>\n";
Expand All @@ -224,17 +206,15 @@ public static function input_amount ($TrAmountDefault)
//Create notes input element
public static function input_notes ($TrNotesDefault)
{
global $lang;

echo "<div class='form-group'>";
echo "<label for='Notes'>{$lang["trans.notes"]}</label>";
echo '<label for="Notes">'.costant::lang("trans.notes").'</label>';
if ($TrNotesDefault <> "Empty")
{
echo "<textarea id='Notes' name='Notes' class='form-control' rows='5' placeholder='{$lang["trans.notes.placeholder"]}'>${TrNotesDefault}</textarea>";
echo "<textarea id='Notes' name='Notes' class='form-control' rows='5' placeholder='".costant::lang("trans.notes.placeholder")."'>{$TrNotesDefault}</textarea>";
}
else
{
echo "<textarea id='Notes' name='Notes' class='form-control' rows='5' placeholder='{$lang["trans.notes.placeholder"]}'></textarea>";
echo "<textarea id='Notes' name='Notes' class='form-control' rows='5' placeholder='".costant::lang("trans.notes.placeholder")."'></textarea>";
}
echo "<span class='help-block'></span>";
echo "</div>\n";
Expand Down Expand Up @@ -313,14 +293,12 @@ 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 "<div class='form-group'>";
echo "<label for='Default_Account'>{$lang["settings.default-account"]}</label>";
echo '<label for="Default_Account">'.costant::lang("settings.default-account").'</label>';
echo "<select id ='Default_Account' name='Default_Account' class='form-control'>";
for ($i = 0; $i < sizeof($AccountArrayDesc); $i++)
{
Expand Down Expand Up @@ -354,12 +332,10 @@ public static function table_cell ($value,$css_class,$s_extra='')
//Create account input element
public static function settings_language ($Language)
{
global $lang;

$AvailableLanguages = array("en","it");

echo "<div class='form-group'>";
echo "<label for='Language'>{$lang["settings.language"]}</label>";
echo '<label for="Language">'.costant::lang("settings.language").'</label>';
echo "<select id ='Language' name='Language' class='form-control'>";
for ($i = 0; $i < sizeof($AvailableLanguages); $i++)
{
Expand Down
11 changes: 5 additions & 6 deletions WebApp/functions_various.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ public static function getPageUrl() : String
*/
public static function getPagesList() : Array
{
global $lang;
$pages_list = [
'new_transaction' => $lang["page.new-transaction"],
'show' => $lang["page.show-transactions"],
'settings' => $lang["page.settings"],
'guide' => $lang["page.guide"],
'about' => $lang["page.about"]
'new_transaction' => costant::lang("page.new-transaction"),
'show' => costant::lang("page.show-transactions"),
'settings' => costant::lang("page.settings"),
'guide' => costant::lang("page.guide"),
'about' => costant::lang("page.about")
];
return $pages_list;
}
Expand Down
9 changes: 7 additions & 2 deletions WebApp/languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,10 @@
$lang["guide.webapp-url"] = "WebApp URL";
$lang["guide.desktop-guid"] = "Desktop GUID";

$lang["show.no-pending-trans"] = "No pending transaction";
$lang["show.current-pending-trans"] = "Current pending transactions";
$lang["show.no_pending_trans"] = "No pending transactions";
$lang["show.current_pending_trans"] = "Current pending transactions";
$lang["show.delete_all_selected"] = "Delete all selected";
$lang["show.add_new"] = "Add new";
$lang["show.delete"] = "Delete";
$lang["show.new"] = "New transaction";
$lang["show.no_trans_selected"] = "No transaction selected!";
11 changes: 8 additions & 3 deletions WebApp/languages/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$lang["page.settings"] = "Impostazioni";
$lang["page.settings.new"] = "Nuove impostazioni";
$lang["page.guide"] = "Guida";
$lang["page.about"] = "About";
$lang["page.about"] = "Info";

$lang["sec.username"] = "Username";
$lang["sec.username.placeholder"] = "Inserisci lo Username";
Expand Down Expand Up @@ -92,5 +92,10 @@
$lang["guide.webapp-url"] = "WebApp URL:";
$lang["guide.desktop-guid"] = "Desktop GUID:";

$lang["show.no-pending-trans"] = "Nessuna operazione in sospeso";
$lang["show.current-pending-trans"] = "Operazioni in sospeso";
$lang["show.no_pending_trans"] = "Nessuna operazione in sospeso";
$lang["show.current_pending_trans"] = "Operazioni in sospeso";
$lang["show.delete_all_selected"] = "Cancella le righe selezionate";
$lang["show.add_new"] = "Nuova operazione";
$lang["show.delete"] = "Cancella";
$lang["show.new"] = "Nuova operazione";
$lang["show.no_trans_selected"] = "Nessuna operazione selezionata!";
6 changes: 3 additions & 3 deletions WebApp/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<br />
<form id="login" method="post" action="settings.php">
<?php
$const_language = costant::language();
$const_uiLanguage = costant::uiLanguage();
$const_disable_authentication = costant::disable_authentication();
$const_username = costant::login_username();
$const_password = costant::login_password();
Expand All @@ -104,8 +104,8 @@
$const_defaultaccountname = costant::transaction_default_account();

//SECTION LANGUAGE
if ($const_language)
{design::settings_language($const_language);}
if ($const_uiLanguage)
{design::settings_language($const_uiLanguage);}
else
{design::settings_language("en");}
echo "<br />";
Expand Down
24 changes: 12 additions & 12 deletions WebApp/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function drawRecordRow(Array $a_transaction, String $s_date) : void

$resultarray = db_function::transaction_select_all_order_by_date('DESC');
echo '<div class="container">';
echo '<h3 class="text_align_center">' . (count($resultarray) == 0 ? $lang["show.no-pending-trans"] : $lang["show.current-pending-trans"]). '</h3>';
echo '<h3 class="text_align_center">' . (count($resultarray) == 0 ? $lang["show.no_pending_trans"] : $lang["show.current_pending_trans"]). '</h3>';
echo '<br />';
echo '<div class="table-responsive">';

Expand All @@ -118,27 +118,27 @@ function drawRecordRow(Array $a_transaction, String $s_date) : void
/**
* delete button
*/
echo '<button type="submit" id="TrDelete" name="btn_action" value="Delete" class="btn btn-lg btn-danger btn-block">Cancella le righe selezionate</button>';
echo "<button type='submit' id='TrDelete' name='btn_action' value='Delete' class='btn btn-lg btn-danger btn-block'>{$lang["show.delete_all_selected"]}</button>";

/**
* new button
*/
echo '<input type="button" class="btn btn-lg btn-success btn-block" id="btn_new" value="Nuova operazione" onclick='."'top.location.href = ".'"new_transaction.php"'."' />";
echo '<input type="button" class="btn btn-lg btn-success btn-block" id="btn_new" value="'.$lang["show.new"].'" onclick='."'top.location.href = ".'"new_transaction.php"'."' />";
echo '<br />';

echo '<table class="table table-hover table-condensed">';
#echo '<table class = "table table-hover table-condensed table-bordered">'; //TABLE BORDERED FOR DEBUG
echo '<thead>';
echo '<tr>';
echo "<th class='text_align_center'><span class='glyphicon glyphicon-trash'></span> <span class='transaction-extra-columns'>Cancella</span></th>";
echo "<th class=''><span class='glyphicon glyphicon-info-sign'></span> <span class='transaction-extra-columns'>Tipo</span></th>";
echo '<th class="text_align_right">Importo</th>';
echo '<th class="text_align_center">Note</th>';
echo '<th>Conto</th>';
echo "<th class='text_align_center'><span class='glyphicon glyphicon-trash'></span> <span class='transaction-extra-columns'>{$lang["show.delete"]}</span></th>";
echo "<th class=''><span class='glyphicon glyphicon-info-sign'></span> <span class='transaction-extra-columns'>{$lang["trans.type"]}</span></th>";
echo "<th class='text_align_right'>{$lang["trans.amount"]}</th>";
echo "<th class='text_align_center'>{$lang["trans.notes"]}</th>";
echo "<th>{$lang["account"]}</th>";
if (costant::disable_payee() == False)
{echo "<th class='transaction-extra-columns'>Beneficiario</th>";}
{echo "<th class='transaction-extra-columns'>{$lang["trans.payee"]}</th>";}
if (costant::disable_category() == False)
{echo '<th>Categoria</th>';}
{echo "<th>{$lang["trans.category"]}</th>";}
echo '</tr>';
echo '</thead>';

Expand All @@ -161,10 +161,10 @@ function drawRecordRow(Array $a_transaction, String $s_date) : void
else: ?>

<div class="container">
<h3 class="text_align_center">nessuna operazione in sospeso</h3>
<h3 class="text_align_center"><?php echo $lang["show.no_pending_trans"] ?></h3>
<br />
<br />
<a href="new_transaction.php" class="btn btn-lg btn-success btn-block">Nuova operazione</a>
<a href="new_transaction.php" class="btn btn-lg btn-success btn-block"><?php echo $lang["show.add_new"] ?></a>

<?php

Expand Down
Loading

0 comments on commit 848ab95

Please sign in to comment.