aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Config.c3
-rw-r--r--src/Config.h1
-rw-r--r--src/Main.c4
-rw-r--r--src/Routes/Home.c2
-rw-r--r--src/Routes/Images.c2
-rw-r--r--src/Routes/Search.c2
-rw-r--r--src/Routes/Settings.c2
-rw-r--r--src/Utility/Utility.c12
-rw-r--r--src/Utility/Utility.h1
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;
diff --git a/src/Main.c b/src/Main.c
index 988d0b0..b6551bc 100644
--- a/src/Main.c
+++ b/src/Main.c
@@ -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);