From: Jaroslav Kysela Date: Mon, 22 Jun 2015 07:34:49 +0000 (+0200) Subject: intl: add en_GB and bg - fix language selector (ACL) X-Git-Tag: v4.2.1~2277 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d93afc920c2bfb0cbea221e788ceddcfae3d0872;p=thirdparty%2Ftvheadend.git intl: add en_GB and bg - fix language selector (ACL) --- diff --git a/Makefile b/Makefile index d4ad82038..5b7e2353f 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ include $(dir $(lastword $(MAKEFILE_LIST))).config.mk PROG := $(BUILDDIR)/tvheadend -LANGUAGES ?= de fr cs pl +LANGUAGES ?= en_GB de fr cs pl bg # # Common compiler flags @@ -578,6 +578,9 @@ intl: intl/tvheadend.pot: +intl/tvheadend.en_GB.po: intl/tvheadend.pot + $(call merge-po,$@,$<) + intl/tvheadend.de.po: intl/tvheadend.pot $(call merge-po,$@,$<) @@ -590,6 +593,9 @@ intl/tvheadend.cs.po: intl/tvheadend.pot intl/tvheadend.pl.po: intl/tvheadend.pot $(call merge-po,$@,$<) +intl/tvheadend.bg.po: intl/tvheadend.pot + $(call merge-po,$@,$<) + $(BUILDDIR)/src/tvh_locale.o: src/tvh_locale_inc.c src/tvh_locale_inc.c: $(PO-FILES) @printf "Building $@\n" diff --git a/Makefile.webui b/Makefile.webui index 2b5ca2ddf..85fe286cc 100644 --- a/Makefile.webui +++ b/Makefile.webui @@ -22,7 +22,7 @@ IAM=$(lastword $(MAKEFILE_LIST)) WEBDIR ?= src/webui -LANGUAGES ?= de fr cs pl +LANGUAGES ?= en_GB de fr cs pl bg ROOTPATH = static ifneq ($(WEBUI),) @@ -253,6 +253,9 @@ intl: intl/js/tvheadend.js.pot: +intl/js/tvheadend.js.en_GB.po: intl/js/tvheadend.js.pot + $(call merge-po,$@,$<) + intl/js/tvheadend.js.de.po: intl/js/tvheadend.js.pot $(call merge-po,$@,$<) @@ -265,6 +268,12 @@ intl/js/tvheadend.js.cs.po: intl/js/tvheadend.js.pot intl/js/tvheadend.js.pl.po: intl/js/tvheadend.js.pot $(call merge-po,$@,$<) +intl/js/tvheadend.js.bg.po: intl/js/tvheadend.js.pot + $(call merge-po,$@,$<) + +src/webui/static/intl/tvh.en_GB.js.gz: intl/js/tvheadend.js.en_GB.po + $(call go-po,$@,$<) + src/webui/static/intl/tvh.de.js.gz: intl/js/tvheadend.js.de.po $(call go-po,$@,$<) @@ -277,6 +286,9 @@ src/webui/static/intl/tvh.cs.js.gz: intl/js/tvheadend.js.cs.po src/webui/static/intl/tvh.pl.js.gz: intl/js/tvheadend.js.pl.po $(call go-po,$@,$<) +src/webui/static/intl/tvh.bg.js.gz: intl/js/tvheadend.js.bg.po + $(call go-po,$@,$<) + .PHONY: clean: rm -f $(foreach f,tvh.js tvh.css tvh-tv.js tvh-tv.css,\ diff --git a/src/access.c b/src/access.c index f657ee879..7c91bf8aa 100644 --- a/src/access.c +++ b/src/access.c @@ -1261,7 +1261,7 @@ language_get_list ( void *obj, const char *lang ) { htsmsg_t *m = htsmsg_create_map(); htsmsg_add_str(m, "type", "api"); - htsmsg_add_str(m, "uri", "language/list"); + htsmsg_add_str(m, "uri", "language/locale"); return m; } diff --git a/src/api/api_language.c b/src/api/api_language.c index 6dd697b15..874dceb49 100644 --- a/src/api/api_language.c +++ b/src/api/api_language.c @@ -45,11 +45,49 @@ api_language_enum return 0; } +static int +api_language_locale_enum + ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) +{ + const lang_code_t *c = lang_codes; + htsmsg_t *l, *e; + const char *s; + char buf1[8]; + char buf2[128]; + + l = htsmsg_create_list(); + while (c->code2b) { + e = htsmsg_create_map(); + htsmsg_add_str(e, "key", c->code2b); + htsmsg_add_str(e, "val", c->desc); + htsmsg_add_msg(l, NULL, e); + s = c->locale; + while (s && *s) { + if (*s == '|') + s++; + if (s[0] == '\0' || s[1] == '\0') + break; + snprintf(buf1, sizeof(buf1), "%s_%c%c", c->code2b, s[0], s[1]); + snprintf(buf2, sizeof(buf2), "%s (%c%c)", c->desc, s[0], s[1]); + e = htsmsg_create_map(); + htsmsg_add_str(e, "key", buf1); + htsmsg_add_str(e, "val", buf2); + htsmsg_add_msg(l, NULL, e); + s += 2; + } + c++; + } + *resp = htsmsg_create_map(); + htsmsg_add_msg(*resp, "entries", l); + return 0; +} + void api_language_init ( void ) { static api_hook_t ah[] = { - { "language/list", ACCESS_ANONYMOUS, api_language_enum, NULL }, + { "language/list", ACCESS_ANONYMOUS, api_language_enum, NULL }, + { "language/locale", ACCESS_ANONYMOUS, api_language_locale_enum, NULL }, { NULL }, }; diff --git a/src/lang_codes.c b/src/lang_codes.c index 707e09973..b56d487e7 100644 --- a/src/lang_codes.c +++ b/src/lang_codes.c @@ -145,7 +145,7 @@ const lang_code_t lang_codes[] = { { "egy", NULL, NULL , "Egyptian (Ancient)" }, { "eka", NULL, NULL , "Ekajuk" }, { "elx", NULL, NULL , "Elamite" }, - { "eng", "en", NULL , "English" }, + { "eng", "en", NULL , "English", "US|GB" }, { "epo", "eo", NULL , "Esperanto" }, { "est", "et", NULL , "Estonian" }, { "ewe", "ee", NULL , "Ewe" }, diff --git a/src/lang_codes.h b/src/lang_codes.h index ffdf0a457..d036d5eee 100644 --- a/src/lang_codes.h +++ b/src/lang_codes.h @@ -27,6 +27,7 @@ typedef struct lang_code const char *code1; ///< ISO 639-1 const char *code2t; ///< ISO 639-2 T const char *desc; ///< Description + const char *locale; ///< Locale variants (like US|GB or DE|BE) } lang_code_t; extern const lang_code_t lang_codes[]; diff --git a/src/tvh_locale.c b/src/tvh_locale.c index 0500c7d23..716ed5f01 100644 --- a/src/tvh_locale.c +++ b/src/tvh_locale.c @@ -39,6 +39,10 @@ const char **tvh_gettext_last_strings = NULL; static const char *tvh_gettext_lang_check(const char *lang) { + if (!strcmp(lang, "eng_US")) + return "en"; + if (!strcmp(lang, "eng_GB")) + return "en_GB"; if (!strcmp(lang, "ger")) return "de"; if (!strcmp(lang, "fre")) @@ -47,6 +51,8 @@ static const char *tvh_gettext_lang_check(const char *lang) return "cs"; if (!strcmp(lang, "pol")) return "pl"; + if (!strcmp(lang, "bul")) + return "bg"; return lang; } @@ -114,6 +120,7 @@ static void tvh_gettext_new_lang(const char *lang) const char *tvh_gettext_lang(const char *lang, const char *s) { const char **strings; + static char unklng[8]; pthread_mutex_lock(&tvh_gettext_mutex); if (lang == NULL) { @@ -129,6 +136,9 @@ const char *tvh_gettext_lang(const char *lang, const char *s) if (tvh_gettext_default_lang == NULL) tvh_gettext_init(); tvh_gettext_new_lang(tvh_gettext_default_lang); + strncpy(unklng, lang, sizeof(unklng)); + unklng[sizeof(unklng)-1] = '\0'; + tvh_gettext_last_lang = unklng; } else { if (tvh_gettext_last_lang == NULL) tvh_gettext_last_lang = "en";