feat: add more locale keys
This commit is contained in:
parent
c41ab84738
commit
116069c8e9
5 changed files with 43 additions and 18 deletions
|
|
@ -23,6 +23,9 @@ save_settings_button = "meow"
|
||||||
no_results = "meow"
|
no_results = "meow"
|
||||||
error_images = "meow"
|
error_images = "meow"
|
||||||
rate_limit = "meow"
|
rate_limit = "meow"
|
||||||
|
warning_fetch_error = "meow"
|
||||||
|
warning_parse_mismatch = "meow"
|
||||||
|
warning_blocked = "meow"
|
||||||
read_more = "meow"
|
read_more = "meow"
|
||||||
view_cached = "meow"
|
view_cached = "meow"
|
||||||
view_image = "meow"
|
view_image = "meow"
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@ save_settings_button = "Save Settings"
|
||||||
no_results = "No results found"
|
no_results = "No results found"
|
||||||
error_images = "Error fetching images"
|
error_images = "Error fetching images"
|
||||||
rate_limit = "Slow down! Too many searches from you!"
|
rate_limit = "Slow down! Too many searches from you!"
|
||||||
|
warning_fetch_error = "request failed before OmniSearch could read search results."
|
||||||
|
warning_parse_mismatch = "returned search results in a format OmniSearch could not parse."
|
||||||
|
warning_blocked = "returned a captcha or another blocking page instead of search results."
|
||||||
read_more = "Read More"
|
read_more = "Read More"
|
||||||
view_cached = "Cached"
|
view_cached = "Cached"
|
||||||
view_image = "Image"
|
view_image = "Image"
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@ save_settings_button = "Save Settings"
|
||||||
no_results = "No results found"
|
no_results = "No results found"
|
||||||
error_images = "Error fetching images"
|
error_images = "Error fetching images"
|
||||||
rate_limit = "Slow down! Too many searches from you!"
|
rate_limit = "Slow down! Too many searches from you!"
|
||||||
|
warning_fetch_error = "request failed before OmniSearch could read search results."
|
||||||
|
warning_parse_mismatch = "returned search results in a format OmniSearch could not parse."
|
||||||
|
warning_blocked = "returned a captcha or another blocking page instead of search results."
|
||||||
read_more = "Read More"
|
read_more = "Read More"
|
||||||
view_cached = "Cached"
|
view_cached = "Cached"
|
||||||
view_image = "Image"
|
view_image = "Image"
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,11 @@ int images_handler(UrlParams *params) {
|
||||||
|
|
||||||
char *locale = get_locale("en_uk");
|
char *locale = get_locale("en_uk");
|
||||||
beaker_set_locale(&ctx, locale);
|
beaker_set_locale(&ctx, locale);
|
||||||
free(locale);
|
|
||||||
|
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
||||||
|
if (!rate_limit_msg) rate_limit_msg = "Slow down! Too many image searches from you!";
|
||||||
|
const char *error_images_msg = beaker_get_locale_value(locale, "error_images");
|
||||||
|
if (!error_images_msg) error_images_msg = "Error fetching images";
|
||||||
|
|
||||||
context_set(&ctx, "page", page_str);
|
context_set(&ctx, "page", page_str);
|
||||||
context_set(&ctx, "prev_page", prev_str);
|
context_set(&ctx, "prev_page", prev_str);
|
||||||
|
|
@ -96,8 +100,7 @@ int images_handler(UrlParams *params) {
|
||||||
rate_limit_check("images", &rate_limit_config);
|
rate_limit_check("images", &rate_limit_config);
|
||||||
if (rate_limit_result.limited) {
|
if (rate_limit_result.limited) {
|
||||||
char response[256];
|
char response[256];
|
||||||
snprintf(response, sizeof(response),
|
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
||||||
"<h1>Slow down!</h1><p>Too many image searches from you!</p>");
|
|
||||||
send_response(response);
|
send_response(response);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
free(display_query);
|
free(display_query);
|
||||||
|
|
@ -115,7 +118,9 @@ int images_handler(UrlParams *params) {
|
||||||
|
|
||||||
if (scrape_images(raw_query, page, &results, &result_count) != 0 ||
|
if (scrape_images(raw_query, page, &results, &result_count) != 0 ||
|
||||||
!results) {
|
!results) {
|
||||||
send_response("<h1>Error fetching images</h1>");
|
char error_html[128];
|
||||||
|
snprintf(error_html, sizeof(error_html), "<h1>%s</h1>", error_images_msg);
|
||||||
|
send_response(error_html);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
free(display_query);
|
free(display_query);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
|
|
|
||||||
|
|
@ -296,15 +296,20 @@ static int add_warning_to_collection(const char *engine_name,
|
||||||
return current_count + 1;
|
return current_count + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *warning_message_for_job(const ScrapeJob *job) {
|
static const char *warning_message_for_job(const ScrapeJob *job, const char *locale) {
|
||||||
switch (job->status) {
|
switch (job->status) {
|
||||||
case SCRAPE_STATUS_FETCH_ERROR:
|
case SCRAPE_STATUS_FETCH_ERROR: {
|
||||||
return "request failed before OmniSearch could read search results.";
|
const char *msg = beaker_get_locale_value(locale, "warning_fetch_error");
|
||||||
case SCRAPE_STATUS_PARSE_MISMATCH:
|
return msg ? msg : "request failed before OmniSearch could read search results.";
|
||||||
return "returned search results in a format OmniSearch could not parse.";
|
}
|
||||||
case SCRAPE_STATUS_BLOCKED:
|
case SCRAPE_STATUS_PARSE_MISMATCH: {
|
||||||
return "returned a captcha or another blocking page instead of search "
|
const char *msg = beaker_get_locale_value(locale, "warning_parse_mismatch");
|
||||||
"results.";
|
return msg ? msg : "returned search results in a format OmniSearch could not parse.";
|
||||||
|
}
|
||||||
|
case SCRAPE_STATUS_BLOCKED: {
|
||||||
|
const char *msg = beaker_get_locale_value(locale, "warning_blocked");
|
||||||
|
return msg ? msg : "returned a captcha or another blocking page instead of search results.";
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -421,7 +426,11 @@ int results_handler(UrlParams *params) {
|
||||||
|
|
||||||
char *locale = get_locale("en_uk");
|
char *locale = get_locale("en_uk");
|
||||||
beaker_set_locale(&ctx, locale);
|
beaker_set_locale(&ctx, locale);
|
||||||
free(locale);
|
|
||||||
|
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
||||||
|
if (!rate_limit_msg) rate_limit_msg = "Slow down! Too many searches from you!";
|
||||||
|
const char *no_results_msg = beaker_get_locale_value(locale, "no_results");
|
||||||
|
if (!no_results_msg) no_results_msg = "No results found";
|
||||||
|
|
||||||
char page_str[16];
|
char page_str[16];
|
||||||
snprintf(page_str, sizeof(page_str), "%d", page);
|
snprintf(page_str, sizeof(page_str), "%d", page);
|
||||||
|
|
@ -518,8 +527,7 @@ int results_handler(UrlParams *params) {
|
||||||
rate_limit_check("search", &rate_limit_config);
|
rate_limit_check("search", &rate_limit_config);
|
||||||
if (rate_limit_result.limited) {
|
if (rate_limit_result.limited) {
|
||||||
char response[256];
|
char response[256];
|
||||||
snprintf(response, sizeof(response),
|
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
||||||
"<h1>Slow down!</h1><p>Too many searches from you!</p>");
|
|
||||||
send_response(response);
|
send_response(response);
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
|
|
@ -629,7 +637,9 @@ int results_handler(UrlParams *params) {
|
||||||
}
|
}
|
||||||
free(request_cache_key);
|
free(request_cache_key);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
send_response("<h1>No results found</h1>");
|
char no_results_html[128];
|
||||||
|
snprintf(no_results_html, sizeof(no_results_html), "<h1>%s</h1>", no_results_msg);
|
||||||
|
send_response(no_results_html);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -661,7 +671,7 @@ int results_handler(UrlParams *params) {
|
||||||
|
|
||||||
int warning_count = 0;
|
int warning_count = 0;
|
||||||
for (int i = 0; i < enabled_engine_count; i++) {
|
for (int i = 0; i < enabled_engine_count; i++) {
|
||||||
if (warning_message_for_job(&jobs[i]))
|
if (warning_message_for_job(&jobs[i], locale))
|
||||||
warning_count++;
|
warning_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -671,7 +681,7 @@ int results_handler(UrlParams *params) {
|
||||||
int warning_index = 0;
|
int warning_index = 0;
|
||||||
|
|
||||||
for (int i = 0; i < enabled_engine_count; i++) {
|
for (int i = 0; i < enabled_engine_count; i++) {
|
||||||
const char *warning_message = warning_message_for_job(&jobs[i]);
|
const char *warning_message = warning_message_for_job(&jobs[i], locale);
|
||||||
if (!warning_message)
|
if (!warning_message)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
@ -886,6 +896,7 @@ int results_handler(UrlParams *params) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(locale);
|
||||||
free_context(&ctx);
|
free_context(&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue