diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-08-03 19:22:36 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-08-03 19:22:36 +0200 |
| commit | 853bbb3752a5fa2f58ef456ffb6e3a552e13cb11 (patch) | |
| tree | ce49a533f82a42a65fa6a4771a7b8fbfe33798cf /src/locales | |
initial commit
Diffstat (limited to 'src/locales')
| -rw-r--r-- | src/locales/en.cpp | 29 | ||||
| -rw-r--r-- | src/locales/locales.cpp | 29 | ||||
| -rw-r--r-- | src/locales/locales.hpp | 21 |
3 files changed, 79 insertions, 0 deletions
diff --git a/src/locales/en.cpp b/src/locales/en.cpp new file mode 100644 index 0000000..5e31c5c --- /dev/null +++ b/src/locales/en.cpp @@ -0,0 +1,29 @@ +#include "locales.hpp" + +locale_entry en_locales[] = { + // General form buttons. + {"form.create", "+ Create"}, + {"form.back", "Back"}, + {"form.save", "Save"}, + {"form.yes", "Yes"}, + {"form.no", "No"}, + {"form.change", "Change"}, + {"form.delete", "Delete"}, + {"form.confirmDelete", "Are you sure you want to delete this item?"}, + + // Contact strings. + {"contact.form.identifier", "Identifier"}, + {"contact.form.fullname", "Full name / name of business"}, + {"contact.form.address1", "Street name + house number, appt. number, etc."}, + {"contact.form.address2", "Zip, city, country"}, + {"contact.form.taxnumber", "Tax number"}, + {"contact.form.businessnumber", "Business number"}, + {"contact.form.email", "Email address"}, + {"contact.form.phonenumber", "Phone number"}, + {"contact.form.bankaccount", "Bank account"}, + {"contact.table.identifier", "Identifier"}, + {"contact.table.name", "Name"}, + {"contact.table.address", "Address"}, +}; + +const int en_locale_count = sizeof(en_locales) / sizeof(en_locales[0]);
\ No newline at end of file diff --git a/src/locales/locales.cpp b/src/locales/locales.cpp new file mode 100644 index 0000000..6ec1233 --- /dev/null +++ b/src/locales/locales.cpp @@ -0,0 +1,29 @@ +#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. + +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]; + } + } +} + +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; + } + } + return "[!MISSING!]"; +}
\ No newline at end of file diff --git a/src/locales/locales.hpp b/src/locales/locales.hpp new file mode 100644 index 0000000..78bb682 --- /dev/null +++ b/src/locales/locales.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include <stdio.h> +#include <string.h> + +typedef struct { + const char* key; + const char* value; +} locale_entry; + +typedef struct { + const char* lang_code; + locale_entry* entries; + int entry_count; +} locale_map; + +extern locale_entry en_locales[]; +extern const int en_locale_count; + +void set_locale(const char key[2]); +const char* localize(const char* key);
\ No newline at end of file |
