feat: setting default locale for instance
This commit is contained in:
@@ -3,6 +3,9 @@ host = 0.0.0.0
|
|||||||
port = 8087
|
port = 8087
|
||||||
domain = https://search.example.com
|
domain = https://search.example.com
|
||||||
|
|
||||||
|
# Default locale (default: en_gb)
|
||||||
|
#locale = en_gb
|
||||||
|
|
||||||
[proxy]
|
[proxy]
|
||||||
# Single proxy (comment out to use list_file instead)
|
# Single proxy (comment out to use list_file instead)
|
||||||
#proxy = "socks5://127.0.0.1:9050"
|
#proxy = "socks5://127.0.0.1:9050"
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ int load_config(const char *filename, Config *config) {
|
|||||||
} else if (strcmp(key, "domain") == 0) {
|
} else if (strcmp(key, "domain") == 0) {
|
||||||
strncpy(config->domain, value, sizeof(config->domain) - 1);
|
strncpy(config->domain, value, sizeof(config->domain) - 1);
|
||||||
config->domain[sizeof(config->domain) - 1] = '\0';
|
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) {
|
} else if (strcmp(section, "proxy") == 0) {
|
||||||
if (strcmp(key, "proxy") == 0) {
|
if (strcmp(key, "proxy") == 0) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ typedef struct {
|
|||||||
char host[256];
|
char host[256];
|
||||||
int port;
|
int port;
|
||||||
char domain[256];
|
char domain[256];
|
||||||
|
char default_locale[32];
|
||||||
char proxy[256];
|
char proxy[256];
|
||||||
char proxy_list_file[256];
|
char proxy_list_file[256];
|
||||||
int max_proxy_retries;
|
int max_proxy_retries;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Routes/Settings.h"
|
#include "Routes/Settings.h"
|
||||||
#include "Routes/SettingsSave.h"
|
#include "Routes/SettingsSave.h"
|
||||||
#include "Scraping/Scraping.h"
|
#include "Scraping/Scraping.h"
|
||||||
|
#include "Utility/Utility.h"
|
||||||
|
|
||||||
Config global_config;
|
Config global_config;
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ int main() {
|
|||||||
Config cfg = {.host = DEFAULT_HOST,
|
Config cfg = {.host = DEFAULT_HOST,
|
||||||
.port = DEFAULT_PORT,
|
.port = DEFAULT_PORT,
|
||||||
.domain = "",
|
.domain = "",
|
||||||
|
.default_locale = "en_gb",
|
||||||
.proxy = "",
|
.proxy = "",
|
||||||
.proxy_list_file = "",
|
.proxy_list_file = "",
|
||||||
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
|
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
|
||||||
@@ -65,6 +67,8 @@ int main() {
|
|||||||
fprintf(stderr, "[WARN] Could not load config file, using defaults\n");
|
fprintf(stderr, "[WARN] Could not load config file, using defaults\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_default_locale(cfg.default_locale);
|
||||||
|
|
||||||
global_config = cfg;
|
global_config = cfg;
|
||||||
|
|
||||||
int loaded = beaker_load_locales();
|
int loaded = beaker_load_locales();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
int home_handler(UrlParams *params) {
|
int home_handler(UrlParams *params) {
|
||||||
(void)params;
|
(void)params;
|
||||||
char *theme = get_theme("");
|
char *theme = get_theme("");
|
||||||
char *locale = get_locale("en_gb");
|
char *locale = get_locale(NULL);
|
||||||
|
|
||||||
TemplateContext ctx = new_context();
|
TemplateContext ctx = new_context();
|
||||||
context_set(&ctx, "theme", theme);
|
context_set(&ctx, "theme", theme);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ int images_handler(UrlParams *params) {
|
|||||||
context_set(&ctx, "theme", theme);
|
context_set(&ctx, "theme", theme);
|
||||||
free(theme);
|
free(theme);
|
||||||
|
|
||||||
char *locale = get_locale("en_gb");
|
char *locale = get_locale(NULL);
|
||||||
beaker_set_locale(&ctx, locale);
|
beaker_set_locale(&ctx, locale);
|
||||||
|
|
||||||
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ int results_handler(UrlParams *params) {
|
|||||||
context_set(&ctx, "theme", theme);
|
context_set(&ctx, "theme", theme);
|
||||||
free(theme);
|
free(theme);
|
||||||
|
|
||||||
char *locale = get_locale("en_gb");
|
char *locale = get_locale(NULL);
|
||||||
beaker_set_locale(&ctx, locale);
|
beaker_set_locale(&ctx, locale);
|
||||||
|
|
||||||
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ int settings_handler(UrlParams *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *theme = get_theme("system");
|
char *theme = get_theme("system");
|
||||||
char *locale = get_locale("en_gb");
|
char *locale = get_locale(NULL);
|
||||||
|
|
||||||
LocaleInfo locales[32];
|
LocaleInfo locales[32];
|
||||||
int locale_count = beaker_get_all_locales(locales, 32);
|
int locale_count = beaker_get_all_locales(locales, 32);
|
||||||
|
|||||||
@@ -5,6 +5,15 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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) {
|
int hex_to_int(char c) {
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
return c - '0';
|
return c - '0';
|
||||||
@@ -32,7 +41,8 @@ char *get_locale(const char *default_locale) {
|
|||||||
return cookie;
|
return cookie;
|
||||||
}
|
}
|
||||||
free(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) {
|
static int engine_id_casecmp(const char *a, const char *b) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
int hex_to_int(char c);
|
int hex_to_int(char c);
|
||||||
char *get_theme(const char *default_theme);
|
char *get_theme(const char *default_theme);
|
||||||
|
void set_default_locale(const char *locale);
|
||||||
char *get_locale(const char *default_locale);
|
char *get_locale(const char *default_locale);
|
||||||
|
|
||||||
int is_engine_id_enabled(const char *engine_id);
|
int is_engine_id_enabled(const char *engine_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user