summaryrefslogtreecommitdiff
path: root/i18n.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2007-08-19 14:34:44 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2007-08-19 14:34:44 +0200
commit69db18ef8f5acf0006f36c3fc8cfcf6b75be0431 (patch)
tree4f412ce65786d5043fc0dbf7b08926cd70fa1eab /i18n.c
parentaebcc9d15cc76d38804d346fabe7c7b664e95db8 (diff)
downloadvdr-69db18ef8f5acf0006f36c3fc8cfcf6b75be0431.tar.gz
vdr-69db18ef8f5acf0006f36c3fc8cfcf6b75be0431.tar.bz2
Explicitly looking for vdr.mo; text files for plugins named 'vdr-name.mo'; revoked 'best match'1.5.8
Diffstat (limited to 'i18n.c')
-rw-r--r--i18n.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/i18n.c b/i18n.c
index 3818ea76..15853a0f 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.311 2007/08/18 09:08:45 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
@@ -91,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));
@@ -100,17 +108,15 @@ void I18nInitialize(void)
bindtextdomain("vdr", I18nLocaleDir);
cFileNameList Locales(I18nLocaleDir, true);
if (Locales.Size() > 0) {
- dsyslog("found %d locales in %s", Locales.Size(), I18nLocaleDir);
- int MatchFull = 0, MatchPartial = 0;
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)
- MatchFull = LanguageLocales.Size();
- else if (strncmp(OldLocale, Locales[i], 2) == 0)
- MatchPartial = LanguageLocales.Size();
+ CurrentLanguage = LanguageLocales.Size();
LanguageLocales.Append(strdup(Locales[i]));
LanguageNames.Append(strdup(gettext(LanguageName)));
const char *Code = gettext(LanguageCode);
@@ -122,15 +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!");
+ break;
+ }
}
}
- CurrentLanguage = MatchFull ? MatchFull : MatchPartial;
- setlocale(LC_MESSAGES, CurrentLanguage ? LanguageLocales[CurrentLanguage] : 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++) {
@@ -152,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)
@@ -161,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);