From 3f1ab2576c31da36e7fc3f69694d4d76c8243842 Mon Sep 17 00:00:00 2001 From: frosty Date: Wed, 1 Apr 2026 04:00:34 +0300 Subject: feat: function for fetching content of locale keys --- beaker.h | 1 + src/l10n.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/beaker.h b/beaker.h index a5f374e..cc87634 100644 --- a/beaker.h +++ b/beaker.h @@ -119,6 +119,7 @@ int beaker_load_locales(void); void beaker_set_locale(TemplateContext *ctx, const char *locale_id); int beaker_get_all_locales(LocaleInfo *out, int max_count); const LocaleMeta *beaker_get_locale_meta(const char *locale_id); +const char *beaker_get_locale_value(const char *locale_id, const char *key); void beaker_free_locales(void); void send_response(const char *html); diff --git a/src/l10n.c b/src/l10n.c index f6e748f..4d8ac30 100644 --- a/src/l10n.c +++ b/src/l10n.c @@ -247,6 +247,23 @@ const LocaleMeta *beaker_get_locale_meta(const char *locale_id) { return NULL; } +const char *beaker_get_locale_value(const char *locale_id, const char *key) { + if (locale_id == NULL || key == NULL) { + return NULL; + } + for (int i = 0; i < locale_count; i++) { + if (strcmp(locales[i].meta.id, locale_id) == 0) { + for (int j = 0; j < locales[i].key_count; j++) { + if (strcmp(locales[i].keys[j].key, key) == 0) { + return locales[i].keys[j].value; + } + } + return NULL; + } + } + return NULL; +} + void beaker_free_locales(void) { for (int i = 0; i < locale_count; i++) { free(locales[i].keys); -- cgit v1.2.3