Skip to content

Commit

Permalink
Add translation system (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite authored Jan 23, 2024
1 parent d287f30 commit d7366dc
Show file tree
Hide file tree
Showing 35 changed files with 965 additions and 317 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Wallos: Open-Source Personal Subscription Tracker
- [Docker-Compose](#docker-compose)
- [Usage](#usage)
- [Contributing](#contributing)
- [Translations](#translations)
- [Screenshots](#screenshots)
- [License](#license)

Expand Down Expand Up @@ -139,6 +140,15 @@ Feel free to open Pull requests with bug fixes and features. I'll do my best to
Feel free to open issues with bug reports or feature requests. Bug fixes will take priority.
I welcome contributions from the community and look forward to working with you to improve this project.

### Translations

If you want to contribute with a translation of wallos:
- Add your language code to `includes/i18n/languages.php` in the format `"en" => "English"`. Please use the original language name and not the english translation.
- Create a copy of the file `includes/i18n/en.php` and rename it to the language code you used above. Example: pt.php for "pt" => "Português".
- Translate all the values on the language file to the new language. (Incomplete translations will not be accepted).
- Create a copy of the file `scripts/i18n/en.php` and rename it to the language code you used above.
- Translate all the values on the language file to the new language. (Incomplete translations will not be accepted).

## License

This project is licensed under the [GNU General Public License, Version 3](LICENSE.md) - see the [LICENSE.md](LICENSE.md) file for details.
Expand Down
26 changes: 13 additions & 13 deletions about.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@

<section class="account-section">
<header>
<h2>About and Credits</h2>
<h2><?= translate('about_and_credits', $i18n) ?></h2>
</header>
<div class="credits-list">
<p>Wallos v1.1.0</p>
<p>License:
<p>Wallos v1.2.0</p>
<p><?= translate('license', $i18n) ?>:
<span>
GPLv3
<a href="https://www.gnu.org/licenses/gpl-3.0.en.html" target="_blank" title="Visit external url">
<a href="https://www.gnu.org/licenses/gpl-3.0.en.html" target="_blank" title="<?= translate('external_url', $i18n) ?>">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</span>
</p>
<p>
Issues and Request:
<?= translate('issues_and_requests', $i18n) ?>:
<span>
GitHub
<a href="https://github.com/ellite/Wallos/issues" target="_blank" title="Visit external url">
<a href="https://github.com/ellite/Wallos/issues" target="_blank" title="<?= translate('external_url', $i18n) ?>">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</span>
</p>
<p>
The author:
<?= translate('the_author', $i18n) ?>:
<span>
https://henrique.pt
<a href="https://henrique.pt/" target="_blank" title="Visit external url">
<a href="https://henrique.pt/" target="_blank" title="<?= translate('external_url', $i18n) ?>">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</span>
</p>
<p>
Icons:
<?= translate('icons', $i18n) ?>:
<span>
https://www.streamlinehq.com/freebies/plump-flat-free
<a href="https://www.streamlinehq.com/freebies/plump-flat-free" target="_blank" title="Visit external url">
<a href="https://www.streamlinehq.com/freebies/plump-flat-free" target="_blank" title="<?= translate('external_url', $i18n) ?>">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</span>
</p>
<p>
Payment Icons:
<?= translate('payment_icons', $i18n) ?>:
<span>
https://www.figma.com/file/5IMW8JfoXfB5GRlPNdTyeg/Credit-Cards-and-Payment-Methods-Icons-(Community)
<a href="https://www.figma.com/file/5IMW8JfoXfB5GRlPNdTyeg/Credit-Cards-and-Payment-Methods-Icons-(Community)" target="_blank" title="Visit external url">
<a href="https://www.figma.com/file/5IMW8JfoXfB5GRlPNdTyeg/Credit-Cards-and-Payment-Methods-Icons-(Community)" target="_blank" title="<?= translate('external_url', $i18n) ?>">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</span>
Expand All @@ -58,7 +58,7 @@
Chart.js:
<span>
https://www.chartjs.org/
<a href="https://www.chartjs.org/" target="_blank" title="Visit external url">
<a href="https://www.chartjs.org/" target="_blank" title="<?= translate('external_url', $i18n) ?>">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
</a>
</span>
Expand Down
22 changes: 12 additions & 10 deletions endpoints/categories/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to add category"
"errorMessage" => translate('failed_add_category', $i18n)
];
echo json_encode($response);
}
Expand All @@ -35,20 +35,21 @@

if ($result) {
$response = [
"success" => true
"success" => true,
"message" => translate('category_saved', $i18n)
];
echo json_encode($response);
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to edit category"
"errorMessage" => translate('failed_edit_category', $i18n)
];
echo json_encode($response);
}
} else {
$response = [
"success" => false,
"errorMessage" => "Please fill all the fields"
"errorMessage" => translate('fill_all_fields', $i18n)
];
echo json_encode($response);
}
Expand All @@ -65,7 +66,7 @@
if ($count > 0) {
$response = [
"success" => false,
"errorMessage" => "Category is in use in subscriptions and can't be removed"
"errorMessage" => translate('category_in_use', $i18n)
];
echo json_encode($response);
} else {
Expand All @@ -75,29 +76,30 @@
$result = $stmt->execute();
if ($result) {
$response = [
"success" => true
"success" => true,
"message" => translate('category_removed', $i18n)
];
echo json_encode($response);
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to remove category"
"errorMessage" => translate('failed_remove_category', $i18n)
];
echo json_encode($response);
}
}
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to remove category"
"errorMessage" => translate('failed_remove_category', $i18n)
];
echo json_encode($response);
}
} else {
echo "Error";
echo translate('error', $i18n);
}
} else {
echo "Error";
echo translate('error', $i18n);
}

