Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
intl: add en_GB and bg - fix language selector (ACL)
  • Loading branch information
perexg committed Jun 22, 2015
1 parent 88cace2 commit d93afc9
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Makefile
Expand Up @@ -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
Expand Down Expand Up @@ -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,$@,$<)

Expand All @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion Makefile.webui
Expand Up @@ -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),)
Expand Down Expand Up @@ -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,$@,$<)

Expand All @@ -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,$@,$<)

Expand All @@ -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,\
Expand Down
2 changes: 1 addition & 1 deletion src/access.c
Expand Up @@ -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;
}

Expand Down
40 changes: 39 additions & 1 deletion src/api/api_language.c
Expand Up @@ -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 },
};
Expand Down
2 changes: 1 addition & 1 deletion src/lang_codes.c
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions src/lang_codes.h
Expand Up @@ -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[];
Expand Down
10 changes: 10 additions & 0 deletions src/tvh_locale.c
Expand Up @@ -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"))
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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";
Expand Down

0 comments on commit d93afc9

Please sign in to comment.