From e5a2aa41c9762bda4ce7b987aba1bcfa1cee6f70 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 19 Aug 2007 18:00:00 +0200 Subject: =?UTF-8?q?Version=201.5.8=20-=20Added=20missing=20install-i18n=20?= =?UTF-8?q?to=20the=20install=20target=20in=20the=20Makefile=20(reported?= =?UTF-8?q?=20=20=20by=20Joachim=20Wilke).=20-=20Fixed=20a=20faulty=20comm?= =?UTF-8?q?ent=20in=20Make.config.template=20(reported=20by=20Marco=20Schl?= =?UTF-8?q?=C3=BC=C3=9Fler).=20-=20Improved=20i18n-to-gettext.pl=20(thanks?= =?UTF-8?q?=20to=20Matthias=20Schwarzott).=20-=20Moved=20the=20"all"=20tar?= =?UTF-8?q?get=20in=20plugin=20Makefiles=20before=20the=20"Implicit=20rule?= =?UTF-8?q?s",=20=20=20so=20that=20a=20plain=20"make"=20will=20compile=20e?= =?UTF-8?q?verything=20(suggested=20by=20Matthias=20=20=20Schwarzott).=20T?= =?UTF-8?q?he=20"newplugin"=20script=20has=20been=20changed=20accordingly.?= =?UTF-8?q?=20=20=20Plugin=20authors=20may=20want=20to=20change=20their=20?= =?UTF-8?q?Makefiles,=20too.=20-=20Added=20DESTDIR=20and=20PREFIX=20handli?= =?UTF-8?q?ng=20to=20the=20Makefile=20(thanks=20to=20Matthias=20=20=20Schw?= =?UTF-8?q?arzott).=20-=20Updated=20the=20Finnish=20OSD=20texts=20(thanks?= =?UTF-8?q?=20to=20Rolf=20Ahrenberg).=20-=20Added=20internationalization?= =?UTF-8?q?=20to=20the=20"skincurses"=20plugin=20(thanks=20to=20Rolf=20=20?= =?UTF-8?q?=20Ahrenberg).=20-=20Checking=20the=20string=20for=20NULL=20in?= =?UTF-8?q?=20I18nTranslate().=20-=20Updated=20the=20French=20OSD=20texts?= =?UTF-8?q?=20(thanks=20to=20Bruno=20Roussel).=20-=20Some=20optimizations?= =?UTF-8?q?=20in=20cDvbDevice::SetChannelDevice()=20(thanks=20to=20Tobias?= =?UTF-8?q?=20Bratfisch).=20-=20Optimized=20cMenuEditChrItem::Set()=20(tha?= =?UTF-8?q?nks=20to=20Tobias=20Bratfisch).=20-=20Optimized=20cNitFilter::P?= =?UTF-8?q?rocess()=20(thanks=20to=20Tobias=20Bratfisch).=20-=20Reduced=20?= =?UTF-8?q?the=20number=20of=20time(NULL)=20calls=20in=20vdr.c's=20main=20?= =?UTF-8?q?loop=20to=20a=20single=20call=20=20=20(thanks=20to=20Tobias=20B?= =?UTF-8?q?ratfisch).=20-=20Changed=20cBitmap::DrawText()=20to=20always=20?= =?UTF-8?q?draw=20the=20background=20unless=20ColorBg=20=20=20is=20clrTran?= =?UTF-8?q?sparent=20(thanks=20to=20Christoph=20Haubrich).=20-=20The=20"Se?= =?UTF-8?q?tup/OSD/Language"=20menu=20now=20only=20shows=20those=20languag?= =?UTF-8?q?es=20that=20actually=20=20=20have=20a=20locale=20(suggested=20b?= =?UTF-8?q?y=20Anssi=20Hannula).=20-=20Now=20using=20setenv()=20instead=20?= =?UTF-8?q?of=20setlocale()=20to=20set=20the=20language=20for=20gettext()?= =?UTF-8?q?=20=20=20(suggested=20by=20Anssi=20Hannula;=20thanks=20also=20t?= =?UTF-8?q?o=20Ludwig=20Nussel=20for=20a=20hint=20on=20using=20=20=20=5Fnl?= =?UTF-8?q?=5Fmsg=5Fcat=5Fcntr).=20-=20When=20scanning=20the=20locale=20di?= =?UTF-8?q?rectory,=20VDR=20now=20explicitly=20looks=20for=20a=20file=20na?= =?UTF-8?q?med=20=20=20vdr.mo.=20Text=20files=20for=20plugins=20are=20now?= =?UTF-8?q?=20named=20"vdr-name.mo",=20when=20"name"=20is=20the=20=20=20na?= =?UTF-8?q?me=20of=20the=20plugin.=20The=20"newplugin"=20script=20has=20be?= =?UTF-8?q?en=20changed=20accordingly,=20and=20=20=20plugin=20authors=20sh?= =?UTF-8?q?ould=20change=20their=20Makefiles,=20too.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'i18n.c') diff --git a/i18n.c b/i18n.c index 1673e53..15853a0 100644 --- a/i18n.c +++ b/i18n.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: i18n.c 1.308 2007/08/12 12:15:29 kls Exp $ + * $Id: i18n.c 1.312 2007/08/19 14:10:46 kls Exp $ * * */ @@ -23,6 +23,7 @@ #include #include #include +#include #include "tools.h" // TRANSLATORS: The name of the language, as written natively @@ -67,6 +68,7 @@ static cStringList LanguageLocales; static cStringList LanguageNames; static cStringList LanguageCodes; +static int NumLocales = 1; static int CurrentLanguage = 0; static bool ContainsCode(const char *Codes, const char *Code) @@ -90,6 +92,13 @@ static const char *SkipContext(const char *s) return p ? p + 1 : s; } +static void SetEnvLanguage(const char *Locale) +{ + setenv("LANGUAGE", Locale, 1); + extern int _nl_msg_cat_cntr; + ++_nl_msg_cat_cntr; +} + void I18nInitialize(void) { LanguageLocales.Append(strdup(I18N_DEFAULT_LOCALE)); @@ -99,11 +108,13 @@ void I18nInitialize(void) bindtextdomain("vdr", I18nLocaleDir); cFileNameList Locales(I18nLocaleDir, true); if (Locales.Size() > 0) { - dsyslog("found %d locales in %s", Locales.Size(), I18nLocaleDir); char *OldLocale = strdup(setlocale(LC_MESSAGES, NULL)); for (int i = 0; i < Locales.Size(); i++) { - if (i < I18N_MAX_LANGUAGES - 1) { - if (setlocale(LC_MESSAGES, Locales[i])) { + cString FileName = cString::sprintf("%s/%s/LC_MESSAGES/vdr.mo", I18nLocaleDir, Locales[i]); + if (access(FileName, F_OK) == 0) { // found a locale with VDR texts + if (i < I18N_MAX_LANGUAGES - 1) { + SetEnvLanguage(Locales[i]); + NumLocales++; if (strstr(OldLocale, Locales[i]) == OldLocale) CurrentLanguage = LanguageLocales.Size(); LanguageLocales.Append(strdup(Locales[i])); @@ -117,12 +128,15 @@ void I18nInitialize(void) } LanguageCodes.Append(strdup(Code)); } + else { + esyslog("ERROR: too many locales - increase I18N_MAX_LANGUAGES!"); + break; + } } - else - esyslog("ERROR: too many locales - increase I18N_MAX_LANGUAGES!"); } - setlocale(LC_MESSAGES, OldLocale); + SetEnvLanguage(LanguageLocales[CurrentLanguage]); free(OldLocale); + dsyslog("found %d locales in %s", NumLocales - 1, I18nLocaleDir); } // Prepare any known language codes for which there was no locale: for (const char **lc = LanguageCodeList; *lc; lc++) { @@ -144,7 +158,8 @@ void I18nInitialize(void) void I18nRegister(const char *Plugin) { - bindtextdomain(Plugin, I18nLocaleDir); + cString Domain = cString::sprintf("vdr-%s", Plugin); + bindtextdomain(Domain, I18nLocaleDir); } void I18nSetLocale(const char *Locale) @@ -153,7 +168,7 @@ void I18nSetLocale(const char *Locale) int i = LanguageLocales.Find(Locale); if (i >= 0) { CurrentLanguage = i; - setlocale(LC_MESSAGES, Locale); + SetEnvLanguage(Locale); } else dsyslog("unknown locale: '%s'", Locale); @@ -173,6 +188,11 @@ void I18nSetLanguage(int Language) } } +int I18nNumLanguagesWithLocale(void) +{ + return NumLocales; +} + const cStringList *I18nLanguages(void) { return &LanguageNames; @@ -180,6 +200,8 @@ const cStringList *I18nLanguages(void) const char *I18nTranslate(const char *s, const char *Plugin) { + if (!s) + return s; if (CurrentLanguage) { const char *t = s; if (Plugin) -- cgit v1.2.3