?>
24 changes: 14 additions & 10 deletions endpoints/currency/currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$currencyId = $db->lastInsertRowID();
echo $currencyId;
} else {
echo "Error adding currency entry.";
echo translate('error_adding_currency', $i18n);
}
} else if (isset($_GET['action']) && $_GET['action'] == "edit") {
if (isset($_GET['currencyId']) && $_GET['currencyId'] != "" && isset($_GET['name']) && $_GET['name'] != "" && isset($_GET['symbol']) && $_GET['symbol'] != "") {
Expand All @@ -36,18 +36,22 @@
$result = $stmt->execute();

if ($result) {
echo json_encode(["success" => true]);
$response = [
"success" => true,
"message" => $name . " " . translate('currency_saved', $i18n)
];
echo json_encode($response);
} else {
$response = [
"success" => false,
"message" => "Failed to store Currency on the Database"
"message" => translate('failed_to_store_currency', $i18n)
];
echo json_encode($response);
}
} else {
$response = [
"success" => false,
"message" => "Some fields are missing"
"message" => translate('fields_missing', $i18n)
];
echo json_encode($response);
}
Expand All @@ -70,15 +74,15 @@
if ($count > 0) {
$response = [
"success" => false,
"message" => "Currency is in use in subscriptions and can't be deleted."
"message" => translate('currency_in_use', $i18n)
];
echo json_encode($response);
exit;
} else {
if ($currencyId == $mainCurrencyId) {
$response = [
"success" => false,
"message" => "Currency is set as main currency and can't be deleted."
"message" => translate('currency_is_main', $i18n)
];
echo json_encode($response);
exit;
Expand All @@ -88,11 +92,11 @@
$stmt->bindParam(':currencyId', $currencyId, SQLITE3_INTEGER);
$result = $stmt->execute();
if ($result) {
echo json_encode(["success" => true]);
echo json_encode(["success" => true, "message" => translate('currency_removed', $i18n)]);
} else {
$response = [
"success" => false,
"message" => "Failed to remove currency from the Database"
"message" => translate('failed_to_remove_currency', $i18n)
];
echo json_encode($response);
}
Expand All @@ -101,7 +105,7 @@
} else {
$response = [
"success" => false,
"message" => "Some fields are missing."
"message" => translate('fields_missing', $i18n)
];
echo json_encode($response);
}
Expand All @@ -111,7 +115,7 @@
} else {
$response = [
"success" => false,
"message" => "Your session expired. Please login again"
"message" => translate('session_expired', $i18n)
];
echo json_encode($response);
}
Expand Down
8 changes: 4 additions & 4 deletions endpoints/currency/fixer_api_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
$stmt->bindParam(":api_key", $newApiKey, SQLITE3_TEXT);
$result = $stmt->execute();
if ($result) {
echo json_encode(["success" => true]);
echo json_encode(["success" => true, "message" => translate('api_key_saved', $i18n)]);
} else {
$response = [
"success" => false,
"message" => "Failed to store API Key on the Database"
"message" => translate('failed_to_store_api_key', $i18n)
];
echo json_encode($response);
}
} else {
echo json_encode(["success" => true]);
echo json_encode(["success" => true, "message" => translate('apy_key_saved', $i18n)]);
}
} else {
$response = [
"success" => false,
"message" => "Invalid API Key"
"message" => translate('invalid_api_key', $i18n)
];
echo json_encode($response);
}
Expand Down
24 changes: 13 additions & 11 deletions endpoints/household/household.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
$householdId = $db->lastInsertRowID();
$response = [
"success" => true,
"householdId" => $householdId
"householdId" => $householdId,
];
echo json_encode($response);
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to add household member"
"errorMessage" => translate('failed_add_household', $i18n)
];
echo json_encode($response);
}
Expand All @@ -35,20 +35,21 @@

if ($result) {
$response = [
"success" => true
"success" => true,
"message" => translate('member_saved', $i18n)
];
echo json_encode($response);
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to edit household member"
"errorMessage" => translate('failed_edit_household', $i18n)
];
echo json_encode($response);
}
} else {
$response = [
"success" => false,
"errorMessage" => "Please fill all the fields"
"errorMessage" => translate('fill_all_fields', $i18n)
];
echo json_encode($response);
}
Expand All @@ -65,7 +66,7 @@
if ($count > 0) {
$response = [
"success" => false,
"errorMessage" => "Household member is in use in subscriptions and can't be removed"
"errorMessage" => translate('household_in_use', $i18n)
];
echo json_encode($response);
} else {
Expand All @@ -75,29 +76,30 @@
$result = $stmt->execute();
if ($result) {
$response = [
"success" => true
"success" => true,
"message" => translate('member_removed', $i18n)
];
echo json_encode($response);
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to remove household member"
"errorMessage" => translate('failed_remove_household', $i18n)
];
echo json_encode($response);
}
}
} else {
$response = [
"success" => false,
"errorMessage" => "Failed to remove household member"
"errorMessage" => translate('failed_remove_household', $i18n)
];
echo json_encode($response);
}
} else {
echo "Error";
echo translate('error', $i18n);
}
} else {
echo "Error";
echo translate('error', $i18n);
}

?>
Loading

0 comments on commit d7366dc

Please sign in to comment.