Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
locale: fix the locale selection for JS
  • Loading branch information
perexg committed Jun 23, 2015
1 parent cbef6f2 commit 1e7eca9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/tvh_locale.c
Expand Up @@ -37,8 +37,10 @@ const char *tvh_gettext_default_lang = NULL;
const char *tvh_gettext_last_lang = NULL;
const char **tvh_gettext_last_strings = NULL;

static const char *tvh_gettext_lang_check(const char *lang)
const char *tvh_gettext_get_lang(const char *lang)
{
if (lang == NULL || lang[0] == '\0')
return "en";
if (!strcmp(lang, "eng_US"))
return "en";
if (!strcmp(lang, "eng_GB"))
Expand Down Expand Up @@ -128,7 +130,7 @@ const char *tvh_gettext_lang(const char *lang, const char *s)
tvh_gettext_init();
lang = tvh_gettext_default_lang;
} else {
lang = tvh_gettext_lang_check(lang);
lang = tvh_gettext_get_lang(lang);
}
if (tvh_gettext_last_lang == NULL || strcmp(tvh_gettext_last_lang, lang)) {
tvh_gettext_new_lang(lang);
Expand Down
1 change: 1 addition & 0 deletions src/tvh_locale.h
Expand Up @@ -18,6 +18,7 @@
#ifndef __TVH_LOCALE_H__
#define __TVH_LOCALE_H__

const char *tvh_gettext_get_lang(const char *lang);
const char *tvh_gettext_lang(const char *lang, const char *s);
static inline const char *tvh_gettext(const char *s)
{ return tvh_gettext_lang(NULL, s); }
Expand Down
19 changes: 2 additions & 17 deletions src/webui/webui.c
Expand Up @@ -1402,21 +1402,6 @@ favicon(http_connection_t *hc, const char *remain, void *opaque)
return 0;
}

/**
*
*/
static const char *http_locale_lang(http_connection_t *hc)
{
const char *s = hc->hc_access->aa_lang;
if (s && s[0]) {
const lang_code_t *lc;
lc = lang_code_get3(s);
if (strcmp(lc->code2b, "und"))
return lc->code1;
}
return NULL;
}

/**
*
*/
Expand Down Expand Up @@ -1449,7 +1434,7 @@ http_redir(http_connection_t *hc, const char *remain, void *opaque)

if (nc == 1) {
if (!strcmp(components[0], "locale.js")) {
lang = http_locale_lang(hc);
lang = tvh_gettext_get_lang(hc->hc_access->aa_lang);
if (lang) {
snprintf(buf, sizeof(buf), "src/webui/static/intl/tvh.%s.js.gz", lang);
if (!http_file_test(buf)) {
Expand All @@ -1467,7 +1452,7 @@ http_redir(http_connection_t *hc, const char *remain, void *opaque)

if (nc >= 2) {
if (!strcmp(components[0], "docs")) {
lang = http_locale_lang(hc);
lang = tvh_gettext_get_lang(hc->hc_access->aa_lang);
snprintf(buf, sizeof(buf), "docs/html/%s/%s%s%s", lang, components[1],
nc > 2 ? "/" : "", nc > 2 ? components[1] : "");
if (http_file_test(buf)) lang = "en";
Expand Down

0 comments on commit 1e7eca9

Please sign in to comment.