From 078dd2a35847068df88a5b6f7a300ee6383a05d9 Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Sun, 6 Nov 2022 02:11:58 -0500 Subject: [PATCH] V2022.11.0-beta2 --- .gitignore | 3 ++ meson.build | 1 + org.nickvision.money.json | 2 +- org.nickvision.money.metainfo.xml | 3 +- po/LINGUAS | 0 po/POTFILES | 14 ++++++ po/meson.build | 5 +++ src/controllers/accountviewcontroller.cpp | 9 ++-- .../transactiondialogcontroller.cpp | 5 ++- src/helpers/stringhelpers.cpp | 3 ++ src/helpers/stringhelpers.hpp | 29 ++++++++++++ src/helpers/translation.hpp | 5 +++ src/main.cpp | 7 +++ src/meson.build | 3 ++ src/models/transaction.cpp | 15 ++++--- src/ui/application.cpp | 7 +-- src/ui/controls/comboboxdialog.cpp | 3 +- src/ui/controls/entrydialog.cpp | 3 +- src/ui/controls/grouprow.cpp | 5 ++- src/ui/controls/transactionrow.cpp | 7 +-- src/ui/views/accountview.cpp | 35 ++++++++------- src/ui/views/groupdialog.cpp | 17 +++---- src/ui/views/mainwindow.cpp | 29 ++++++------ src/ui/views/preferencesdialog.cpp | 21 ++++----- src/ui/views/shortcutsdialog.cpp | 44 +++++++++++++------ src/ui/views/transactiondialog.cpp | 35 ++++++++------- 26 files changed, 207 insertions(+), 103 deletions(-) create mode 100644 po/LINGUAS create mode 100644 po/POTFILES create mode 100644 po/meson.build create mode 100644 src/helpers/stringhelpers.cpp create mode 100644 src/helpers/stringhelpers.hpp create mode 100644 src/helpers/translation.hpp diff --git a/.gitignore b/.gitignore index 2251e1000..4cf08a611 100644 --- a/.gitignore +++ b/.gitignore @@ -334,6 +334,9 @@ ASALocalRun/ # Local History for Visual Studio .localhistory/ +# Gettext model +*.pot + # Prerequisites *.d diff --git a/meson.build b/meson.build index 5bbc83ceb..dae1146df 100644 --- a/meson.build +++ b/meson.build @@ -11,6 +11,7 @@ sqlitecpp = dependency('SQLiteCpp') boost = dependency('boost') subdir('src') +subdir('po') executable('org.nickvision.money', sources, dependencies: [threads, adwaita, jsoncpp, dl, sqlitecpp, boost], install: true) install_data(resources, install_dir: 'share/icons/hicolor/scalable/apps') diff --git a/org.nickvision.money.json b/org.nickvision.money.json index 65cee7efd..8b1469c6c 100644 --- a/org.nickvision.money.json +++ b/org.nickvision.money.json @@ -64,7 +64,7 @@ { "type": "git", "url": "https://github.com/nlogozzo/NickvisionMoney.git", - "tag": "2022.11.0-beta1" + "tag": "2022.11.0-beta2" } ] } diff --git a/org.nickvision.money.metainfo.xml b/org.nickvision.money.metainfo.xml index dca809f2c..7aa870058 100644 --- a/org.nickvision.money.metainfo.xml +++ b/org.nickvision.money.metainfo.xml @@ -31,9 +31,10 @@ org.nickvision.money - +

- Introducing Groups: Add groups to an account and associate transactions with groups for a more precise finance management system

+

- Added support for translations

diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 000000000..e69de29bb diff --git a/po/POTFILES b/po/POTFILES new file mode 100644 index 000000000..526d2c6aa --- /dev/null +++ b/po/POTFILES @@ -0,0 +1,14 @@ +src/controllers/accountviewcontroller.cpp +src/controllers/transactiondialogcontroller.cpp +src/models/transaction.cpp +src/ui/application.cpp +src/ui/controls/comboboxdialog.cpp +src/ui/controls/entrydialog.cpp +src/ui/controls/grouprow.cpp +src/ui/controls/transactionrow.cpp +src/ui/views/accountview.cpp +src/ui/views/groupdialog.cpp +src/ui/views/mainwindow.cpp +src/ui/views/preferencesdialog.cpp +src/ui/views/shortcutsdialog.cpp +src/ui/views/transactiondialog.cpp \ No newline at end of file diff --git a/po/meson.build b/po/meson.build new file mode 100644 index 000000000..05fc058f9 --- /dev/null +++ b/po/meson.build @@ -0,0 +1,5 @@ +i18n = import('i18n') +# define GETTEXT_PACKAGE and LOCALE_DIR +add_project_arguments('-DGETTEXT_PACKAGE="' + meson.project_name() + '"', language:'cpp') +add_project_arguments('-DLOCALE_DIR="' + join_paths(get_option('prefix'), get_option('localedir')) + '"', language:'cpp') +i18n.gettext(meson.project_name()) \ No newline at end of file diff --git a/src/controllers/accountviewcontroller.cpp b/src/controllers/accountviewcontroller.cpp index 9ae1ce5f4..1c1b7831f 100644 --- a/src/controllers/accountviewcontroller.cpp +++ b/src/controllers/accountviewcontroller.cpp @@ -1,7 +1,10 @@ #include "accountviewcontroller.hpp" #include +#include "../helpers/stringhelpers.hpp" +#include "../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; +using namespace NickvisionMoney::Helpers; using namespace NickvisionMoney::Models; AccountViewController::AccountViewController(const std::string& path, const std::string& currencySymbol, bool displayCurrencySymbolOnRight, const std::function& sendToastCallback) : m_currencySymbol{ currencySymbol }, m_displayCurrencySymbolOnRight{ displayCurrencySymbolOnRight }, m_account{ path }, m_sendToastCallback{ sendToastCallback } @@ -89,11 +92,11 @@ void AccountViewController::exportAsCSV(std::string& path) } if(m_account.exportAsCSV(path)) { - m_sendToastCallback("Exported account to CSV successfully."); + m_sendToastCallback(_("Exported account to CSV successfully.")); } else { - m_sendToastCallback("Unable to export account as CSV."); + m_sendToastCallback(_("Unable to export account as CSV.")); } } @@ -104,7 +107,7 @@ void AccountViewController::importFromCSV(std::string& path) { m_accountInfoChangedCallback(); } - m_sendToastCallback("Imported " + std::to_string(imported) + " transactions from CSV."); + m_sendToastCallback(StringHelpers::format(_("Imported %d transactions from CSV."), imported)); } void AccountViewController::addGroup(const Group& group) diff --git a/src/controllers/transactiondialogcontroller.cpp b/src/controllers/transactiondialogcontroller.cpp index a984afc48..e95199605 100644 --- a/src/controllers/transactiondialogcontroller.cpp +++ b/src/controllers/transactiondialogcontroller.cpp @@ -1,13 +1,14 @@ #include "transactiondialogcontroller.hpp" #include #include +#include "../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; using namespace NickvisionMoney::Models; TransactionDialogController::TransactionDialogController(unsigned int newId, const std::string& currencySymbol, const std::map& groups) : m_response{ "cancel" }, m_currencySymbol{ currencySymbol }, m_transaction{ newId }, m_groups{ groups } { - m_groupNames.push_back("None"); + m_groupNames.push_back(_("None")); for(const std::pair& pair : m_groups) { m_groupNames.push_back(pair.second.getName()); @@ -16,7 +17,7 @@ TransactionDialogController::TransactionDialogController(unsigned int newId, con TransactionDialogController::TransactionDialogController(const Transaction& transaction, const std::string& currencySymbol, const std::map& groups) : m_response{ "cancel" }, m_currencySymbol{ currencySymbol }, m_transaction{ transaction }, m_groups{ groups } { - m_groupNames.push_back("None"); + m_groupNames.push_back(_("None")); for(const std::pair& pair : m_groups) { m_groupNames.push_back(pair.second.getName()); diff --git a/src/helpers/stringhelpers.cpp b/src/helpers/stringhelpers.cpp new file mode 100644 index 000000000..4894d236e --- /dev/null +++ b/src/helpers/stringhelpers.cpp @@ -0,0 +1,3 @@ +#include "stringhelpers.hpp" + +using namespace NickvisionMoney::Helpers; diff --git a/src/helpers/stringhelpers.hpp b/src/helpers/stringhelpers.hpp new file mode 100644 index 000000000..e05fae4aa --- /dev/null +++ b/src/helpers/stringhelpers.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +namespace NickvisionMoney::Helpers::StringHelpers +{ + /** + * Formats a string similarly to sprintf in C + * + * @param format The source string + * @param args The arguments to be added + * @returns The formatted string + */ + template + std::string format(const std::string& format, Args... args) + { + int size_s{ std::snprintf(nullptr, 0, format.c_str(), args...) + 1 }; // Extra space for '\0' + if (size_s <= 0) + { + throw std::runtime_error("Error during formatting."); + } + size_t size{ static_cast(size_s) }; + std::unique_ptr buf{ new char[size] }; + std::snprintf(buf.get(), size, format.c_str(), args...); + return { buf.get(), buf.get() + size - 1 }; // We don't want the '\0' inside + } +} \ No newline at end of file diff --git a/src/helpers/translation.hpp b/src/helpers/translation.hpp new file mode 100644 index 000000000..15b70fbab --- /dev/null +++ b/src/helpers/translation.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +#define _(String) gettext(String) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4f9b1fbc9..a789c6a2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include #include "ui/application.hpp" using namespace NickvisionMoney::UI; @@ -12,6 +13,12 @@ using namespace NickvisionMoney::UI; */ int main(int argc, char* argv[]) { + //Translations + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + //Start App Application app("org.nickvision.money"); return app.run(argc, argv); } diff --git a/src/meson.build b/src/meson.build index dacb55eb0..4824ee67a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,7 @@ sources = files('main.cpp', + 'helpers/translation.hpp', + 'helpers/stringhelpers.hpp', + 'helpers/stringhelpers.cpp', 'models/appinfo.hpp', 'models/appinfo.cpp', 'models/configuration.hpp', diff --git a/src/models/transaction.cpp b/src/models/transaction.cpp index ab01b5a66..c0b55afdb 100644 --- a/src/models/transaction.cpp +++ b/src/models/transaction.cpp @@ -1,4 +1,5 @@ #include "transaction.hpp" +#include "../helpers/translation.hpp" using namespace NickvisionMoney::Models; @@ -51,31 +52,31 @@ std::string Transaction::getRepeatIntervalAsString() const { if(m_repeatInterval == RepeatInterval::Never) { - return "Never"; + return _("Never"); } else if(m_repeatInterval == RepeatInterval::Daily) { - return "Daily"; + return _("Daily"); } else if(m_repeatInterval == RepeatInterval::Weekly) { - return "Weekly"; + return _("Weekly"); } else if(m_repeatInterval == RepeatInterval::Monthly) { - return "Monthly"; + return _("Monthly"); } else if(m_repeatInterval == RepeatInterval::Quarterly) { - return "Quarterly"; + return _("Quarterly"); } else if(m_repeatInterval == RepeatInterval::Yearly) { - return "Yearly"; + return _("Yearly"); } else if(m_repeatInterval == RepeatInterval::Biyearly) { - return "Biyearly"; + return _("Biyearly"); } return ""; } diff --git a/src/ui/application.cpp b/src/ui/application.cpp index d306f9e03..d07d5f7a7 100644 --- a/src/ui/application.cpp +++ b/src/ui/application.cpp @@ -1,5 +1,6 @@ #include "application.hpp" #include "../controllers/mainwindowcontroller.hpp" +#include "../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; using namespace NickvisionMoney::Models; @@ -12,9 +13,9 @@ Application::Application(const std::string& id, GApplicationFlags flags) : m_adw m_appInfo.setId(id); m_appInfo.setName("Nickvision Money"); m_appInfo.setShortName("Money"); - m_appInfo.setDescription("A personal finance manager."); - m_appInfo.setVersion("2022.11.0-beta1"); - m_appInfo.setChangelog("
  • Introducing Groups: Add groups to an account and associate transactions with groups for a more precise finance management system
"); + m_appInfo.setDescription(_("A personal finance manager.")); + m_appInfo.setVersion("2022.11.0-beta2"); + m_appInfo.setChangelog("
  • Introducing Groups: Add groups to an account and associate transactions with groups for a more precise finance management system
  • Added support for translations
