mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
Explicitly looking for vdr.mo; text files for plugins named 'vdr-name.mo'; revoked 'best match'
This commit is contained in:
39
i18n.c
39
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);
|
||||
|
Reference in New Issue
Block a user