/* * 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 #include #include "locales.hpp" 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 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* 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; } }