diff options
| author | frosty <gabriel@bwaaa.monster> | 2026-04-06 01:56:11 -0400 |
|---|---|---|
| committer | frosty <gabriel@bwaaa.monster> | 2026-04-06 01:56:11 -0400 |
| commit | f6c8242e7273b50a923ae0d5c59753505fa9df9b (patch) | |
| tree | b28979fd48a38dc3245babfadd2aef62c4099cb4 /src | |
| parent | e0c209c974b130a5e893c7d7b3d342f4ec325c8d (diff) | |
| download | omnisearch-f6c8242e7273b50a923ae0d5c59753505fa9df9b.tar.gz | |
feat: setting default locale for instanceindev
Diffstat (limited to 'src')
| -rw-r--r-- | src/Config.c | 3 | ||||
| -rw-r--r-- | src/Config.h | 1 | ||||
| -rw-r--r-- | src/Main.c | 4 | ||||
| -rw-r--r-- | src/Routes/Home.c | 2 | ||||
| -rw-r--r-- | src/Routes/Images.c | 2 | ||||
| -rw-r--r-- | src/Routes/Search.c | 2 | ||||
| -rw-r--r-- | src/Routes/Settings.c | 2 | ||||
| -rw-r--r-- | src/Utility/Utility.c | 12 | ||||
| -rw-r--r-- | src/Utility/Utility.h | 1 |
9 files changed, 24 insertions, 5 deletions
diff --git a/src/Config.c b/src/Config.c index c4bd1f1..967a4b4 100644 --- a/src/Config.c +++ b/src/Config.c @@ -68,6 +68,9 @@ int load_config(const char *filename, Config *config) { } else if (strcmp(key, "domain") == 0) { strncpy(config->domain, value, sizeof(config->domain) - 1); config->domain[sizeof(config->domain) - 1] = '\0'; + } else if (strcmp(key, "locale") == 0) { + strncpy(config->default_locale, value, sizeof(config->default_locale) - 1); + config->default_locale[sizeof(config->default_locale) - 1] = '\0'; } } else if (strcmp(section, "proxy") == 0) { if (strcmp(key, "proxy") == 0) { diff --git a/src/Config.h b/src/Config.h index 8e68eae..25bd978 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,6 +35,7 @@ typedef struct { char host[256]; int port; char domain[256]; + char default_locale[32]; char proxy[256]; char proxy_list_file[256]; int max_proxy_retries; @@ -16,6 +16,7 @@ #include "Routes/Settings.h" #include "Routes/SettingsSave.h" #include "Scraping/Scraping.h" +#include "Utility/Utility.h" Config global_config; @@ -46,6 +47,7 @@ int main() { Config cfg = {.host = DEFAULT_HOST, .port = DEFAULT_PORT, .domain = "", + .default_locale = "en_gb", .proxy = "", .proxy_list_file = "", .max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES, @@ -65,6 +67,8 @@ int main() { fprintf(stderr, "[WARN] Could not load config file, using defaults\n"); } + set_default_locale(cfg.default_locale); + global_config = cfg; int loaded = beaker_load_locales(); diff --git a/src/Routes/Home.c b/src/Routes/Home.c index be9a3d0..0534517 100644 --- a/src/Routes/Home.c +++ b/src/Routes/Home.c @@ -6,7 +6,7 @@ int home_handler(UrlParams *params) { (void)params; char *theme = get_theme(""); - char *locale = get_locale("en_gb"); + char *locale = get_locale(NULL); TemplateContext ctx = new_context(); context_set(&ctx, "theme", theme); diff --git a/src/Routes/Images.c b/src/Routes/Images.c index 21e6f63..dda329c 100644 --- a/src/Routes/Images.c +++ b/src/Routes/Images.c @@ -63,7 +63,7 @@ int images_handler(UrlParams *params) { context_set(&ctx, "theme", theme); free(theme); - char *locale = get_locale("en_gb"); + char *locale = get_locale(NULL); beaker_set_locale(&ctx, locale); const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit"); diff --git a/src/Routes/Search.c b/src/Routes/Search.c index 09c4b8a..f51fc5f 100644 --- a/src/Routes/Search.c +++ b/src/Routes/Search.c @@ -461,7 +461,7 @@ int results_handler(UrlParams *params) { context_set(&ctx, "theme", theme); free(theme); - char *locale = get_locale("en_gb"); + char *locale = get_locale(NULL); beaker_set_locale(&ctx, locale); const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit"); diff --git a/src/Routes/Settings.c b/src/Routes/Settings.c index 7a16595..b21dd6f 100644 --- a/src/Routes/Settings.c +++ b/src/Routes/Settings.c @@ -16,7 +16,7 @@ int settings_handler(UrlParams *params) { } char *theme = get_theme("system"); - char *locale = get_locale("en_gb"); + char *locale = get_locale(NULL); LocaleInfo locales[32]; int locale_count = beaker_get_all_locales(locales, 32); diff --git a/src/Utility/Utility.c b/src/Utility/Utility.c index e6a4549..8bcb748 100644 --- a/src/Utility/Utility.c +++ b/src/Utility/Utility.c @@ -5,6 +5,15 @@ #include <stdlib.h> #include <string.h> +static char global_default_locale[32] = "en_gb"; + +void set_default_locale(const char *locale) { + if (locale && strlen(locale) > 0) { + strncpy(global_default_locale, locale, sizeof(global_default_locale) - 1); + global_default_locale[sizeof(global_default_locale) - 1] = '\0'; + } +} + int hex_to_int(char c) { if (c >= '0' && c <= '9') return c - '0'; @@ -32,7 +41,8 @@ char *get_locale(const char *default_locale) { return cookie; } free(cookie); - return strdup(default_locale); + const char *fallback = default_locale ? default_locale : global_default_locale; + return strdup(fallback); } static int engine_id_casecmp(const char *a, const char *b) { diff --git a/src/Utility/Utility.h b/src/Utility/Utility.h index e00e50c..bd48295 100644 --- a/src/Utility/Utility.h +++ b/src/Utility/Utility.h @@ -15,6 +15,7 @@ int hex_to_int(char c); char *get_theme(const char *default_theme); +void set_default_locale(const char *locale); char *get_locale(const char *default_locale); int is_engine_id_enabled(const char *engine_id); |
