diff options
author | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2007-08-19 18:00:00 +0200 |
---|---|---|
committer | Klaus Schmidinger <kls (at) cadsoft (dot) de> | 2007-08-19 18:00:00 +0200 |
commit | e5a2aa41c9762bda4ce7b987aba1bcfa1cee6f70 (patch) | |
tree | cb794be1f7796ccbfdd1ce04bca0d75d997ead0b /i18n.c | |
parent | 4c65b525dc1e3c62336b223d200a46fb30dc7e52 (diff) | |
download | vdr-patch-lnbsharing-e5a2aa41c9762bda4ce7b987aba1bcfa1cee6f70.tar.gz vdr-patch-lnbsharing-e5a2aa41c9762bda4ce7b987aba1bcfa1cee6f70.tar.bz2 |
Version 1.5.8vdr-1.5.8
- Added missing install-i18n to the install target in the Makefile (reported
by Joachim Wilke).
- Fixed a faulty comment in Make.config.template (reported by Marco Schlüßler).
- Improved i18n-to-gettext.pl (thanks to Matthias Schwarzott).
- Moved the "all" target in plugin Makefiles before the "Implicit rules",
so that a plain "make" will compile everything (suggested by Matthias
Schwarzott). The "newplugin" script has been changed accordingly.
Plugin authors may want to change their Makefiles, too.
- Added DESTDIR and PREFIX handling to the Makefile (thanks to Matthias
Schwarzott).
- Updated the Finnish OSD texts (thanks to Rolf Ahrenberg).
- Added internationalization to the "skincurses" plugin (thanks to Rolf
Ahrenberg).
- Checking the string for NULL in I18nTranslate().
- Updated the French OSD texts (thanks to Bruno Roussel).
- Some optimizations in cDvbDevice::SetChannelDevice() (thanks to Tobias Bratfisch).
- Optimized cMenuEditChrItem::Set() (thanks to Tobias Bratfisch).
- Optimized cNitFilter::Process() (thanks to Tobias Bratfisch).
- Reduced the number of time(NULL) calls in vdr.c's main loop to a single call
(thanks to Tobias Bratfisch).
- Changed cBitmap::DrawText() to always draw the background unless ColorBg
is clrTransparent (thanks to Christoph Haubrich).
- The "Setup/OSD/Language" menu now only shows those languages that actually
have a locale (suggested by Anssi Hannula).
- Now using setenv() instead of setlocale() to set the language for gettext()
(suggested by Anssi Hannula; thanks also to Ludwig Nussel for a hint on using
_nl_msg_cat_cntr).
- When scanning the locale directory, VDR now explicitly looks for a file named
vdr.mo. Text files for plugins are now named "vdr-name.mo", when "name" is the
name of the plugin. The "newplugin" script has been changed accordingly, and
plugin authors should change their Makefiles, too.
Diffstat (limited to 'i18n.c')
-rw-r--r-- | i18n.c | 40 |
1 files changed, 31 insertions, 9 deletions
@@ -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 <ctype.h> #include <libintl.h> #include <locale.h> +#include <unistd.h> #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) |