Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website translation with php array files #48

Merged
merged 12 commits into from
Aug 16, 2024
2 changes: 1 addition & 1 deletion WebApp/_btn_back.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="div_btn_back">
<a href="landing.php" class="btn btn-lg btn-primary btn-block">Return to menu</a>
<a href="landing.php" class="btn btn-lg btn-primary btn-block"><?php echo $lang["return_to_menu"] ?></a>
</div>
2 changes: 1 addition & 1 deletion WebApp/_btn_logout.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="div_btn_logout">
<a href="logout.php" class="btn btn-lg btn-success btn-block">Logout</a>
<a href="logout.php" class="btn btn-lg btn-success btn-block"><?php echo $lang["sec.logout"] ?></a>
</div>
2 changes: 1 addition & 1 deletion WebApp/_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
if (!isset($b_debug))
{
$b_debug = false;
}
}
5 changes: 5 additions & 0 deletions WebApp/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions WebApp/functions_costant.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,16 @@ public static function current_page_url ()
{$pageURL .= ':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];}
return $pageURL;
}

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

public static function lang ($Key)
{
global $lang;
return $lang[$Key];
}
}
84 changes: 58 additions & 26 deletions WebApp/functions_design.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class design
public static function input_date ($TrDateDefault)
{
echo "<div class='form-group'>";
echo "<label for='Date'>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 @@ -20,11 +20,18 @@ public static function input_date ($TrDateDefault)
//Create status input element
public static function input_status ($TrStatusDefault)
{
$StatusArrayDesc = array ("None", "Reconciled", "Void", "Follow Up", "Duplicate");
$StatusArrayDesc = array (
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'>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 @@ -42,24 +49,29 @@ public static function input_status ($TrStatusDefault)
//Create type input element
public static function input_type ($TrTypeDefault)
{
$TypeArrayDesc = array ('Withdrawal', 'Deposit', 'Transfer');
$TypeArrayDesc = array (
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">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($TypeArrayDesc); $i++)
for ($i = 0; $i < sizeof($TypeArrayCode); $i++)
{
$is_selected = '';
if ($TypeArrayDesc[$i] == $TrTypeDefault)
if ($TypeArrayCode[$i] == $TrTypeDefault)
{
# $is_selected = 'selected';
$is_selected = 'checked';
}
$element_id = 'Type_' . $TypeArrayDesc[$i];
$element_id = 'Type_' . $TypeArrayCode[$i];
$element_onchange = str_replace('Type', $element_id, $on_change);
# echo "<option value='${TypeArrayDesc[$i]}' $is_selected> ${TypeArrayDesc[$i]} </option>";
echo '<input type="radio" id="' . $element_id . '" name="Type" value="' . $TypeArrayDesc[$i] . '" ' . $element_onchange . $is_selected . '>';
echo '<input type="radio" id="' . $element_id . '" name="Type" value="' . $TypeArrayCode[$i] . '" ' . $element_onchange . $is_selected . '>';
echo '<label for="' . $element_id . '">' . $TypeArrayDesc[$i] . '</label>';

}
Expand All @@ -77,7 +89,7 @@ public static function input_account ($TrAccountDefault)
{$AccountArrayDesc[0] = "None";}

echo "<div class='form-group'>";
echo "<label for='Account'>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 @@ -99,7 +111,7 @@ public static function input_toaccount ($TrToAccountDefault)
array_unshift($ToAccountArrayDesc,"None");

echo "<div class='form-group'>";
echo "<label for='ToAccount'>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 @@ -121,8 +133,8 @@ public static function input_payee ($TrPayeeDefault)
array_unshift($PayeeArrayDesc,"None");

echo "<div class='form-group'>";
echo "<label for='Payee'>Payee</label>";
echo "<input id='Payee' type='text' name='Payee' class='form-control' placeholder='Choose a payee' 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 @@ -142,8 +154,8 @@ public static function input_category ($TrCategoryDefault)
array_unshift($CategoryArrayDesc,"None");

echo "<div class='form-group'>";
echo "<label for='Category'>Category</label>";
echo "<input id='Category' type='text' name='Category' class='form-control' placeholder='Choose a category' 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 @@ -160,8 +172,8 @@ public static function input_category ($TrCategoryDefault)
public static function input_subcategory ($TrSubCategoryDefault)
{
echo "<div class='form-group'>";
echo "<label for='SubCategory'>SubCategory</label>";
echo "<input id='SubCategory' type='text' name='SubCategory' class='form-control' placeholder='Choose a subcategory' 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 @@ -176,14 +188,14 @@ public static function input_subcategory ($TrSubCategoryDefault)
public static function input_amount ($TrAmountDefault)
{
echo "<div class='form-group'>";
echo "<label for='Amount'>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='New transaction amount' 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='New transaction amount' 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 @@ -195,14 +207,14 @@ public static function input_amount ($TrAmountDefault)
public static function input_notes ($TrNotesDefault)
{
echo "<div class='form-group'>";
echo "<label for='Notes'>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='New transaction notes'>${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='New transaction notes'></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 @@ -263,10 +275,10 @@ public static function settings_checkbox ($VarName,$VarValue,$VarDescription)


//Create password input element
public static function settings_password ($VarName,$PlaceHolder,$Required)
public static function settings_password ($VarName,$PlaceHolder,$Required,$Label)
{
echo "<div class='form-group'>";
echo "<label for='Set_${VarName}'>".str_replace("_"," ",$VarName)."</label>";
echo "<label for='Set_${VarName}'>$Label</label>";
if ($Required == True)
{
echo "<input id='Set_${VarName}' type='Password' name='Set_${VarName}' class='form-control' placeholder='${PlaceHolder}' required />";
Expand All @@ -286,7 +298,7 @@ public static function settings_default_account ($TrAccountDefault)
{$AccountArrayDesc[0] = "None";}

echo "<div class='form-group'>";
echo "<label for='Default_Account'> 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 @@ -316,4 +328,24 @@ public static function table_cell ($value,$css_class,$s_extra='')
echo $value;
echo '</td>';
}

//Create account input element
public static function settings_language ($Language)
{
$AvailableLanguages = array("en","it");

echo "<div class='form-group'>";
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++)
{
if ($AvailableLanguages[$i] == $Language)
{echo "<option value=\"{$AvailableLanguages[$i]}\" selected> {$AvailableLanguages[$i]} </option>";}
else
{echo "<option value=\"{$AvailableLanguages[$i]}\"> {$AvailableLanguages[$i]} </option>";}
}
echo "</select>";
echo "<span class='help-block'></span>";
echo "</div>\n";
}
}
10 changes: 5 additions & 5 deletions WebApp/functions_various.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public static function getPageUrl() : String
public static function getPagesList() : Array
{
$pages_list = [
'new_transaction' => 'New transaction',
'show' => 'Show transactions',
'settings' => 'Edit settings',
'guide' => 'Guide',
'about' => '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
10 changes: 5 additions & 5 deletions WebApp/guide.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
<p>
<ol>
<li>
Copy the data below and paste them into your desktop application.
<?php echo $lang["guide.step1"] ?>
</li>
<li>
Re-open desktop application to synchronise bank account(s), etc. to the WebApp from Desktop.
<?php echo $lang["guide.step2"] ?>
</li>
<li>
Start using the WebApp version.
<?php echo $lang["guide.step3"] ?>
</li>
</ol>
</p>
</div>
<div class="container text_align_center">
<h4>
WebApp URL:
<?php echo $lang["guide.webapp-url"] ?>
</h4>
<p>
<strong>
Expand All @@ -35,7 +35,7 @@
</p>
<br />
<h4>
Desktop GUID:
<?php echo $lang["guide.desktop-guid"] ?>
</h4>
<p>
<strong>
Expand Down
12 changes: 6 additions & 6 deletions WebApp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$upgrade_result = db_upgrade::upgrade_db();
if ($upgrade_result == 'update_done')
{
various::send_alert_and_redirect('Database succesfully updated to version '.costant::app_version(), 'index.php');
various::send_alert_and_redirect($lang["db_successfully_updated_to_version"].costant::app_version(), 'index.php');
}
}
$username = null;
Expand Down Expand Up @@ -71,17 +71,17 @@
<div class="container text_align_center">
<form id="login" method="post">
<div class="form-group">
<label for="Username">Username</label>
<input id="Username" type="text" name="Username" class="form-control" placeholder="Insert Username" autofocus required />
<label for="Username"><?php echo $lang["sec.username"]; ?></label>
<input id="Username" type="text" name="Username" class="form-control" placeholder="<?php echo $lang["sec.username.placeholder"] ?>"" autofocus required />
<span class="help-block"></span>
</div>
<div class="form-group">
<label for="Password">Password</label>
<input id="Password" type="password" name="Password" class="form-control" placeholder="Insert Password" required />
<label for="Password"><?php echo $lang["sec.password"]; ?></label>
<input id="Password" type="password" name="Password" class="form-control" placeholder="<?php echo $lang["sec.password.placeholder"] ?>" required />
<span class="help-block"></span>
</div>
<br />
<button type="submit" id="Login" name="Login" class="btn btn-lg btn-success btn-block" value = "Login">Login</button>
<button type="submit" id="Login" name="Login" class="btn btn-lg btn-success btn-block" value = "Login"><?php echo $lang["sec.login"] ?></button>
</form>
</div>
<?php
Expand Down
15 changes: 8 additions & 7 deletions WebApp/insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@
$TrEditedNr = $_POST["TrEditedNr"];
}

include_once '_common.php';

switch ($TrEditedNr)
{
case -1:
$s_page_title = 'New Transaction';
$s_page_title = $lang["page.transaction.added"];
$transaction_action = 'added';
break;
case 0:
$s_page_title = 'Existing Transaction';
$s_page_title = $lang["page.transaction.duplicated"];
$transaction_action = 'duplicated';
break;
default:
$s_page_title = 'Existing Transaction';
$s_page_title = $lang["page.transaction.updated"];
$transaction_action = 'updated';
break;
}

$a_head_js_add[] = '<script src="res/app/base-1.0.4.js" type="text/javascript"></script>';
$a_head_css_add[] = '<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">';

include_once '_common.php';
include_once '_header.php';


Expand Down Expand Up @@ -84,13 +85,13 @@
check_box
</i>
<h3>
<?php echo ucfirst($transaction_action); ?> successfully
<?php echo $lang["trans.msg.action-".$transaction_action.".successfully"] ?>
</h3>
<br />
<br />
<a href="new_transaction.php" class="btn btn-lg btn-success btn-block">Add next</a>
<a href="new_transaction.php" class="btn btn-lg btn-success btn-block"><?php echo $lang["trans.msg.add-next"] ?></a>
<br />
<a href="show.php" class="btn btn-lg btn-success btn-block">Show transactions</a>
<a href="show.php" class="btn btn-lg btn-success btn-block"><?php echo $lang["page.show-transactions"] ?></a>
<br />
</div>

Expand Down
Loading