"); m_appInfo.setGitHubRepo("https://github.com/nlogozzo/NickvisionMoney"); m_appInfo.setIssueTracker("https://github.com/nlogozzo/NickvisionMoney/issues/new"); m_appInfo.setSupportUrl("https://github.com/nlogozzo/NickvisionMoney/discussions"); diff --git a/src/ui/controls/comboboxdialog.cpp b/src/ui/controls/comboboxdialog.cpp index dc15b4b81..57ea127af 100644 --- a/src/ui/controls/comboboxdialog.cpp +++ b/src/ui/controls/comboboxdialog.cpp @@ -1,4 +1,5 @@ #include "comboboxdialog.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::UI::Controls; @@ -6,7 +7,7 @@ ComboBoxDialog::ComboBoxDialog(GtkWindow* parent, const std::string& title, cons { //Dialog Settings gtk_window_set_hide_on_close(GTK_WINDOW(m_gobj), true); - adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", "Cancel", "ok", "OK", nullptr); + adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", _("Cancel"), "ok", _("OK"), nullptr); adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(m_gobj), "ok", ADW_RESPONSE_SUGGESTED); adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); diff --git a/src/ui/controls/entrydialog.cpp b/src/ui/controls/entrydialog.cpp index 475b9c688..351f08027 100644 --- a/src/ui/controls/entrydialog.cpp +++ b/src/ui/controls/entrydialog.cpp @@ -1,4 +1,5 @@ #include "entrydialog.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::UI::Controls; @@ -6,7 +7,7 @@ EntryDialog::EntryDialog(GtkWindow* parent, const std::string& title, const std: { //Dialog Settings gtk_window_set_hide_on_close(GTK_WINDOW(m_gobj), true); - adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", "Cancel", "ok", "OK", nullptr); + adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", _("Cancel"), "ok", _("OK"), nullptr); adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(m_gobj), "ok", ADW_RESPONSE_SUGGESTED); adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); diff --git a/src/ui/controls/grouprow.cpp b/src/ui/controls/grouprow.cpp index d21f621eb..45627480c 100644 --- a/src/ui/controls/grouprow.cpp +++ b/src/ui/controls/grouprow.cpp @@ -1,6 +1,7 @@ #include "grouprow.hpp" #include #include +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Models; using namespace NickvisionMoney::UI::Controls; @@ -27,7 +28,7 @@ GroupRow::GroupRow(const Group& group, const std::string& currencySymbol, bool d gtk_widget_set_valign(m_btnEdit, GTK_ALIGN_CENTER); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnEdit), "flat"); gtk_button_set_icon_name(GTK_BUTTON(m_btnEdit), "edit-symbolic"); - gtk_widget_set_tooltip_text(m_btnEdit, "Edit Group"); + gtk_widget_set_tooltip_text(m_btnEdit, _("Edit Group")); adw_action_row_set_activatable_widget(ADW_ACTION_ROW(m_gobj), m_btnEdit); g_signal_connect(m_btnEdit, "clicked", G_CALLBACK((void (*)(GtkButton*, gpointer))[](GtkButton*, gpointer data) { reinterpret_cast(data)->onEdit(); }), this); //Delete Button @@ -35,7 +36,7 @@ GroupRow::GroupRow(const Group& group, const std::string& currencySymbol, bool d gtk_widget_set_valign(m_btnDelete, GTK_ALIGN_CENTER); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnDelete), "flat"); gtk_button_set_icon_name(GTK_BUTTON(m_btnDelete), "user-trash-symbolic"); - gtk_widget_set_tooltip_text(m_btnDelete, "Delete Group"); + gtk_widget_set_tooltip_text(m_btnDelete, _("Delete Group")); g_signal_connect(m_btnDelete, "clicked", G_CALLBACK((void (*)(GtkButton*, gpointer))[](GtkButton*, gpointer data) { reinterpret_cast(data)->onDelete(); }), this); //Box m_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); diff --git a/src/ui/controls/transactionrow.cpp b/src/ui/controls/transactionrow.cpp index c76aa4f28..0fbf811fe 100644 --- a/src/ui/controls/transactionrow.cpp +++ b/src/ui/controls/transactionrow.cpp @@ -1,6 +1,7 @@ #include "transactionrow.hpp" #include #include +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Models; using namespace NickvisionMoney::UI::Controls; @@ -16,7 +17,7 @@ TransactionRow::TransactionRow(const Transaction& transaction, const std::string builder << boost::gregorian::to_iso_extended_string(m_transaction.getDate()); if(m_transaction.getRepeatInterval() != RepeatInterval::Never) { - builder << "\n" << "Repeat Interval: " << m_transaction.getRepeatIntervalAsString(); + builder << "\n" << _("Repeat Interval: ") << m_transaction.getRepeatIntervalAsString(); } adw_action_row_set_subtitle(ADW_ACTION_ROW(m_gobj), builder.str().c_str()); //Amount Label @@ -37,7 +38,7 @@ TransactionRow::TransactionRow(const Transaction& transaction, const std::string gtk_widget_set_valign(m_btnEdit, GTK_ALIGN_CENTER); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnEdit), "flat"); gtk_button_set_icon_name(GTK_BUTTON(m_btnEdit), "edit-symbolic"); - gtk_widget_set_tooltip_text(m_btnEdit, "Edit Transaction"); + gtk_widget_set_tooltip_text(m_btnEdit, _("Edit Transaction")); adw_action_row_set_activatable_widget(ADW_ACTION_ROW(m_gobj), m_btnEdit); g_signal_connect(m_btnEdit, "clicked", G_CALLBACK((void (*)(GtkButton*, gpointer))[](GtkButton*, gpointer data) { reinterpret_cast(data)->onEdit(); }), this); //Delete Button @@ -45,7 +46,7 @@ TransactionRow::TransactionRow(const Transaction& transaction, const std::string gtk_widget_set_valign(m_btnDelete, GTK_ALIGN_CENTER); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnDelete), "flat"); gtk_button_set_icon_name(GTK_BUTTON(m_btnDelete), "user-trash-symbolic"); - gtk_widget_set_tooltip_text(m_btnDelete, "Delete Transaction"); + gtk_widget_set_tooltip_text(m_btnDelete, _("Delete Transaction")); g_signal_connect(m_btnDelete, "clicked", G_CALLBACK((void (*)(GtkButton*, gpointer))[](GtkButton*, gpointer data) { reinterpret_cast(data)->onDelete(); }), this); //Box m_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); diff --git a/src/ui/views/accountview.cpp b/src/ui/views/accountview.cpp index 732f796d2..f602ddc2f 100644 --- a/src/ui/views/accountview.cpp +++ b/src/ui/views/accountview.cpp @@ -2,6 +2,7 @@ #include "groupdialog.hpp" #include "transactiondialog.hpp" #include "../controls/messagedialog.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; using namespace NickvisionMoney::Models; @@ -14,7 +15,7 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con m_boxMain = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); //Account Total m_rowTotal = adw_expander_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowTotal), "Total"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowTotal), _("Total")); adw_expander_row_set_subtitle(ADW_EXPANDER_ROW(m_rowTotal), ""); adw_expander_row_set_expanded(ADW_EXPANDER_ROW(m_rowTotal), true); //Account Income @@ -22,7 +23,7 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_widget_set_valign(m_lblIncome, GTK_ALIGN_CENTER); gtk_style_context_add_class(gtk_widget_get_style_context(m_lblIncome), "success"); m_rowIncome = adw_action_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowIncome), "Income"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowIncome), _("Income")); adw_action_row_add_suffix(ADW_ACTION_ROW(m_rowIncome), m_lblIncome); adw_expander_row_add_row(ADW_EXPANDER_ROW(m_rowTotal), m_rowIncome); //Account Expense @@ -30,7 +31,7 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_widget_set_valign(m_lblExpense, GTK_ALIGN_CENTER); gtk_style_context_add_class(gtk_widget_get_style_context(m_lblExpense), "error"); m_rowExpense = adw_action_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowExpense), "Expense"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowExpense), _("Expense")); adw_action_row_add_suffix(ADW_ACTION_ROW(m_rowExpense), m_lblExpense); adw_expander_row_add_row(ADW_EXPANDER_ROW(m_rowTotal), m_rowExpense); //Button Menu Account Actions @@ -38,11 +39,11 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_style_context_add_class(gtk_widget_get_style_context(m_btnMenuAccountActions), "flat"); GtkWidget* btnMenuAccountActionsContent{ adw_button_content_new() }; adw_button_content_set_icon_name(ADW_BUTTON_CONTENT(btnMenuAccountActionsContent), "document-properties-symbolic"); - adw_button_content_set_label(ADW_BUTTON_CONTENT(btnMenuAccountActionsContent), "Actions"); + adw_button_content_set_label(ADW_BUTTON_CONTENT(btnMenuAccountActionsContent), _("Actions")); gtk_menu_button_set_child(GTK_MENU_BUTTON(m_btnMenuAccountActions), btnMenuAccountActionsContent); GMenu* menuActions{ g_menu_new() }; - g_menu_append(menuActions, "Export as CSV", "account.exportAsCSV"); - g_menu_append(menuActions, "Import from CSV", "account.importFromCSV"); + g_menu_append(menuActions, _("Export as CSV"), "account.exportAsCSV"); + g_menu_append(menuActions, _("Import from CSV"), "account.importFromCSV"); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(m_btnMenuAccountActions), G_MENU_MODEL(menuActions)); g_object_unref(menuActions); //Overview Group @@ -51,7 +52,7 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_widget_set_margin_top(m_grpOverview, 10); gtk_widget_set_margin_end(m_grpOverview, 30); gtk_widget_set_margin_bottom(m_grpOverview, 10); - adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpOverview), "Overview"); + adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpOverview), _("Overview")); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpOverview), m_rowTotal); adw_preferences_group_set_header_suffix(ADW_PREFERENCES_GROUP(m_grpOverview), m_btnMenuAccountActions); gtk_box_append(GTK_BOX(m_boxMain), m_grpOverview); @@ -60,8 +61,8 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_style_context_add_class(gtk_widget_get_style_context(m_btnNewGroup), "flat"); GtkWidget* btnNewGroupContent{ adw_button_content_new() }; adw_button_content_set_icon_name(ADW_BUTTON_CONTENT(btnNewGroupContent), "list-add-symbolic"); - adw_button_content_set_label(ADW_BUTTON_CONTENT(btnNewGroupContent), "New"); - gtk_widget_set_tooltip_text(m_btnNewGroup, "New Group (Ctrl+G)"); + adw_button_content_set_label(ADW_BUTTON_CONTENT(btnNewGroupContent), _("New")); + gtk_widget_set_tooltip_text(m_btnNewGroup, _("New Group (Ctrl+G)")); gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(m_btnNewGroup), "account.newGroup"); gtk_button_set_child(GTK_BUTTON(m_btnNewGroup), btnNewGroupContent); //Groups Group @@ -70,7 +71,7 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_widget_set_margin_top(m_grpGroups, 10); gtk_widget_set_margin_end(m_grpGroups, 30); gtk_widget_set_margin_bottom(m_grpGroups, 10); - adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpGroups), "Groups"); + adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpGroups), _("Groups")); adw_preferences_group_set_header_suffix(ADW_PREFERENCES_GROUP(m_grpGroups), m_btnNewGroup); gtk_box_append(GTK_BOX(m_boxMain), m_grpGroups); //Button New Transaction @@ -78,8 +79,8 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_style_context_add_class(gtk_widget_get_style_context(m_btnNewTransaction), "flat"); GtkWidget* btnNewTransactionContent{ adw_button_content_new() }; adw_button_content_set_icon_name(ADW_BUTTON_CONTENT(btnNewTransactionContent), "list-add-symbolic"); - adw_button_content_set_label(ADW_BUTTON_CONTENT(btnNewTransactionContent), "New"); - gtk_widget_set_tooltip_text(m_btnNewTransaction, "New Transaction (Ctrl+Shift+N)"); + adw_button_content_set_label(ADW_BUTTON_CONTENT(btnNewTransactionContent), _("New")); + gtk_widget_set_tooltip_text(m_btnNewTransaction, _("New Transaction (Ctrl+Shift+N)")); gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(m_btnNewTransaction), "account.newTransaction"); gtk_button_set_child(GTK_BUTTON(m_btnNewTransaction), btnNewTransactionContent); //Transactions Group @@ -88,7 +89,7 @@ AccountView::AccountView(GtkWindow* parentWindow, AdwTabView* parentTabView, con gtk_widget_set_margin_top(m_grpTransactions, 10); gtk_widget_set_margin_end(m_grpTransactions, 30); gtk_widget_set_margin_bottom(m_grpTransactions, 10); - adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpTransactions), "Transactions"); + adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpTransactions), _("Transactions")); adw_preferences_group_set_header_suffix(ADW_PREFERENCES_GROUP(m_grpTransactions), m_btnNewTransaction); gtk_box_append(GTK_BOX(m_boxMain), m_grpTransactions); //Main Layout @@ -173,7 +174,7 @@ void AccountView::onAccountInfoChanged() void AccountView::onExportAsCSV() { - GtkFileChooserNative* saveFileDialog{ gtk_file_chooser_native_new("Export as CSV", m_parentWindow, GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", "_Cancel") }; + GtkFileChooserNative* saveFileDialog{ gtk_file_chooser_native_new(_("Export as CSV"), m_parentWindow, GTK_FILE_CHOOSER_ACTION_SAVE, _("_Save"), _("_Cancel")) }; gtk_native_dialog_set_modal(GTK_NATIVE_DIALOG(saveFileDialog), true); GtkFileFilter* filter{ gtk_file_filter_new() }; gtk_file_filter_set_name(filter, "CSV (*.csv)"); @@ -197,7 +198,7 @@ void AccountView::onExportAsCSV() void AccountView::onImportFromCSV() { - GtkFileChooserNative* openFileDialog{ gtk_file_chooser_native_new("Import from CSV", m_parentWindow, GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", "_Cancel") }; + GtkFileChooserNative* openFileDialog{ gtk_file_chooser_native_new(_("Import from CSV"), m_parentWindow, GTK_FILE_CHOOSER_ACTION_OPEN, _("_Open"), _("_Cancel")) }; gtk_native_dialog_set_modal(GTK_NATIVE_DIALOG(openFileDialog), true); GtkFileFilter* filter{ gtk_file_filter_new() }; gtk_file_filter_set_name(filter, "CSV (*.csv)"); @@ -241,7 +242,7 @@ void AccountView::onEditGroup(unsigned int id) void AccountView::onDeleteGroup(unsigned int id) { - MessageDialog messageDialog{ m_parentWindow, "Delete Group?", "Are you sure you want to delete this group?\nThis action is irreversible.", "No", "Yes" }; + MessageDialog messageDialog{ m_parentWindow, _("Delete Group?"), _("Are you sure you want to delete this group?\nThis action is irreversible."), _("No"), _("Yes") }; if(messageDialog.run() == MessageDialogResponse::Destructive) { m_controller.deleteGroup(id); @@ -270,7 +271,7 @@ void AccountView::onEditTransaction(unsigned int id) void AccountView::onDeleteTransaction(unsigned int id) { - MessageDialog messageDialog{ m_parentWindow, "Delete Transaction?", "Are you sure you want to delete this transaction?\nThis action is irreversible.", "No", "Yes" }; + MessageDialog messageDialog{ m_parentWindow, _("Delete Transaction?"), _("Are you sure you want to delete this transaction?\nThis action is irreversible."), _("No"), _("Yes") }; if(messageDialog.run() == MessageDialogResponse::Destructive) { m_controller.deleteTransaction(id); diff --git a/src/ui/views/groupdialog.cpp b/src/ui/views/groupdialog.cpp index 8da6d6c74..442458fa8 100644 --- a/src/ui/views/groupdialog.cpp +++ b/src/ui/views/groupdialog.cpp @@ -1,13 +1,14 @@ #include "groupdialog.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; using namespace NickvisionMoney::UI::Views; -GroupDialog::GroupDialog(GtkWindow* parent, NickvisionMoney::Controllers::GroupDialogController& controller) : m_controller{ controller }, m_gobj{ adw_message_dialog_new(parent, "Group", nullptr) } +GroupDialog::GroupDialog(GtkWindow* parent, NickvisionMoney::Controllers::GroupDialogController& controller) : m_controller{ controller }, m_gobj{ adw_message_dialog_new(parent, _("Group"), nullptr) } { //Dialog Settings gtk_window_set_hide_on_close(GTK_WINDOW(m_gobj), true); - adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", "Cancel", "ok", "OK", nullptr); + adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", _("Cancel"), "ok", _("OK"), nullptr); adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(m_gobj), "ok", ADW_RESPONSE_SUGGESTED); adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(m_gobj), "ok"); adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); @@ -17,13 +18,13 @@ GroupDialog::GroupDialog(GtkWindow* parent, NickvisionMoney::Controllers::GroupD //Name m_rowName = adw_entry_row_new(); gtk_widget_set_size_request(m_rowName, 420, -1); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), "Name"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), _("Name")); adw_entry_row_set_activates_default(ADW_ENTRY_ROW(m_rowName), true); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowName); //Description m_rowDescription = adw_entry_row_new(); gtk_widget_set_size_request(m_rowDescription, 420, -1); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), _("Description")); adw_entry_row_set_activates_default(ADW_ENTRY_ROW(m_rowDescription), true); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowDescription); //Layout @@ -55,19 +56,19 @@ bool GroupDialog::run() { //Reset UI gtk_style_context_remove_class(gtk_widget_get_style_context(m_rowName), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), "Name"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), _("Name")); gtk_style_context_remove_class(gtk_widget_get_style_context(m_rowDescription), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), _("Description")); //Mark Error if(status == GroupCheckStatus::EmptyName) { gtk_style_context_add_class(gtk_widget_get_style_context(m_rowName), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), "Name (Empty)"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowName), _("Name (Empty)")); } else if(status == GroupCheckStatus::EmptyDescription) { gtk_style_context_add_class(gtk_widget_get_style_context(m_rowDescription), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description (Empty)"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), _("Description (Empty)")); } return run(); } diff --git a/src/ui/views/mainwindow.cpp b/src/ui/views/mainwindow.cpp index d5ba06841..95d46fffa 100644 --- a/src/ui/views/mainwindow.cpp +++ b/src/ui/views/mainwindow.cpp @@ -2,6 +2,7 @@ #include #include "preferencesdialog.hpp" #include "shortcutsdialog.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; using namespace NickvisionMoney::UI::Views; @@ -21,23 +22,23 @@ MainWindow::MainWindow(GtkApplication* application, const MainWindowController& //Menu Account Button m_btnMenuAccount = gtk_menu_button_new(); GMenu* menuAccount{ g_menu_new() }; - g_menu_append(menuAccount, "New Account", "win.newAccount"); - g_menu_append(menuAccount, "Open Account", "win.openAccount"); - g_menu_append(menuAccount, "Close Account", "win.closeAccount"); + g_menu_append(menuAccount, _("New Account"), "win.newAccount"); + g_menu_append(menuAccount, _("Open Account"), "win.openAccount"); + g_menu_append(menuAccount, _("Close Account"), "win.closeAccount"); gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(m_btnMenuAccount), "bank-symbolic"); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(m_btnMenuAccount), G_MENU_MODEL(menuAccount)); - gtk_widget_set_tooltip_text(m_btnMenuAccount, "Account Menu"); + gtk_widget_set_tooltip_text(m_btnMenuAccount, _("Account Menu")); adw_header_bar_pack_start(ADW_HEADER_BAR(m_headerBar), m_btnMenuAccount); g_object_unref(menuAccount); //Menu Help Button m_btnMenuHelp = gtk_menu_button_new(); GMenu* menuHelp{ g_menu_new() }; - g_menu_append(menuHelp, "Preferences", "win.preferences"); - g_menu_append(menuHelp, "Keyboard Shortcuts", "win.keyboardShortcuts"); - g_menu_append(menuHelp, std::string("About " + m_controller.getAppInfo().getShortName()).c_str(), "win.about"); + g_menu_append(menuHelp, _("Preferences"), "win.preferences"); + g_menu_append(menuHelp, _("Keyboard Shortcuts"), "win.keyboardShortcuts"); + g_menu_append(menuHelp, std::string(_("About ") + m_controller.getAppInfo().getShortName()).c_str(), "win.about"); gtk_menu_button_set_direction(GTK_MENU_BUTTON(m_btnMenuHelp), GTK_ARROW_NONE); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(m_btnMenuHelp), G_MENU_MODEL(menuHelp)); - gtk_widget_set_tooltip_text(m_btnMenuHelp, "Main Menu"); + gtk_widget_set_tooltip_text(m_btnMenuHelp, _("Main Menu")); adw_header_bar_pack_end(ADW_HEADER_BAR(m_headerBar), m_btnMenuHelp); g_object_unref(menuHelp); //Toast Overlay @@ -52,7 +53,7 @@ MainWindow::MainWindow(GtkApplication* application, const MainWindowController& gtk_widget_set_size_request(m_btnNewAccount, 200, 50); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnNewAccount), "circular"); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnNewAccount), "suggested-action"); - gtk_button_set_label(GTK_BUTTON(m_btnNewAccount), "New Account"); + gtk_button_set_label(GTK_BUTTON(m_btnNewAccount), _("New Account")); gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(m_btnNewAccount), "win.newAccount"); gtk_box_append(GTK_BOX(m_boxStatusButtons), m_btnNewAccount); //Open Account Button @@ -60,14 +61,14 @@ MainWindow::MainWindow(GtkApplication* application, const MainWindowController& gtk_widget_set_halign(m_btnOpenAccount, GTK_ALIGN_CENTER); gtk_widget_set_size_request(m_btnOpenAccount, 200, 50); gtk_style_context_add_class(gtk_widget_get_style_context(m_btnOpenAccount), "circular"); - gtk_button_set_label(GTK_BUTTON(m_btnOpenAccount), "Open Account"); + gtk_button_set_label(GTK_BUTTON(m_btnOpenAccount), _("Open Account")); gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(m_btnOpenAccount), "win.openAccount"); gtk_box_append(GTK_BOX(m_boxStatusButtons), m_btnOpenAccount); //Page No Downloads m_pageStatusNoAccounts = adw_status_page_new(); adw_status_page_set_icon_name(ADW_STATUS_PAGE(m_pageStatusNoAccounts), "org.nickvision.money-symbolic"); - adw_status_page_set_title(ADW_STATUS_PAGE(m_pageStatusNoAccounts), "No Accounts Open"); - adw_status_page_set_description(ADW_STATUS_PAGE(m_pageStatusNoAccounts), "Open or create an account to get started."); + adw_status_page_set_title(ADW_STATUS_PAGE(m_pageStatusNoAccounts), _("No Accounts Open")); + adw_status_page_set_description(ADW_STATUS_PAGE(m_pageStatusNoAccounts), _("Open or create an account to get started.")); adw_status_page_set_child(ADW_STATUS_PAGE(m_pageStatusNoAccounts), m_boxStatusButtons); //Page Tabs m_pageTabs = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); @@ -151,7 +152,7 @@ void MainWindow::onAccountAdded() void MainWindow::onNewAccount() { - GtkFileChooserNative* saveFileDialog{ gtk_file_chooser_native_new("Open Account", GTK_WINDOW(m_gobj), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", "_Cancel") }; + GtkFileChooserNative* saveFileDialog{ gtk_file_chooser_native_new(_("Open Account"), GTK_WINDOW(m_gobj), GTK_FILE_CHOOSER_ACTION_SAVE, _("_Save"), _("_Cancel")) }; gtk_native_dialog_set_modal(GTK_NATIVE_DIALOG(saveFileDialog), true); GtkFileFilter* filter{ gtk_file_filter_new() }; gtk_file_filter_set_name(filter, "Money Account (*.nmoney)"); @@ -175,7 +176,7 @@ void MainWindow::onNewAccount() void MainWindow::onOpenAccount() { - GtkFileChooserNative* openFileDialog{ gtk_file_chooser_native_new("Open Account", GTK_WINDOW(m_gobj), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", "_Cancel") }; + GtkFileChooserNative* openFileDialog{ gtk_file_chooser_native_new(_("Open Account"), GTK_WINDOW(m_gobj), GTK_FILE_CHOOSER_ACTION_OPEN, _("_Open"), _("_Cancel")) }; gtk_native_dialog_set_modal(GTK_NATIVE_DIALOG(openFileDialog), true); GtkFileFilter* filter{ gtk_file_filter_new() }; gtk_file_filter_set_name(filter, "Money Account (*.nmoney)"); diff --git a/src/ui/views/preferencesdialog.cpp b/src/ui/views/preferencesdialog.cpp index c046f1ce3..8e2c0f35e 100644 --- a/src/ui/views/preferencesdialog.cpp +++ b/src/ui/views/preferencesdialog.cpp @@ -1,4 +1,5 @@ #include "preferencesdialog.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; using namespace NickvisionMoney::UI::Views; @@ -13,31 +14,31 @@ PreferencesDialog::PreferencesDialog(GtkWindow* parent, const PreferencesDialogC gtk_window_set_hide_on_close(GTK_WINDOW(m_gobj), true); //Header Bar m_headerBar = adw_header_bar_new(); - adw_header_bar_set_title_widget(ADW_HEADER_BAR(m_headerBar), adw_window_title_new("Preferences", nullptr)); + adw_header_bar_set_title_widget(ADW_HEADER_BAR(m_headerBar), adw_window_title_new(_("Preferences"), nullptr)); //User Interface Group m_grpUserInterface = adw_preferences_group_new(); - adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpUserInterface), "User Interface"); - adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(m_grpUserInterface), "Customize the application's user interface."); + adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpUserInterface), _("User Interface")); + adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(m_grpUserInterface), _("Customize the application's user interface.")); //Theme Row m_rowTheme = adw_combo_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowTheme), "Theme"); - adw_combo_row_set_model(ADW_COMBO_ROW(m_rowTheme), G_LIST_MODEL(gtk_string_list_new(new const char*[4]{ "System", "Light", "Dark", nullptr }))); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowTheme), _("Theme")); + adw_combo_row_set_model(ADW_COMBO_ROW(m_rowTheme), G_LIST_MODEL(gtk_string_list_new(new const char*[4]{ _("System"), _("Light"), _("Dark"), nullptr }))); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpUserInterface), m_rowTheme); g_signal_connect(m_rowTheme, "notify::selected-item", G_CALLBACK((void (*)(GObject*, GParamSpec*, gpointer))[](GObject*, GParamSpec*, gpointer data) { reinterpret_cast(data)->onThemeChanged(); }), this); //Currency Group m_grpCurrency = adw_preferences_group_new(); - adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpCurrency), "Currency"); - adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(m_grpCurrency), "Customize currency settings.\n\nA change in one of these settings will only be applied on newly opened accounts."); + adw_preferences_group_set_title(ADW_PREFERENCES_GROUP(m_grpCurrency), _("Currency")); + adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(m_grpCurrency), _("Customize currency settings.\n\nA change in one of these settings will only be applied on newly opened accounts.")); //Currency Symbol Row m_rowCurrencySymbol = adw_entry_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowCurrencySymbol), "Currency Symbol"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowCurrencySymbol), _("Currency Symbol")); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpCurrency), m_rowCurrencySymbol); //Display Currency Symbol On Right Row m_rowDisplayCurrencySymbolOnRight = adw_action_row_new(); m_switchDisplayCurrencySymbolOnRight = gtk_switch_new(); gtk_widget_set_valign(m_switchDisplayCurrencySymbolOnRight, GTK_ALIGN_CENTER); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDisplayCurrencySymbolOnRight), "Display Currency Symbol On Right"); - adw_action_row_set_subtitle(ADW_ACTION_ROW(m_rowDisplayCurrencySymbolOnRight), "If checked, the currency symbol will be displayed on the right of a monetary value."); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDisplayCurrencySymbolOnRight), _("Display Currency Symbol On Right")); + adw_action_row_set_subtitle(ADW_ACTION_ROW(m_rowDisplayCurrencySymbolOnRight), _("If checked, the currency symbol will be displayed on the right of a monetary value.")); adw_action_row_add_suffix(ADW_ACTION_ROW(m_rowDisplayCurrencySymbolOnRight), m_switchDisplayCurrencySymbolOnRight); adw_action_row_set_activatable_widget(ADW_ACTION_ROW(m_rowDisplayCurrencySymbolOnRight), m_switchDisplayCurrencySymbolOnRight); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_grpCurrency), m_rowDisplayCurrencySymbolOnRight); diff --git a/src/ui/views/shortcutsdialog.cpp b/src/ui/views/shortcutsdialog.cpp index 092e622c9..56a7a4d0e 100644 --- a/src/ui/views/shortcutsdialog.cpp +++ b/src/ui/views/shortcutsdialog.cpp @@ -1,10 +1,13 @@ #include "shortcutsdialog.hpp" +#include "../../helpers/stringhelpers.hpp" +#include "../../helpers/translation.hpp" +using namespace NickvisionMoney::Helpers; using namespace NickvisionMoney::UI::Views; ShortcutsDialog::ShortcutsDialog(GtkWindow* parent) { - m_xml = R"( + m_xml = StringHelpers::format(R"( @@ -18,22 +21,22 @@ ShortcutsDialog::ShortcutsDialog(GtkWindow* parent) - Account + %s - New Account + %s <Control>N - Open Account + %s <Control>O - Close Account + %s <Control>W @@ -41,10 +44,10 @@ ShortcutsDialog::ShortcutsDialog(GtkWindow* parent) - Group + %s - New Group + %s <Control>G @@ -52,10 +55,10 @@ ShortcutsDialog::ShortcutsDialog(GtkWindow* parent) - Transaction + %s - New Transaction + %s <Control><Shift>N @@ -63,22 +66,22 @@ ShortcutsDialog::ShortcutsDialog(GtkWindow* parent) - Application + %s - Preferences + %s <Control>comma - Keyboard Shortcuts + %s <Control>question - About + %s F1 @@ -88,7 +91,20 @@ ShortcutsDialog::ShortcutsDialog(GtkWindow* parent) - )"; + )", + _("Account"), + _("New Account"), + _("Open Account"), + _("Close Account"), + _("Group"), + _("New Group"), + _("Transaction"), + _("New Transaction"), + _("Application"), + _("Preferences"), + _("Keyboard Shortcuts"), + _("About") + ); GtkBuilder* builder{ gtk_builder_new_from_string(m_xml.c_str(), -1) }; m_gobj = GTK_WIDGET(gtk_builder_get_object(builder, "m_dialog")); gtk_window_set_transient_for(GTK_WINDOW(m_gobj), GTK_WINDOW(parent)); diff --git a/src/ui/views/transactiondialog.cpp b/src/ui/views/transactiondialog.cpp index 155e6e3bd..aca5107d3 100644 --- a/src/ui/views/transactiondialog.cpp +++ b/src/ui/views/transactiondialog.cpp @@ -1,13 +1,16 @@ #include "transactiondialog.hpp" +#include "../../helpers/stringhelpers.hpp" +#include "../../helpers/translation.hpp" using namespace NickvisionMoney::Controllers; +using namespace NickvisionMoney::Helpers; using namespace NickvisionMoney::UI::Views; -TransactionDialog::TransactionDialog(GtkWindow* parent, NickvisionMoney::Controllers::TransactionDialogController& controller) : m_controller{ controller }, m_gobj{ adw_message_dialog_new(parent, "Transaction", nullptr) } +TransactionDialog::TransactionDialog(GtkWindow* parent, NickvisionMoney::Controllers::TransactionDialogController& controller) : m_controller{ controller }, m_gobj{ adw_message_dialog_new(parent, _("Transaction"), nullptr) } { //Dialog Settings gtk_window_set_hide_on_close(GTK_WINDOW(m_gobj), true); - adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", "Cancel", "ok", "OK", nullptr); + adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(m_gobj), "cancel", _("Cancel"), "ok", _("OK"), nullptr); adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(m_gobj), "ok", ADW_RESPONSE_SUGGESTED); adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(m_gobj), "ok"); adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(m_gobj), "cancel"); @@ -17,7 +20,7 @@ TransactionDialog::TransactionDialog(GtkWindow* parent, NickvisionMoney::Control //Id m_rowId = adw_entry_row_new(); gtk_widget_set_size_request(m_rowId, 420, -1); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowId), "ID"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowId), _("ID")); gtk_editable_set_editable(GTK_EDITABLE(m_rowId), false); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowId); //Date @@ -32,29 +35,29 @@ TransactionDialog::TransactionDialog(GtkWindow* parent, NickvisionMoney::Control gtk_menu_button_set_label(GTK_MENU_BUTTON(m_btnDate), g_date_time_format(gtk_calendar_get_date(GTK_CALENDAR(m_calendarDate)), "%Y-%m-%d")); m_rowDate = adw_action_row_new(); gtk_widget_set_size_request(m_rowDate, 420, -1); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDate), "Date"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDate), _("Date")); adw_action_row_add_suffix(ADW_ACTION_ROW(m_rowDate), m_btnDate); adw_action_row_set_activatable_widget(ADW_ACTION_ROW(m_rowDate), m_btnDate); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowDate); //Description m_rowDescription = adw_entry_row_new(); gtk_widget_set_size_request(m_rowDescription, 420, -1); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), _("Description")); adw_entry_row_set_activates_default(ADW_ENTRY_ROW(m_rowDescription), true); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowDescription); //Type m_rowType = adw_combo_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowType), "Type"); - adw_combo_row_set_model(ADW_COMBO_ROW(m_rowType), G_LIST_MODEL(gtk_string_list_new(new const char*[3]{ "Income", "Expense", nullptr }))); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowType), _("Type")); + adw_combo_row_set_model(ADW_COMBO_ROW(m_rowType), G_LIST_MODEL(gtk_string_list_new(new const char*[3]{ _("Income"), _("Expense"), nullptr }))); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowType); //Repeat Interval m_rowRepeatInterval = adw_combo_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowRepeatInterval), "Repeat Interval"); - adw_combo_row_set_model(ADW_COMBO_ROW(m_rowRepeatInterval), G_LIST_MODEL(gtk_string_list_new(new const char*[8]{ "Never", "Daily", "Weekly", "Monthly", "Quarterly", "Yearly", "Biyearly", nullptr }))); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowRepeatInterval), _("Repeat Interval")); + adw_combo_row_set_model(ADW_COMBO_ROW(m_rowRepeatInterval), G_LIST_MODEL(gtk_string_list_new(new const char*[8]{ _("Never"), _("Daily"), _("Weekly"), _("Monthly"), _("Quarterly"), _("Yearly"), _("Biyearly"), nullptr }))); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowRepeatInterval); //Group m_rowGroup = adw_combo_row_new(); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowGroup), "Group"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowGroup), _("Group")); const char** groupNames{ new const char*[m_controller.getGroupNames().size() + 1] }; for(size_t i = 0; i < m_controller.getGroupNames().size(); i++) { @@ -66,7 +69,7 @@ TransactionDialog::TransactionDialog(GtkWindow* parent, NickvisionMoney::Control //Amount m_rowAmount = adw_entry_row_new(); gtk_widget_set_size_request(m_rowAmount, 420, -1); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), std::string("Amount (" + m_controller.getCurrencySymbol() + ")").c_str()); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), StringHelpers::format(_("Amount (%s)"), m_controller.getCurrencySymbol().c_str()).c_str()); adw_entry_row_set_activates_default(ADW_ENTRY_ROW(m_rowAmount), true); adw_preferences_group_add(ADW_PREFERENCES_GROUP(m_preferencesGroup), m_rowAmount); //Layout @@ -103,24 +106,24 @@ bool TransactionDialog::run() { //Reset UI gtk_style_context_remove_class(gtk_widget_get_style_context(m_rowDescription), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), _("Description")); gtk_style_context_remove_class(gtk_widget_get_style_context(m_rowAmount), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), std::string("Amount (" + m_controller.getCurrencySymbol() + ")").c_str()); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), StringHelpers::format(_("Amount (%s)"), m_controller.getCurrencySymbol().c_str()).c_str()); //Mark Error if(status == TransactionCheckStatus::EmptyDescription) { gtk_style_context_add_class(gtk_widget_get_style_context(m_rowDescription), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), "Description (Empty)"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowDescription), _("Description (Empty)")); } else if(status == TransactionCheckStatus::EmptyAmount) { gtk_style_context_add_class(gtk_widget_get_style_context(m_rowAmount), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), "Amount (Empty)"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), _("Amount (Empty)")); } else if(status == TransactionCheckStatus::InvalidAmount) { gtk_style_context_add_class(gtk_widget_get_style_context(m_rowAmount), "error"); - adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), "Amount (Invalid)"); + adw_preferences_row_set_title(ADW_PREFERENCES_ROW(m_rowAmount), _("Amount (Invalid)")); } return run(); }