/* * Copyright (c) 2025 Aldrik Ramaekers * * 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 "locales.hpp" #include "strops.hpp" extern locale_entry en_locales[]; extern int en_locale_count; typedef struct { const char* lang_code; locale_entry* entries; int entry_count; } locale_map; namespace locale { static locale_map locales[] = { {"en", en_locales, 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* get_locale() { return g_locale.lang_code; } void set_locale(const char* key) { for (int i = 0; i < locale_map_count; ++i) { if (strops::equals(locales[i].lang_code, key)) { g_locale = locales[i]; } } } const char* get(const char* key) { for (int i = 0; i < g_locale.entry_count; ++i) { if (strops::equals(g_locale.entries[i].key, key)) { return g_locale.entries[i].value; } } return key; } }