diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-04 15:54:30 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-04 15:54:30 +0200 |
| commit | 2855642dd16cea260f3b32351f0529328a0bcb15 (patch) | |
| tree | a375d2c57e1089ba54746371674e48c9216bb8e4 /src | |
| parent | b8e049f02a16dc8398b2a954b561c84beda423c7 (diff) | |
namespacing locale, config, file_templates
Diffstat (limited to 'src')
| -rw-r--r-- | src/administration.cpp | 4 | ||||
| -rw-r--r-- | src/administration_reader.cpp | 6 | ||||
| -rw-r--r-- | src/administration_writer.cpp | 26 | ||||
| -rw-r--r-- | src/ai_providers/DeepSeek.cpp | 6 | ||||
| -rw-r--r-- | src/ai_providers/openAI.cpp | 2 | ||||
| -rw-r--r-- | src/config.cpp | 24 | ||||
| -rw-r--r-- | src/importer.cpp (renamed from src/import_service.cpp) | 26 | ||||
| -rw-r--r-- | src/locales.cpp | 52 | ||||
| -rw-r--r-- | src/locales/en.cpp | 4 | ||||
| -rw-r--r-- | src/ui/imgui_extensions.cpp | 46 | ||||
| -rw-r--r-- | src/ui/ui_contacts.cpp | 58 | ||||
| -rw-r--r-- | src/ui/ui_earnings.cpp | 22 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 74 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 86 | ||||
| -rw-r--r-- | src/ui/ui_main.cpp | 22 | ||||
| -rw-r--r-- | src/ui/ui_projects.cpp | 34 | ||||
| -rw-r--r-- | src/ui/ui_settings.cpp | 50 |
17 files changed, 261 insertions, 281 deletions
diff --git a/src/administration.cpp b/src/administration.cpp index a07e79a..4f996bf 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -337,7 +337,7 @@ void administration_create_from_file(char* save_file) administration_create(); strops_copy(g_administration.path, save_file, sizeof(g_administration.path)); - strops_copy(g_administration.program_version, PROGRAM_VERSION, sizeof(g_administration.program_version)); + strops_copy(g_administration.program_version, config::PROGRAM_VERSION, sizeof(g_administration.program_version)); } void administration_create_empty(char* save_file) @@ -349,7 +349,7 @@ void administration_create_empty(char* save_file) g_administration.next_sequence_number = 1; strops_copy(g_administration.path, save_file, sizeof(g_administration.path)); - strops_copy(g_administration.program_version, PROGRAM_VERSION, sizeof(g_administration.program_version)); + strops_copy(g_administration.program_version, config::PROGRAM_VERSION, sizeof(g_administration.program_version)); administration_company_info_set(administration_contact_create_empty()); } diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp index e845e7c..801941b 100644 --- a/src/administration_reader.cpp +++ b/src/administration_reader.cpp @@ -30,7 +30,7 @@ bool administration_reader_open_new() { - // @localize + // @locale::get char const * lFilterPatterns[1] = { "*.openbook" }; char* save_path = tinyfd_saveFileDialog("Select destination", NULL, 1, lFilterPatterns, NULL); @@ -43,7 +43,7 @@ bool administration_reader_open_new() bool administration_reader_save_new() { - // @localize + // @locale::get char const * lFilterPatterns[1] = { "*.openbook" }; char* save_path = tinyfd_saveFileDialog("Select destination", NULL, 1, lFilterPatterns, NULL); @@ -58,7 +58,7 @@ bool administration_reader_save_new() bool administration_reader_open_existing(char* file_path) { if (file_path == NULL) { - // @localize + // @locale::get char const * lFilterPatterns[1] = { "*.openbook" }; file_path = tinyfd_openFileDialog("Select save file", NULL, 1, lFilterPatterns, NULL, 0); diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp index 0ac0b40..6f58a21 100644 --- a/src/administration_writer.cpp +++ b/src/administration_writer.cpp @@ -35,10 +35,10 @@ mtx_t _save_file_mutex; static void on_administration_data_changed() { if (administration_writer_save_all_administration_info_blocking()) { - ui_set_status(localize("status.saved")); + ui_set_status(locale::get("status.saved")); } else { - ui_set_status(localize("status.saveFailed")); + ui_set_status(locale::get("status.saveFailed")); } } @@ -337,7 +337,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) int buf_length = 150000; // Ballpark file content size. char* file_content = (char*)malloc(buf_length); memset(file_content, 0, buf_length); - memcpy(file_content, peppol_invoice_template, strlen(peppol_invoice_template)); + memcpy(file_content, file_template::peppol_invoice_template, strlen(file_template::peppol_invoice_template)); struct tm *tm_info = 0; char date_buffer[11]; // "YYYY-MM-DD" + null terminator @@ -412,7 +412,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) tax_rate* tax_rate_buffer = (tax_rate*)malloc(sizeof(tax_rate)*administration_billing_item_count(&inv)); u32 tax_rate_count = administration_invoice_get_tax_rates(&inv, tax_rate_buffer); - u32 tax_subtotal_list_buffer_size = (u32)strlen(peppol_invoice_tax_subtotal_template) * 2 * tax_rate_count; // Ballpark list size. + u32 tax_subtotal_list_buffer_size = (u32)strlen(file_template::peppol_invoice_tax_subtotal_template) * 2 * tax_rate_count; // Ballpark list size. char* tax_subtotal_list_buffer = (char*)malloc(tax_subtotal_list_buffer_size); memset(tax_subtotal_list_buffer, 0, tax_subtotal_list_buffer_size); u32 tax_subtotal_list_buffer_cursor = 0; @@ -420,7 +420,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) for (u32 i = 0; i < tax_rate_count; i++) { int tax_entry_buf_length = 0; - char* tax_entry_file_content = administration_writer_copy_template(peppol_invoice_tax_subtotal_template, &tax_entry_buf_length); + char* tax_entry_file_content = administration_writer_copy_template(file_template::peppol_invoice_tax_subtotal_template, &tax_entry_buf_length); tax_subtotal subtotal; administration_invoice_get_subtotal_for_tax_rate(&inv, tax_rate_buffer[i], &subtotal); @@ -455,7 +455,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) billing_item* billing_item_buffer = (billing_item*)malloc(sizeof(billing_item) * administration_billing_item_count(&inv)); u32 billing_item_count = administration_billing_item_get_all_for_invoice(&inv, billing_item_buffer); - u32 billing_item_list_buffer_size = (u32)strlen(peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size. + u32 billing_item_list_buffer_size = (u32)strlen(file_template::peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size. char* billing_item_list_buffer = (char*)malloc(billing_item_list_buffer_size); memset(billing_item_list_buffer, 0, billing_item_list_buffer_size); u32 billing_item_list_buffer_cursor = 0; @@ -463,7 +463,7 @@ bool administration_writer_save_invoice_blocking(invoice inv) for (u32 i = 0; i < billing_item_count; i++) { int billing_item_buf_length = 0; - char* billing_item_file_content = administration_writer_copy_template(peppol_invoice_line_template, &billing_item_buf_length); + char* billing_item_file_content = administration_writer_copy_template(file_template::peppol_invoice_line_template, &billing_item_buf_length); billing_item bi = billing_item_buffer[i]; tax_rate rate; @@ -557,7 +557,7 @@ bool administration_writer_save_project_blocking(project project) bool result = 1; int buf_length = 0; - char* file_content = administration_writer_copy_template(project_save_template, &buf_length); + char* file_content = administration_writer_copy_template(file_template::project_save_template, &buf_length); struct tm *tm_info = 0; char date_buffer[11]; // "YYYY-MM-DD" + null terminator @@ -616,7 +616,7 @@ bool administration_writer_save_cost_center_blocking(cost_center cost) bool result = 1; int buf_length = 0; - char* file_content = administration_writer_copy_template(costcenter_save_template, &buf_length); + char* file_content = administration_writer_copy_template(file_template::costcenter_save_template, &buf_length); strops_replace(file_content, buf_length, "{{COSTCENTER_ID}}", cost.id); strops_replace(file_content, buf_length, "{{COSTCENTER_CODE}}", cost.code); @@ -664,7 +664,7 @@ bool administration_writer_save_tax_rate_blocking(tax_rate rate) bool result = 1; int buf_length = 0; - char* file_content = administration_writer_copy_template(taxrate_save_template, &buf_length); + char* file_content = administration_writer_copy_template(file_template::taxrate_save_template, &buf_length); strops_replace(file_content, buf_length, "{{TAXBRACKET_ID}}", rate.id); strops_replace(file_content, buf_length, "{{TAXBRACKET_COUNTRY}}", rate.country_code); @@ -715,7 +715,7 @@ bool administration_writer_save_contact_blocking(contact c) bool result = 1; int buf_length = 0; - char* file_content = administration_writer_copy_template(contact_save_template, &buf_length); + char* file_content = administration_writer_copy_template(file_template::contact_save_template, &buf_length); strops_replace(file_content, buf_length, "{{CONTACT_ID}}", c.id); strops_replace(file_content, buf_length, "{{CONTACT_NAME}}", c.name); @@ -779,11 +779,11 @@ bool administration_writer_save_all_administration_info_blocking() bool result = 1; int buf_length = 0; - char* file_content = administration_writer_copy_template(administration_save_template, &buf_length); + char* file_content = administration_writer_copy_template(file_template::administration_save_template, &buf_length); strops_replace_int32(file_content, buf_length, "{{NEXT_ID}}", administration_get_next_id()); strops_replace_int32(file_content, buf_length, "{{NEXT_SEQUENCE_NUMBER}}", administration_get_next_sequence_number()); - strops_replace(file_content, buf_length, "{{PROGRAM_VERSION}}", PROGRAM_VERSION); + strops_replace(file_content, buf_length, "{{PROGRAM_VERSION}}", config::PROGRAM_VERSION); ai_service ai_service = administration_get_ai_service(); strops_replace_int32(file_content, buf_length, "{{AI_SERVICE_PROVIDER}}", (s32)ai_service.provider); diff --git a/src/ai_providers/DeepSeek.cpp b/src/ai_providers/DeepSeek.cpp index 67d17c2..334f024 100644 --- a/src/ai_providers/DeepSeek.cpp +++ b/src/ai_providers/DeepSeek.cpp @@ -24,13 +24,15 @@ #include "httplib.h" #include "strops.hpp" #include "log.hpp" -#include "import_service.hpp" +#include "importer.hpp" #define QUERY_BUFFER_SIZE 1000000 char* query_buffer = 0; static bool _DeepSeek_query_with_file(char* query, size_t query_length, char* file_id, char** response) { + (void)file_id; + (void)query_length; assert(query_buffer); const char *api_key = administration_get_ai_service().api_key_public; @@ -78,6 +80,8 @@ static bool _DeepSeek_query_with_file(char* query, size_t query_length, char* fi static bool _DeepSeek_upload_file(char* file_path, char* file_id, size_t file_id_len) { + (void)file_id; + (void)file_id_len; const char *filename = strops_get_filename(file_path); FILE* orig_file = fopen(file_path, "r"); diff --git a/src/ai_providers/openAI.cpp b/src/ai_providers/openAI.cpp index 20c1fa4..415d8ce 100644 --- a/src/ai_providers/openAI.cpp +++ b/src/ai_providers/openAI.cpp @@ -24,7 +24,7 @@ #include "httplib.h" #include "strops.hpp" #include "log.hpp" -#include "import_service.hpp" +#include "importer.hpp" static bool _openAI_query_with_file(char* query, size_t query_length, char* file_id, char** response) { diff --git a/src/config.cpp b/src/config.cpp deleted file mode 100644 index 9ab8e90..0000000 --- a/src/config.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com> -* -* Permission to use, copy, modify, and/or distribute this software for any -* purpose with or without fee is hereby granted, provided that the above -* copyright notice and this permission notice appear in all copies. -* -* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "config.hpp" - -const char* country_codes[] = { - // "AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", - /*"DE", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT",*/ "NL", - // "PL", "PT", "RO", "SK", "SI", "ES", "SE" -}; -s32 country_count = sizeof(country_codes) / sizeof(country_codes[0]);
\ No newline at end of file diff --git a/src/import_service.cpp b/src/importer.cpp index cff7fdb..404ee8c 100644 --- a/src/import_service.cpp +++ b/src/importer.cpp @@ -24,10 +24,11 @@ #define CPPHTTPLIB_OPENSSL_SUPPORT #include "httplib.h" #include "log.hpp" -#include "import_service.hpp" +#include "importer.hpp" #include "strops.hpp" #include "administration_reader.hpp" #include "locales.hpp" +#include "file_templates.hpp" ai_provider_impl _ai_get_impl() { @@ -43,9 +44,6 @@ ai_provider_impl _ai_get_impl() return ai_provider_impl {0}; } -extern const char* peppol_invoice_template; -extern const char* peppol_invoice_line_template; - static int _ai_document_to_invoice_t(void *arg) { import_invoice_request* request = (import_invoice_request*)arg; char* file_path = request->file_path; @@ -66,8 +64,8 @@ static int _ai_document_to_invoice_t(void *arg) { char* template_buffer = (char*)malloc(query_buffer_len); memset(template_buffer, 0, query_buffer_len); - strncpy(template_buffer, peppol_invoice_template, query_buffer_len); - strops_replace(template_buffer, 50000, "{{INVOICE_LINE_LIST}}", peppol_invoice_line_template); + strncpy(template_buffer, file_template::peppol_invoice_template, query_buffer_len); + strops_replace(template_buffer, 50000, "{{INVOICE_LINE_LIST}}", file_template::peppol_invoice_line_template); char* ai_query = "\n\nI have provided a file containing an invoice. Fill in the above Peppol 3.0 template with the information from the invoice.\n" @@ -169,11 +167,11 @@ const char* import_status_to_str(import_status status) { switch(status) { - case import_status::IMPORT_STARTING: return localize("import.status.starting"); - case import_status::IMPORT_UPLOADING_FILE: return localize("import.status.uploading_file"); - case import_status::IMPORT_QUERYING: return localize("import.status.querying"); - case import_status::IMPORT_WAITING_FOR_RESPONSE: return localize("import.status.waiting_for_result"); - case import_status::IMPORT_DONE: return localize("import.status.done"); + case import_status::IMPORT_STARTING: return locale::get("import.status.starting"); + case import_status::IMPORT_UPLOADING_FILE: return locale::get("import.status.uploading_file"); + case import_status::IMPORT_QUERYING: return locale::get("import.status.querying"); + case import_status::IMPORT_WAITING_FOR_RESPONSE: return locale::get("import.status.waiting_for_result"); + case import_status::IMPORT_DONE: return locale::get("import.status.done"); } return ""; } @@ -182,9 +180,9 @@ const char* import_error_to_str(i_err error) { switch(error) { - case I_ERR_FAILED_UPLOAD: return localize("import.error.upload"); - case I_ERR_FAILED_QUERY: return localize("import.error.query"); - case I_ERR_FAILED_IMPORT: return localize("import.error.import"); + case I_ERR_FAILED_UPLOAD: return locale::get("import.error.upload"); + case I_ERR_FAILED_QUERY: return locale::get("import.error.query"); + case I_ERR_FAILED_IMPORT: return locale::get("import.error.import"); } return ""; }
\ No newline at end of file diff --git a/src/locales.cpp b/src/locales.cpp index 62bf6fb..ef2ff6a 100644 --- a/src/locales.cpp +++ b/src/locales.cpp @@ -19,35 +19,37 @@ #include "locales.hpp" -locale_map locales[] = { - {"en", en_locales, en_locale_count}, - // Add new locales here. -}; - -const int locale_map_count = sizeof(locales) / sizeof(locales[0]); - -locale_map g_locale = locales[0]; // Default to english. - -const char* get_locale() -{ - return g_locale.lang_code; -} +namespace locale { + static locale_map locales[] = { + {"en", locale::en_locales, locale::en_locale_count}, + // Add new locales here. + }; + + static const int locale_map_count = sizeof(locales) / sizeof(locales[0]); + static locale_map g_locale = locales[0]; // Default to english. + + const char* locale::get_locale() + { + return g_locale.lang_code; + } -void set_locale(const char* key) -{ - for (int i = 0; i < locale_map_count; ++i) { - if (strcmp(locales[i].lang_code, key) == 0) { - g_locale = locales[i]; + void locale::set_locale(const char* key) + { + for (int i = 0; i < locale_map_count; ++i) { + if (strcmp(locales[i].lang_code, key) == 0) { + g_locale = locales[i]; + } } } -} -const char* localize(const char* key) -{ - for (int i = 0; i < g_locale.entry_count; ++i) { - if (strcmp(g_locale.entries[i].key, key) == 0) { - return g_locale.entries[i].value; + const char* locale::get(const char* key) + { + for (int i = 0; i < g_locale.entry_count; ++i) { + if (strcmp(g_locale.entries[i].key, key) == 0) { + return g_locale.entries[i].value; + } } + return key; } - return key; + }
\ No newline at end of file diff --git a/src/locales/en.cpp b/src/locales/en.cpp index d311b36..9410663 100644 --- a/src/locales/en.cpp +++ b/src/locales/en.cpp @@ -16,7 +16,7 @@ #include "locales.hpp" -locale_entry en_locales[] = { +locale::locale_entry locale::en_locales[] = { // General UI strings. {"ui.unsavedProject", "[unsaved project]"}, {"ui.workingOn", "Working on"}, @@ -209,4 +209,4 @@ locale_entry en_locales[] = { {"import.error.import","Failure: Failed to import result from service"}, }; -const int en_locale_count = sizeof(en_locales) / sizeof(en_locales[0]);
\ No newline at end of file +const int locale::en_locale_count = sizeof(locale::en_locales) / sizeof(locale::en_locales[0]);
\ No newline at end of file diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 4a0117b..8c8f4c4 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -13,7 +13,7 @@ namespace ImGui void InputTextWithError(const char* text, char* buffer, size_t buf_size, bool has_error) { if (has_error) { - ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); + ImGui::PushStyleColor(ImGuiCol_Border, config::colors::COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } ImGui::InputText(text, buffer, buf_size); @@ -29,7 +29,7 @@ namespace ImGui ImGui::SetNextItemWidth(widthAvailable*0.5f); if (has_error) { - ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); + ImGui::PushStyleColor(ImGuiCol_Border, config::colors::COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } ImGui::InputTextWithHint(hint, hint, buffer, buf_size); @@ -53,7 +53,7 @@ namespace ImGui { const char *filterPatterns[] = { "*.pdf" }; const char *file = tinyfd_openFileDialog( - "Choose a file", // dialog title // @localize + "Choose a file", // dialog title // @locale::get NULL, // default path 1, // number of filter patterns filterPatterns, // filter patterns array @@ -76,7 +76,7 @@ namespace ImGui result = true; } ImGui::SameLine(); - ImGui::TextWrapped("Selected: %s", buffer); // @localize + ImGui::TextWrapped("Selected: %s", buffer); // @locale::get } @@ -90,16 +90,16 @@ namespace ImGui ImGui::SetNextItemWidth(widthAvailable*0.5f); const char* countries[30]; - for (int x = 0; x < country_count; x++) + for (int x = 0; x < config::country_count; x++) { char locale_str[20]; - snprintf(locale_str, 20, "country.%s", country_codes[x]); - countries[x] = localize(locale_str); + snprintf(locale_str, 20, "country.%s", config::country_codes[x]); + countries[x] = locale::get(locale_str); } - for (int i = 0; i < country_count; i++) + for (int i = 0; i < config::country_count; i++) { - if (strcmp(country_codes[i], buffer) == 0) + if (strcmp(config::country_codes[i], buffer) == 0) { selected_country = countries[i]; break; @@ -109,13 +109,13 @@ namespace ImGui int selected_country_index = -1; if (!has_a_selection) { - ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); + ImGui::PushStyleColor(ImGuiCol_Border, config::colors::COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } - if (ImGui::BeginCombo(localize("contact.form.country"), selected_country)) + if (ImGui::BeginCombo(locale::get("contact.form.country"), selected_country)) { - for (int n = 0; n < country_count; n++) + for (int n = 0; n < config::country_count; n++) { bool is_selected = (selected_country == countries[n]); if (ImGui::Selectable(countries[n], is_selected)) { @@ -136,7 +136,7 @@ namespace ImGui } if (selected_country_index != -1) { - strops_copy(buffer, country_codes[selected_country_index], buf_size); + strops_copy(buffer, config::country_codes[selected_country_index], buf_size); } } @@ -144,9 +144,9 @@ namespace ImGui { float widthAvailable = ImGui::GetContentRegionAvail().x; ImGui::SetNextItemWidth(widthAvailable*0.5f); - const char* customer_types[2] = { localize("contact.form.type.business"), localize("contact.form.type.consumer") }; + const char* customer_types[2] = { locale::get("contact.form.type.business"), locale::get("contact.form.type.consumer") }; int currentItem = static_cast<int>(*type); - if (ImGui::Combo(localize("contact.form.type"), ¤tItem, customer_types, IM_ARRAYSIZE(customer_types))) + if (ImGui::Combo(locale::get("contact.form.type"), ¤tItem, customer_types, IM_ARRAYSIZE(customer_types))) { *type = static_cast<contact_type>(currentItem); } @@ -159,7 +159,7 @@ namespace ImGui static bool is_open = false; if (has_error) { - ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); + ImGui::PushStyleColor(ImGuiCol_Border, config::colors::COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } ImGui::InputTextWithHint(hint, hint, buffer, buf_size); @@ -230,7 +230,7 @@ namespace ImGui snprintf(autocomplete_strings[i], 200, "%s (%s %s)", autocomplete_list[i].name, autocomplete_list[i].address.address1, autocomplete_list[i].address.address2); } - int autocomplete_index = ImGui::TextInputWithAutocomplete(localize("contact.form.fullname"), + int autocomplete_index = ImGui::TextInputWithAutocomplete(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), (char**)autocomplete_strings, autocomplete_count, has_error); if (autocomplete_index != -1) @@ -266,12 +266,12 @@ namespace ImGui } int selected_costcenter_index = -1; - if (ImGui::BeginCombo(localize("invoice.form.costcenter"), selected_costcenter == NULL ? NULL : localize(selected_costcenter->description))) + if (ImGui::BeginCombo(locale::get("invoice.form.costcenter"), selected_costcenter == NULL ? NULL : locale::get(selected_costcenter->description))) { for (u32 n = 0; n < costcenter_count; n++) { bool is_selected = selected_costcenter && strcmp(selected_costcenter->id, buffer[n].id) == 0; - if (ImGui::Selectable(localize(buffer[n].description), is_selected)) { + if (ImGui::Selectable(locale::get(buffer[n].description), is_selected)) { selected_costcenter_index = n; } } @@ -307,7 +307,7 @@ namespace ImGui } int selected_project_index = -1; - if (ImGui::BeginCombo(localize("invoice.form.project"), selected_project == NULL ? NULL : selected_project->description)) + if (ImGui::BeginCombo(locale::get("invoice.form.project"), selected_project == NULL ? NULL : selected_project->description)) { for (u32 n = 0; n < project_count; n++) { @@ -356,13 +356,13 @@ namespace ImGui if (strcmp(selected_tax_rate->country_code, "00") == 0) { char category_code_desc[MAX_LEN_LONG_DESC]; snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", selected_tax_rate->category_code); - snprintf(rate_str_buf, 40, "%s", localize(category_code_desc)); + snprintf(rate_str_buf, 40, "%s", locale::get(category_code_desc)); } else snprintf(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate); } if (has_error) { - ImGui::PushStyleColor(ImGuiCol_Border, COLOR_ERROR_OUTLINE); + ImGui::PushStyleColor(ImGuiCol_Border, config::colors::COLOR_ERROR_OUTLINE); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.5f); } @@ -375,7 +375,7 @@ namespace ImGui if (strcmp(buffer[n].country_code, "00") == 0) { char category_code_desc[MAX_LEN_LONG_DESC]; snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", buffer[n].category_code); - snprintf(rate_str_buf, 40, "%s", localize(category_code_desc)); + snprintf(rate_str_buf, 40, "%s", locale::get(category_code_desc)); } else snprintf(rate_str_buf, 40, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate); diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index ffed39a..e282374 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -32,11 +32,11 @@ static contact active_contact; void ui_draw_address_form(address* buffer, a_err last_err) { - ImGui::FormInputTextWithErrorHint(localize("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); - ImGui::FormInputTextWithErrorHint(localize("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); - ImGui::FormInputTextWithErrorHint(localize("contact.form.city"), buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); - ImGui::FormInputTextWithErrorHint(localize("contact.form.postal"), buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); - ImGui::FormInputTextWithErrorHint(localize("contact.form.region"), buffer->region, IM_ARRAYSIZE(buffer->region), 0); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.address1"), buffer->address1, IM_ARRAYSIZE(buffer->address1), last_err & A_ERR_MISSING_ADDRESS1); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.address2"), buffer->address2, IM_ARRAYSIZE(buffer->address2), 0); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.city"), buffer->city, IM_ARRAYSIZE(buffer->city), last_err & A_ERR_MISSING_CITY); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.postal"), buffer->postal, IM_ARRAYSIZE(buffer->postal), last_err & A_ERR_MISSING_POSTAL); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.region"), buffer->region, IM_ARRAYSIZE(buffer->region), 0); ImGui::FormCountryCombo(buffer->country_code, IM_ARRAYSIZE(buffer->country_code)); } @@ -59,7 +59,7 @@ void draw_addressee_form_ex(delivery_info* buffer, bool viewing_only = false) if (!viewing_only) ImGui::EndDisabled(); - ImGui::FormInputTextWithErrorHint(localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); ui_draw_address_form(&buffer->address, last_err); @@ -79,7 +79,7 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ if (!viewing_only) ImGui::EndDisabled(); if (with_autocomplete) ImGui::FormContactAutocomplete(buffer, last_err & A_ERR_MISSING_NAME); - else ImGui::FormInputTextWithErrorHint(localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); + else ImGui::FormInputTextWithErrorHint(locale::get("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name), last_err & A_ERR_MISSING_NAME); ui_draw_address_form(&buffer->address, last_err); @@ -88,13 +88,13 @@ void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_ // Fields only required for businesses. if (buffer->type == contact_type::CONTACT_BUSINESS) { - ImGui::FormInputTextWithErrorHint(localize("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); - ImGui::FormInputTextWithErrorHint(localize("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid), last_err & A_ERR_MISSING_TAXID); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid), last_err & A_ERR_MISSING_BUSINESSID); } - ImGui::FormInputTextWithErrorHint(localize("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); - ImGui::FormInputTextWithErrorHint(localize("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); - ImGui::FormInputTextWithErrorHint(localize("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email), last_err & A_ERR_MISSING_EMAIL); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number), 0); + ImGui::FormInputTextWithErrorHint(locale::get("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account), 0); if (viewing_only) ImGui::EndDisabled(); ImGui::PopID(); @@ -113,7 +113,7 @@ static void draw_contact_list() if (max_page == 0) max_page = 1; // Table header controls: create button and pagination. - if (ImGui::Button(localize("form.create"))) + if (ImGui::Button(locale::get("form.create"))) { current_view_state = view_state::CREATE; active_contact = administration_contact_create_empty(); @@ -126,7 +126,7 @@ static void draw_contact_list() ImGui::SameLine(); bool enable_prev = current_page > 0; if (!enable_prev) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.prev")) && current_page > 0) current_page--; + if (ImGui::Button(locale::get("ui.prev")) && current_page > 0) current_page--; if (!enable_prev) ImGui::EndDisabled(); ImGui::SameLine(); @@ -136,16 +136,16 @@ static void draw_contact_list() ImGui::SameLine(); bool enable_next = current_page < max_page-1; if (!enable_next) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.next")) && current_page < max_page-1) current_page++; + if (ImGui::Button(locale::get("ui.next")) && current_page < max_page-1) current_page++; if (!enable_next) ImGui::EndDisabled(); ImGui::Spacing(); if (ImGui::BeginTable("TableContacts", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - ImGui::TableSetupColumn(localize("contact.table.identifier"), ImGuiTableColumnFlags_WidthFixed, 80); - ImGui::TableSetupColumn(localize("contact.table.name"), ImGuiTableColumnFlags_WidthStretch); - ImGui::TableSetupColumn(localize("contact.table.address"), ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn(locale::get("contact.table.identifier"), ImGuiTableColumnFlags_WidthFixed, 80); + ImGui::TableSetupColumn(locale::get("contact.table.name"), ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn(locale::get("contact.table.address"), ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 160); ImGui::TableHeadersRow(); @@ -163,7 +163,7 @@ static void draw_contact_list() ImGui::TableSetColumnIndex(3); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.view"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_contact = c; current_view_state = view_state::VIEW; @@ -171,14 +171,14 @@ static void draw_contact_list() ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.change"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_contact = c; current_view_state = view_state::EDIT; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.delete"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); @@ -187,15 +187,15 @@ static void draw_contact_list() // Confirmation popup before contact is deleted definitively. if (ImGui::BeginPopupModal("ConfirmDeletePopup", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoTitleBar)) { - ImGui::Text(localize("form.confirmDelete")); + ImGui::Text(locale::get("form.confirmDelete")); ImGui::Separator(); - if (ImGui::Button(localize("form.yes"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.yes"), ImVec2(120, 0))) { administration_contact_remove(selected_for_removal); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); - if (ImGui::Button(localize("form.no"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.no"), ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -207,7 +207,7 @@ static void draw_contact_list() static void ui_draw_contacts_create() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -218,7 +218,7 @@ static void ui_draw_contacts_create() if (!can_save) ImGui::BeginDisabled(); // Save button ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_contact_add(active_contact); current_view_state = view_state::LIST; } @@ -227,7 +227,7 @@ static void ui_draw_contacts_create() static void ui_draw_contacts_update() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -238,7 +238,7 @@ static void ui_draw_contacts_update() if (!can_save) ImGui::BeginDisabled(); // Save button ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_contact_update(active_contact); current_view_state = view_state::LIST; } @@ -254,7 +254,7 @@ void ui_draw_contacts() case view_state::EDIT: ui_draw_contacts_update(); break; case view_state::VIEW: - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } diff --git a/src/ui/ui_earnings.cpp b/src/ui/ui_earnings.cpp index 82fe1af..2106015 100644 --- a/src/ui/ui_earnings.cpp +++ b/src/ui/ui_earnings.cpp @@ -45,7 +45,7 @@ void ui_draw_earnings() bool enable_prev = current_page > 0; if (!enable_prev) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.prev")) && current_page > 0) current_page--; + if (ImGui::Button(locale::get("ui.prev")) && current_page > 0) current_page--; if (!enable_prev) ImGui::EndDisabled(); ImGui::SameLine(); @@ -54,7 +54,7 @@ void ui_draw_earnings() ImGui::SameLine(); bool enable_next = current_page < max_page-1; if (!enable_next) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.next")) && current_page < max_page-1) current_page++; + if (ImGui::Button(locale::get("ui.next")) && current_page < max_page-1) current_page++; if (!enable_next) ImGui::EndDisabled(); ImGui::Spacing(); @@ -100,7 +100,7 @@ void ui_draw_earnings() // Uncategorized income and expenses if (has_uncategorized_revenue || has_uncategorized_taxes || has_uncategorized_expenses) { ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text("(%s)", localize("statement.uncategorized")); + ImGui::TableSetColumnIndex(0); ImGui::Text("(%s)", locale::get("statement.uncategorized")); ImGui::TableSetColumnIndex(1); ImGui::Text(""); ImGui::TableSetColumnIndex(2); ImGui::Text(""); ImGui::TableSetColumnIndex(3); ImGui::Text(""); @@ -109,7 +109,7 @@ void ui_draw_earnings() if (has_uncategorized_revenue) { ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize("statement.revenue")); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get("statement.revenue")); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].uncategorized_revenue, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].uncategorized_revenue, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].uncategorized_revenue, currency_symbol); @@ -118,7 +118,7 @@ void ui_draw_earnings() if (has_uncategorized_taxes) { ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize("statement.tax")); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get("statement.tax")); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].uncategorized_taxes, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].uncategorized_taxes, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].uncategorized_taxes, currency_symbol); @@ -127,7 +127,7 @@ void ui_draw_earnings() if (has_uncategorized_expenses) { ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize("statement.expenses")); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get("statement.expenses")); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].uncategorized_expenses, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].uncategorized_expenses, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].uncategorized_expenses, currency_symbol); @@ -154,7 +154,7 @@ void ui_draw_earnings() ImGui::PushFont(fontBold); ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize("statement.revenue")); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get("statement.revenue")); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].reports[p].revenue, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].reports[p].revenue, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].reports[p].revenue, currency_symbol); @@ -162,7 +162,7 @@ void ui_draw_earnings() ImGui::PopFont(); ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize("statement.tax")); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get("statement.tax")); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].reports[p].taxes, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].reports[p].taxes, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].reports[p].taxes, currency_symbol); @@ -170,7 +170,7 @@ void ui_draw_earnings() ImGui::PushFont(fontBold); ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize("statement.expenses")); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get("statement.expenses")); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].reports[p].expenses_total, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].reports[p].expenses_total, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].reports[p].expenses_total, currency_symbol); @@ -182,7 +182,7 @@ void ui_draw_earnings() project_expense* expense = &report->expenses[e]; if (!expense->expense_used_in_project) continue; ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", localize(expense->description)); + ImGui::TableSetColumnIndex(0); ImGui::Text(" %s", locale::get(expense->description)); ImGui::TableSetColumnIndex(1); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 0].reports[p].expenses[e].total, currency_symbol); ImGui::TableSetColumnIndex(2); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 1].reports[p].expenses[e].total, currency_symbol); ImGui::TableSetColumnIndex(3); ImGui::Text("%.0f %s", statement->quarters[quarter_start + 2].reports[p].expenses[e].total, currency_symbol); @@ -194,7 +194,7 @@ void ui_draw_earnings() ImGui::PushFont(fontBold); ImGui::TableNextRow(); - ImGui::TableNextColumn(); ImGui::TextUnformatted(localize("statement.profit")); + ImGui::TableNextColumn(); ImGui::TextUnformatted(locale::get("statement.profit")); #define PUSH_PROFIT_COLUMN(_profit)\ ImGui::TableNextColumn(); \ diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index c02cdce..acb53a8 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -27,7 +27,7 @@ #include "administration.hpp" #include "administration_writer.hpp" #include "locales.hpp" -#include "import_service.hpp" +#include "importer.hpp" static import_invoice_request* active_import_request = 0; @@ -65,8 +65,8 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) { if (viewing_only) ImGui::BeginDisabled(); - ImGui::Text("%s: %s", localize("invoice.form.invoicenumber"), buffer->sequential_number); - ImGui::Text("%s: %s", localize("invoice.form.billedTo"), buffer->customer.name); + ImGui::Text("%s: %s", locale::get("invoice.form.invoicenumber"), buffer->sequential_number); + ImGui::Text("%s: %s", locale::get("invoice.form.billedTo"), buffer->customer.name); tm issued_at_date = *gmtime(&buffer->issued_at); if (ImGui::DatePicker("##issuedAt", issued_at_date)) @@ -74,7 +74,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) buffer->issued_at = mktime(&issued_at_date); } ImGui::SameLine(); - ImGui::Text(localize("invoice.form.issuedat")); + ImGui::Text(locale::get("invoice.form.issuedat")); tm expires_at_date = *gmtime(&buffer->expires_at); if (ImGui::DatePicker("##expiresAt", expires_at_date)) @@ -82,7 +82,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) buffer->expires_at = mktime(&expires_at_date); } ImGui::SameLine(); - ImGui::Text(localize("invoice.form.expiresat")); + ImGui::Text(locale::get("invoice.form.expiresat")); tm delivered_at_date = *gmtime(&buffer->delivered_at); if (ImGui::DatePicker("##deliveredAt", delivered_at_date)) @@ -90,23 +90,23 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) buffer->delivered_at = mktime(&delivered_at_date); } ImGui::SameLine(); - ImGui::Text(localize("invoice.form.deliveredat")); + ImGui::Text(locale::get("invoice.form.deliveredat")); ImGui::Separator(); - if (ImGui::FormInvoiceFileSelector("Select file...", buffer->document.original_path)) { // @localize + if (ImGui::FormInvoiceFileSelector("Select file...", buffer->document.original_path)) { // @locale::get buffer->document.copy_path[0] = 0; } ImGui::Separator(); - ImGui::Text(localize("invoice.form.supplier")); + ImGui::Text(locale::get("invoice.form.supplier")); draw_contact_form_ex(&buffer->supplier, false, true); - ImGui::Checkbox(localize("invoice.form.triangulation"), &buffer->is_triangulation); + ImGui::Checkbox(locale::get("invoice.form.triangulation"), &buffer->is_triangulation); if (buffer->is_triangulation) { ImGui::Spacing(); - ImGui::Text(localize("invoice.form.shippinginformation")); + ImGui::Text(locale::get("invoice.form.shippinginformation")); draw_addressee_form_ex(&buffer->addressee, 0); } ImGui::Separator(); @@ -122,7 +122,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) bool max_items_reached = administration_billing_item_count(buffer) >= MAX_BILLING_ITEMS; if (max_items_reached) ImGui::BeginDisabled(); - if (ImGui::Button(localize(localize("invoice.form.add")))) + if (ImGui::Button(locale::get(locale::get("invoice.form.add")))) { billing_item item = administration_billing_item_create_empty(); administration_billing_item_add_to_invoice(buffer, item); @@ -130,7 +130,7 @@ static void draw_expense_form(invoice* buffer, bool viewing_only = false) if (max_items_reached) ImGui::EndDisabled(); ImGui::SameLine(); - ImGui::Text("| %s: ", localize("invoice.form.currency")); + ImGui::Text("| %s: ", locale::get("invoice.form.currency")); ImGui::SameLine(); if (ImGui::FormCurrencyCombo(buffer->currency)) { @@ -146,7 +146,7 @@ static void ui_draw_expenses_list() { if (!administration_can_create_invoices()) { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 102, 204, 255)); // blue - ImGui::Text(localize("ui.invoiceRequirementP1")); + ImGui::Text(locale::get("ui.invoiceRequirementP1")); ImGui::PopStyleColor(); if (ImGui::IsItemHovered()) { @@ -157,7 +157,7 @@ static void ui_draw_expenses_list() } ImGui::SameLine(); - ImGui::Text(localize("ui.invoiceRequirementP2")); + ImGui::Text(locale::get("ui.invoiceRequirementP2")); return; } @@ -172,7 +172,7 @@ static void ui_draw_expenses_list() if (max_page == 0) max_page = 1; // Table header controls: create, import, and pagination. - if (ImGui::Button(localize("form.create"))) + if (ImGui::Button(locale::get("form.create"))) { current_view_state = view_state::CREATE; active_invoice = administration_invoice_create_empty(); // @leak @@ -183,7 +183,7 @@ static void ui_draw_expenses_list() char import_file_path[MAX_LEN_PATH] = {0}; ImGui::SameLine(); - if (ImGui::FormInvoiceFileSelector("+ Import", import_file_path)) { // @localize + if (ImGui::FormInvoiceFileSelector("+ Import", import_file_path)) { // @locale::get current_view_state = view_state::VIEW_IMPORT_REQUEST; active_invoice = administration_invoice_create_empty(); // @leak active_invoice.customer = administration_company_info_get(); @@ -200,7 +200,7 @@ static void ui_draw_expenses_list() ImGui::SameLine(); bool enable_prev = current_page > 0; if (!enable_prev) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.prev")) && current_page > 0) current_page--; + if (ImGui::Button(locale::get("ui.prev")) && current_page > 0) current_page--; if (!enable_prev) ImGui::EndDisabled(); ImGui::SameLine(); @@ -210,19 +210,19 @@ static void ui_draw_expenses_list() ImGui::SameLine(); bool enable_next = current_page < max_page-1; if (!enable_next) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.next")) && current_page < max_page-1) current_page++; + if (ImGui::Button(locale::get("ui.next")) && current_page < max_page-1) current_page++; if (!enable_next) ImGui::EndDisabled(); ImGui::Spacing(); if (ImGui::BeginTable("TableInvoices", 7, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - ImGui::TableSetupColumn(localize("invoice.table.invoicenumber"), ImGuiTableColumnFlags_WidthFixed, 120); - ImGui::TableSetupColumn(localize("invoice.table.sender")); - ImGui::TableSetupColumn(localize("invoice.table.customer")); - ImGui::TableSetupColumn(localize("invoice.table.issuedat")); - ImGui::TableSetupColumn(localize("invoice.table.total")); - ImGui::TableSetupColumn(localize("invoice.table.status")); + ImGui::TableSetupColumn(locale::get("invoice.table.invoicenumber"), ImGuiTableColumnFlags_WidthFixed, 120); + ImGui::TableSetupColumn(locale::get("invoice.table.sender")); + ImGui::TableSetupColumn(locale::get("invoice.table.customer")); + ImGui::TableSetupColumn(locale::get("invoice.table.issuedat")); + ImGui::TableSetupColumn(locale::get("invoice.table.total")); + ImGui::TableSetupColumn(locale::get("invoice.table.status")); ImGui::TableSetupColumn(""); ImGui::TableHeadersRow(); @@ -240,11 +240,11 @@ static void ui_draw_expenses_list() ImGui::TableSetColumnIndex(3); ImGui::Text(buf); ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f %s", c.total, c.currency); - ImGui::TableSetColumnIndex(5); ImGui::Text("%s", localize(administration_invoice_get_status_string(&c))); + ImGui::TableSetColumnIndex(5); ImGui::Text("%s", locale::get(administration_invoice_get_status_string(&c))); ImGui::TableSetColumnIndex(6); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.view"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_invoice = c; current_view_state = view_state::VIEW; @@ -252,14 +252,14 @@ static void ui_draw_expenses_list() ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.change"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_invoice = administration_invoice_create_copy(&c); // We create a copy because of billing item list pointers. current_view_state = view_state::EDIT; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.delete"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); @@ -268,15 +268,15 @@ static void ui_draw_expenses_list() // Confirmation popup before contact is deleted definitively. if (ImGui::BeginPopupModal("ConfirmDeletePopup", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoTitleBar)) { - ImGui::Text(localize("form.confirmDelete")); + ImGui::Text(locale::get("form.confirmDelete")); ImGui::Separator(); - if (ImGui::Button(localize("form.yes"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.yes"), ImVec2(120, 0))) { administration_invoice_remove(&selected_for_removal); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); - if (ImGui::Button(localize("form.no"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.no"), ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -289,7 +289,7 @@ static void ui_draw_expenses_list() static void ui_draw_expense_update() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -299,7 +299,7 @@ static void ui_draw_expense_update() if (!can_save) ImGui::BeginDisabled(); ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_invoice_update(&active_invoice); current_view_state = view_state::LIST; @@ -313,7 +313,7 @@ static void ui_draw_expense_update() static void ui_draw_expense_create() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -323,7 +323,7 @@ static void ui_draw_expense_create() if (!can_save) ImGui::BeginDisabled(); ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_invoice_add(&active_invoice); current_view_state = view_state::LIST; @@ -337,7 +337,7 @@ static void ui_draw_expense_create() static void ui_draw_expense_view() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -356,7 +356,7 @@ static void ui_draw_import_request() return; } else { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; active_import_request = 0; return; diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 4a087be..ee816a9 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -60,14 +60,14 @@ void draw_invoice_items_form(invoice* invoice) if (ImGui::BeginTable("TableBillingItems", 9, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { ImGui::TableSetupColumn("##actions", ImGuiTableColumnFlags_WidthFixed, 20); - ImGui::TableSetupColumn(localize("invoice.table.amount"), ImGuiTableColumnFlags_WidthFixed, 80); - ImGui::TableSetupColumn(localize("invoice.table.description")); - ImGui::TableSetupColumn(localize("invoice.table.price"), ImGuiTableColumnFlags_WidthFixed, 100); - ImGui::TableSetupColumn(localize("invoice.table.discount"), ImGuiTableColumnFlags_WidthFixed, 100); - ImGui::TableSetupColumn(localize("invoice.table.net"), ImGuiTableColumnFlags_WidthFixed, 100); - ImGui::TableSetupColumn(localize("invoice.table.tax%"), ImGuiTableColumnFlags_WidthFixed, 120); - ImGui::TableSetupColumn(localize("invoice.table.tax"), ImGuiTableColumnFlags_WidthFixed, 100); - ImGui::TableSetupColumn(localize("invoice.table.total"), ImGuiTableColumnFlags_WidthFixed, 100); + ImGui::TableSetupColumn(locale::get("invoice.table.amount"), ImGuiTableColumnFlags_WidthFixed, 80); + ImGui::TableSetupColumn(locale::get("invoice.table.description")); + ImGui::TableSetupColumn(locale::get("invoice.table.price"), ImGuiTableColumnFlags_WidthFixed, 100); + ImGui::TableSetupColumn(locale::get("invoice.table.discount"), ImGuiTableColumnFlags_WidthFixed, 100); + ImGui::TableSetupColumn(locale::get("invoice.table.net"), ImGuiTableColumnFlags_WidthFixed, 100); + ImGui::TableSetupColumn(locale::get("invoice.table.tax%"), ImGuiTableColumnFlags_WidthFixed, 120); + ImGui::TableSetupColumn(locale::get("invoice.table.tax"), ImGuiTableColumnFlags_WidthFixed, 100); + ImGui::TableSetupColumn(locale::get("invoice.table.total"), ImGuiTableColumnFlags_WidthFixed, 100); ImGui::TableHeadersRow(); @@ -145,7 +145,7 @@ void draw_invoice_items_form(invoice* invoice) ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, IM_COL32(50, 50, 50, 255)); ImGui::TableSetColumnIndex(2); - ImGui::Text("%s %s", localize("invoice.form.finalSettlement"), administration_get_default_currency()); + ImGui::Text("%s %s", locale::get("invoice.form.finalSettlement"), administration_get_default_currency()); ImGui::TableSetColumnIndex(4); ImGui::InputFloat("##final_allowance", &invoice->allowance, 0.0f, 0.0f, "%.2f"); @@ -176,8 +176,8 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) { ImGui::BeginDisabled(); - ImGui::Text("%s: %s", localize("invoice.form.invoicenumber"), buffer->sequential_number); - ImGui::Text("%s: %s", localize("invoice.form.supplier"), buffer->supplier.name); + ImGui::Text("%s: %s", locale::get("invoice.form.invoicenumber"), buffer->sequential_number); + ImGui::Text("%s: %s", locale::get("invoice.form.supplier"), buffer->supplier.name); tm issued_at_date = *gmtime(&buffer->issued_at); if (ImGui::DatePicker("##issuedAt", issued_at_date)) @@ -185,7 +185,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) buffer->issued_at = mktime(&issued_at_date); } ImGui::SameLine(); - ImGui::Text(localize("invoice.form.issuedat")); + ImGui::Text(locale::get("invoice.form.issuedat")); tm expires_at_date = *gmtime(&buffer->expires_at); if (ImGui::DatePicker("##expiresAt", expires_at_date)) @@ -193,7 +193,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) buffer->expires_at = mktime(&expires_at_date); } ImGui::SameLine(); - ImGui::Text(localize("invoice.form.expiresat")); + ImGui::Text(locale::get("invoice.form.expiresat")); if (!viewing_only) ImGui::EndDisabled(); tm delivered_at_date = *gmtime(&buffer->delivered_at); @@ -202,23 +202,23 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) buffer->delivered_at = mktime(&delivered_at_date); } ImGui::SameLine(); - ImGui::Text(localize("invoice.form.deliveredat")); + ImGui::Text(locale::get("invoice.form.deliveredat")); ImGui::Separator(); - if (ImGui::FormInvoiceFileSelector("Select file...", buffer->document.original_path)) { // @localize + if (ImGui::FormInvoiceFileSelector("Select file...", buffer->document.original_path)) { // @locale::get buffer->document.copy_path[0] = 0; } ImGui::Separator(); - ImGui::Text(localize("invoice.form.billinginformation")); + ImGui::Text(locale::get("invoice.form.billinginformation")); draw_contact_form_ex(&buffer->customer, false, true); - ImGui::Checkbox(localize("invoice.form.triangulation"), &buffer->is_triangulation); + ImGui::Checkbox(locale::get("invoice.form.triangulation"), &buffer->is_triangulation); if (buffer->is_triangulation) { ImGui::Spacing(); - ImGui::Text(localize("invoice.form.shippinginformation")); + ImGui::Text(locale::get("invoice.form.shippinginformation")); draw_addressee_form_ex(&buffer->addressee, 0); } ImGui::Separator(); @@ -231,7 +231,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) bool max_items_reached = administration_billing_item_count(buffer) >= MAX_BILLING_ITEMS; if (max_items_reached) ImGui::BeginDisabled(); - if (ImGui::Button(localize(localize("invoice.form.add")))) + if (ImGui::Button(locale::get(locale::get("invoice.form.add")))) { billing_item item = administration_billing_item_create_empty(); administration_billing_item_add_to_invoice(buffer, item); @@ -239,7 +239,7 @@ static void draw_invoice_form(invoice* buffer, bool viewing_only = false) if (max_items_reached) ImGui::EndDisabled(); ImGui::SameLine(); - ImGui::Text("| %s: ", localize("invoice.form.currency")); + ImGui::Text("| %s: ", locale::get("invoice.form.currency")); ImGui::SameLine(); if (ImGui::FormCurrencyCombo(buffer->currency)) { @@ -255,7 +255,7 @@ static void ui_draw_invoices_list() { if (!administration_can_create_invoices()) { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 102, 204, 255)); // blue - ImGui::Text(localize("ui.invoiceRequirementP1")); + ImGui::Text(locale::get("ui.invoiceRequirementP1")); ImGui::PopStyleColor(); if (ImGui::IsItemHovered()) { @@ -266,7 +266,7 @@ static void ui_draw_invoices_list() } ImGui::SameLine(); - ImGui::Text(localize("ui.invoiceRequirementP2")); + ImGui::Text(locale::get("ui.invoiceRequirementP2")); return; } @@ -281,7 +281,7 @@ static void ui_draw_invoices_list() if (max_page == 0) max_page = 1; // Table header controls: create button and pagination. - if (ImGui::Button(localize("form.create"))) + if (ImGui::Button(locale::get("form.create"))) { current_view_state = view_state::CREATE; active_invoice = administration_invoice_create_empty(); // @leak @@ -297,7 +297,7 @@ static void ui_draw_invoices_list() ImGui::SameLine(); bool enable_prev = current_page > 0; if (!enable_prev) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.prev")) && current_page > 0) current_page--; + if (ImGui::Button(locale::get("ui.prev")) && current_page > 0) current_page--; if (!enable_prev) ImGui::EndDisabled(); ImGui::SameLine(); @@ -307,19 +307,19 @@ static void ui_draw_invoices_list() ImGui::SameLine(); bool enable_next = current_page < max_page-1; if (!enable_next) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.next")) && current_page < max_page-1) current_page++; + if (ImGui::Button(locale::get("ui.next")) && current_page < max_page-1) current_page++; if (!enable_next) ImGui::EndDisabled(); ImGui::Spacing(); if (ImGui::BeginTable("TableInvoices", 7, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - ImGui::TableSetupColumn(localize("invoice.table.invoicenumber"), ImGuiTableColumnFlags_WidthFixed, 120); - ImGui::TableSetupColumn(localize("invoice.table.customer")); - ImGui::TableSetupColumn(localize("invoice.table.addressee")); - ImGui::TableSetupColumn(localize("invoice.table.issuedat")); - ImGui::TableSetupColumn(localize("invoice.table.total")); - ImGui::TableSetupColumn(localize("invoice.table.status")); + ImGui::TableSetupColumn(locale::get("invoice.table.invoicenumber"), ImGuiTableColumnFlags_WidthFixed, 120); + ImGui::TableSetupColumn(locale::get("invoice.table.customer")); + ImGui::TableSetupColumn(locale::get("invoice.table.addressee")); + ImGui::TableSetupColumn(locale::get("invoice.table.issuedat")); + ImGui::TableSetupColumn(locale::get("invoice.table.total")); + ImGui::TableSetupColumn(locale::get("invoice.table.status")); ImGui::TableSetupColumn(""); ImGui::TableHeadersRow(); @@ -337,11 +337,11 @@ static void ui_draw_invoices_list() ImGui::TableSetColumnIndex(3); ImGui::Text(buf); ImGui::TableSetColumnIndex(4); ImGui::Text("%.2f %s", c.total, c.currency); - ImGui::TableSetColumnIndex(5); ImGui::Text("%s", localize(administration_invoice_get_status_string(&c))); + ImGui::TableSetColumnIndex(5); ImGui::Text("%s", locale::get(administration_invoice_get_status_string(&c))); ImGui::TableSetColumnIndex(6); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.view"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_invoice = c; current_view_state = view_state::VIEW; @@ -351,14 +351,14 @@ static void ui_draw_invoices_list() if (c.status == invoice_status::INVOICE_CONCEPT) { - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.change"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_invoice = administration_invoice_create_copy(&c); // We create a copy because of billing item list pointers. current_view_state = view_state::EDIT; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.delete"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); @@ -368,15 +368,15 @@ static void ui_draw_invoices_list() // Confirmation popup before contact is deleted definitively. if (ImGui::BeginPopupModal("ConfirmDeletePopup", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoTitleBar)) { - ImGui::Text(localize("form.confirmDelete")); + ImGui::Text(locale::get("form.confirmDelete")); ImGui::Separator(); - if (ImGui::Button(localize("form.yes"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.yes"), ImVec2(120, 0))) { administration_invoice_remove(&selected_for_removal); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); - if (ImGui::Button(localize("form.no"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.no"), ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); @@ -389,7 +389,7 @@ static void ui_draw_invoices_list() static void ui_draw_invoice_update() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -399,7 +399,7 @@ static void ui_draw_invoice_update() if (!can_save) ImGui::BeginDisabled(); ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_invoice_update(&active_invoice); current_view_state = view_state::LIST; @@ -413,7 +413,7 @@ static void ui_draw_invoice_update() static void ui_draw_invoice_create() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } @@ -423,7 +423,7 @@ static void ui_draw_invoice_create() if (!can_save) ImGui::BeginDisabled(); ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_invoice_add(&active_invoice); current_view_state = view_state::LIST; @@ -437,7 +437,7 @@ static void ui_draw_invoice_create() static void ui_draw_invoice_view() { - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; } diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp index 45b787b..f918ce8 100644 --- a/src/ui/ui_main.cpp +++ b/src/ui/ui_main.cpp @@ -67,7 +67,7 @@ void ui_draw_main() { if (ui_state == main_state::UI_END) ui_set_state(main_state::UI_INVOICES); - // @localize + // @locale::get if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("File")) @@ -107,22 +107,22 @@ void ui_draw_main() float buttonWidth = sidePanelWidth; - if (ImGui::Button(localize("nav.invoices"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_INVOICES); - if (ImGui::Button(localize("nav.expenses"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_EXPENSES); - if (ImGui::Button(localize("nav.contacts"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_CONTACTS); + if (ImGui::Button(locale::get("nav.invoices"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_INVOICES); + if (ImGui::Button(locale::get("nav.expenses"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_EXPENSES); + if (ImGui::Button(locale::get("nav.contacts"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_CONTACTS); static bool reports_opened = true; - if (ImGui::Button(localize("nav.reports"), ImVec2(buttonWidth, 24))) reports_opened = !reports_opened; + if (ImGui::Button(locale::get("nav.reports"), ImVec2(buttonWidth, 24))) reports_opened = !reports_opened; if (reports_opened) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(20.0f, 0.0f)); - if (ImGui::Button(localize("nav.reports.results"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_REPORT_RESULTS); - if (ImGui::Button(localize("nav.reports.tax"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_REPORT_TAX); + if (ImGui::Button(locale::get("nav.reports.results"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_REPORT_RESULTS); + if (ImGui::Button(locale::get("nav.reports.tax"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_REPORT_TAX); ImGui::PopStyleVar(); } - if (ImGui::Button(localize("nav.projects"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_PROJECTS); - if (ImGui::Button(localize("nav.settings"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_SETTINGS); + if (ImGui::Button(locale::get("nav.projects"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_PROJECTS); + if (ImGui::Button(locale::get("nav.settings"), ImVec2(buttonWidth, 24))) ui_set_state(main_state::UI_SETTINGS); ImGui::PopStyleColor(1); ImGui::PopStyleVar(3); @@ -154,10 +154,10 @@ void ui_draw_main() char* path = administration_get_file_path(); if (path == NULL) { - ImGui::Text("%s: %s", localize("ui.workingOn"), localize("ui.unsavedProject")); + ImGui::Text("%s: %s", locale::get("ui.workingOn"), locale::get("ui.unsavedProject")); } else { - ImGui::Text("%s: %s", localize("ui.workingOn"), path); + ImGui::Text("%s: %s", locale::get("ui.workingOn"), path); } ImGui::SameLine(); diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp index e7fa86f..560bc72 100644 --- a/src/ui/ui_projects.cpp +++ b/src/ui/ui_projects.cpp @@ -39,7 +39,7 @@ static void draw_project_form() bool viewing_only = (current_view_state == view_state::VIEW); static const char* selected_country = NULL; - if (ImGui::Button(localize("form.back"))) { + if (ImGui::Button(locale::get("form.back"))) { current_view_state = view_state::LIST; active_project = administration_project_create_empty(); selected_country = 0; @@ -51,10 +51,10 @@ static void draw_project_form() a_err last_err = administration_project_is_valid(active_project); ImGui::SetNextItemWidth(widthAvailable*0.2f); - ImGui::InputText(localize("project.form.identifier"), active_project.id, IM_ARRAYSIZE(active_project.id)); + ImGui::InputText(locale::get("project.form.identifier"), active_project.id, IM_ARRAYSIZE(active_project.id)); if (!viewing_only) ImGui::EndDisabled(); - ImGui::FormInputTextWithErrorHint(localize("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); + ImGui::FormInputTextWithErrorHint(locale::get("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description), last_err & A_ERR_MISSING_DESCRIPTION); if (viewing_only) ImGui::EndDisabled(); @@ -64,7 +64,7 @@ static void draw_project_form() if (!can_save) ImGui::BeginDisabled(); // Save button ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { if (current_view_state == view_state::CREATE) { administration_project_add(active_project); } @@ -91,7 +91,7 @@ static void draw_project_list() s32 max_page = (administration_project_count() + items_per_page - 1) / items_per_page; if (max_page == 0) max_page = 1; - if (ImGui::Button(localize("form.create"))) + if (ImGui::Button(locale::get("form.create"))) { current_view_state = view_state::CREATE; active_project = administration_project_create_empty(); @@ -103,7 +103,7 @@ static void draw_project_list() ImGui::SameLine(); bool enable_prev = current_page > 0; if (!enable_prev) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.prev")) && current_page > 0) current_page--; + if (ImGui::Button(locale::get("ui.prev")) && current_page > 0) current_page--; if (!enable_prev) ImGui::EndDisabled(); ImGui::SameLine(); @@ -112,16 +112,16 @@ static void draw_project_list() ImGui::SameLine(); bool enable_next = current_page < max_page-1; if (!enable_next) ImGui::BeginDisabled(); - if (ImGui::Button(localize("ui.next")) && current_page < max_page-1) current_page++; + if (ImGui::Button(locale::get("ui.next")) && current_page < max_page-1) current_page++; if (!enable_next) ImGui::EndDisabled(); ImGui::Spacing(); if (ImGui::BeginTable("TableProjects", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - ImGui::TableSetupColumn(localize("project.table.identifier"), ImGuiTableColumnFlags_WidthFixed, 80); - ImGui::TableSetupColumn(localize("project.table.status"), ImGuiTableColumnFlags_WidthFixed, 140); - ImGui::TableSetupColumn(localize("project.table.description"), ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn(locale::get("project.table.identifier"), ImGuiTableColumnFlags_WidthFixed, 80); + ImGui::TableSetupColumn(locale::get("project.table.status"), ImGuiTableColumnFlags_WidthFixed, 140); + ImGui::TableSetupColumn(locale::get("project.table.description"), ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 160); ImGui::TableHeadersRow(); @@ -133,13 +133,13 @@ static void draw_project_list() ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::Text(c.id); - ImGui::TableSetColumnIndex(1); ImGui::Text(localize(administration_project_get_status_string(c))); + ImGui::TableSetColumnIndex(1); ImGui::Text(locale::get(administration_project_get_status_string(c))); ImGui::TableSetColumnIndex(2); ImGui::Text(c.description); ImGui::TableSetColumnIndex(3); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.view"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_project = c; current_view_state = view_state::VIEW; @@ -148,14 +148,14 @@ static void draw_project_list() if (c.state == project_state::PROJECT_RUNNING) { ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.change"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_project = c; current_view_state = view_state::EDIT; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.cancel"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.cancel"), i); if (ImGui::Button(btn_name)) { selected_for_cancellation = c; ImGui::OpenPopup("ConfirmCancelProject"); @@ -164,15 +164,15 @@ static void draw_project_list() } if (ImGui::BeginPopupModal("ConfirmCancelProject", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoTitleBar)) { - ImGui::Text(localize("form.confirmCancelProject")); + ImGui::Text(locale::get("form.confirmCancelProject")); ImGui::Separator(); - if (ImGui::Button(localize("form.yes"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.yes"), ImVec2(120, 0))) { administration_project_cancel(selected_for_cancellation); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); - if (ImGui::Button(localize("form.no"), ImVec2(120, 0))) { + if (ImGui::Button(locale::get("form.no"), ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp index d7dfd4d..79d65da 100644 --- a/src/ui/ui_settings.cpp +++ b/src/ui/ui_settings.cpp @@ -69,8 +69,8 @@ static void ui_draw_vat_rates() if (ImGui::BeginTable("TableVatRates", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - ImGui::TableSetupColumn(localize("settings.vat.table.country"), ImGuiTableColumnFlags_WidthFixed, 220); - ImGui::TableSetupColumn(localize("settings.vat.table.rates")); + ImGui::TableSetupColumn(locale::get("settings.vat.table.country"), ImGuiTableColumnFlags_WidthFixed, 220); + ImGui::TableSetupColumn(locale::get("settings.vat.table.rates")); // Used to generate headers for each individual country. char prev_country[MAX_LEN_COUNTRY_CODE]; @@ -105,7 +105,7 @@ static void ui_draw_vat_rates() char locale_buf[20]; snprintf(locale_buf, sizeof(locale_buf), "country.%s", c.country_code); ImGui::TableSetColumnIndex(0); - ImGui::Text(localize(locale_buf)); + ImGui::Text(locale::get(locale_buf)); // If not adding an item already, show + button next to country name. if (!is_adding_item) @@ -132,7 +132,7 @@ static void ui_draw_vat_rates() char category_code_desc[MAX_LEN_LONG_DESC]; snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", c.category_code); - ImGui::Text(can_be_modified ? "" : localize(category_code_desc)); + ImGui::Text(can_be_modified ? "" : locale::get(category_code_desc)); // Column 2: When editing, show input for new rate. Else we display the stored rate and check for modify request. @@ -145,7 +145,7 @@ static void ui_draw_vat_rates() if (new_tax_rate.rate > 100.0f) new_tax_rate.rate = 100.0f; ImGui::SameLine(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { is_editing_item = false; is_adding_item = false; @@ -156,7 +156,7 @@ static void ui_draw_vat_rates() } ImGui::SameLine(); - if (ImGui::Button(localize("form.cancel"))) { + if (ImGui::Button(locale::get("form.cancel"))) { is_editing_item = false; is_adding_item = false; memset(&new_tax_rate, 0, sizeof(new_tax_rate)); @@ -191,7 +191,7 @@ static void ui_draw_vat_rates() if (new_tax_rate.rate > 100.0f) new_tax_rate.rate = 100.0f; ImGui::SameLine(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { is_editing_item = false; is_adding_item = false; @@ -202,7 +202,7 @@ static void ui_draw_vat_rates() } ImGui::SameLine(); - if (ImGui::Button(localize("form.cancel"))) { + if (ImGui::Button(locale::get("form.cancel"))) { is_editing_item = false; is_adding_item = false; memset(&new_tax_rate, 0, sizeof(new_tax_rate)); @@ -225,8 +225,8 @@ static void ui_draw_cost_centers() if (ImGui::BeginTable("TableCostCenters", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - ImGui::TableSetupColumn(localize("settings.costcenters.table.code"), ImGuiTableColumnFlags_WidthFixed, 140); - ImGui::TableSetupColumn(localize("settings.costcenters.table.description")); + ImGui::TableSetupColumn(locale::get("settings.costcenters.table.code"), ImGuiTableColumnFlags_WidthFixed, 140); + ImGui::TableSetupColumn(locale::get("settings.costcenters.table.description")); for (u32 i = 0; i < cost_center_count; i++) { cost_center c = cost_centers[i]; @@ -247,7 +247,7 @@ static void ui_draw_cost_centers() if (!is_desc_valid) ImGui::BeginDisabled(); ImGui::SameLine(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { is_editing_item = false; is_adding_item = false; @@ -261,7 +261,7 @@ static void ui_draw_cost_centers() if (!is_desc_valid) ImGui::EndDisabled(); ImGui::SameLine(); - if (ImGui::Button(localize("form.cancel"))) { + if (ImGui::Button(locale::get("form.cancel"))) { is_editing_item = false; is_adding_item = false; memset(&new_cost_center, 0, sizeof(new_cost_center)); @@ -269,7 +269,7 @@ static void ui_draw_cost_centers() } else { - ImGui::Text(localize(c.description)); + ImGui::Text(locale::get(c.description)); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { @@ -302,7 +302,7 @@ static void ui_draw_cost_centers() if (!can_save) ImGui::BeginDisabled(); ImGui::SameLine(); - if (ImGui::Button(localize("form.create"))) + if (ImGui::Button(locale::get("form.create"))) { is_adding_item = false; is_editing_item = false; @@ -314,7 +314,7 @@ static void ui_draw_cost_centers() if (!can_save) ImGui::EndDisabled(); ImGui::SameLine(); - if (ImGui::Button(localize("form.cancel"))) { + if (ImGui::Button(locale::get("form.cancel"))) { is_adding_item = false; is_editing_item = false; memset(&new_cost_center, 0, sizeof(new_cost_center)); @@ -325,7 +325,7 @@ static void ui_draw_cost_centers() } // If not adding a new item already, show create button at bottom of list. - if (!is_adding_item && ImGui::Button(localize("form.create"))) + if (!is_adding_item && ImGui::Button(locale::get("form.create"))) { new_cost_center = administration_cost_center_create_empty(); is_adding_item = true; @@ -336,7 +336,7 @@ static void ui_draw_cost_centers() static void ui_draw_services() { // AI service - if (ImGui::CollapsingHeader(localize("settings.services.ai_service"))) + if (ImGui::CollapsingHeader(locale::get("settings.services.ai_service"))) { // TODO: get this from iterator over ai_get_impl char* services[2] = { @@ -344,7 +344,7 @@ static void ui_draw_services() "DeepSeek", }; - if (ImGui::BeginCombo(localize("settings.services.ai_service.provider"), services[new_service.provider])) + if (ImGui::BeginCombo(locale::get("settings.services.ai_service.provider"), services[new_service.provider])) { for (u32 n = 0; n < 2; n++) { @@ -356,10 +356,10 @@ static void ui_draw_services() ImGui::EndCombo(); } - ImGui::InputTextWithHint(localize("settings.services.ai_service.pubkey"), localize("settings.services.ai_service.pubkey"), + ImGui::InputTextWithHint(locale::get("settings.services.ai_service.pubkey"), locale::get("settings.services.ai_service.pubkey"), new_service.api_key_public, sizeof(new_service.api_key_public)); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_set_ai_service(new_service); } } @@ -369,7 +369,7 @@ void ui_draw_settings() { if (ImGui::BeginTabBar("SettingsTabBar")) { - if (ImGui::BeginTabItem(localize("settings.table.company"), nullptr, select_company_tab == 1 ? ImGuiTabItemFlags_SetSelected : 0)) + if (ImGui::BeginTabItem(locale::get("settings.table.company"), nullptr, select_company_tab == 1 ? ImGuiTabItemFlags_SetSelected : 0)) { select_company_tab = 0; draw_contact_form(&company_info); @@ -378,24 +378,24 @@ void ui_draw_settings() bool can_save = administration_contact_is_valid(company_info) == A_ERR_SUCCESS; if (!can_save) ImGui::BeginDisabled(); ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { + if (ImGui::Button(locale::get("form.save"))) { administration_company_info_set(company_info); } if (!can_save) ImGui::EndDisabled(); ImGui::EndTabItem(); } - if (ImGui::BeginTabItem(localize("settings.table.vatrates"))) + if (ImGui::BeginTabItem(locale::get("settings.table.vatrates"))) { ui_draw_vat_rates(); ImGui::EndTabItem(); } - if (ImGui::BeginTabItem(localize("settings.table.costcenters"))) + if (ImGui::BeginTabItem(locale::get("settings.table.costcenters"))) { ui_draw_cost_centers(); ImGui::EndTabItem(); } - if (ImGui::BeginTabItem(localize("settings.table.services"))) + if (ImGui::BeginTabItem(locale::get("settings.table.services"))) { ui_draw_services(); ImGui::EndTabItem(); |
