79 for ( ; l < 3 && Code[l]; l++) {
80 if (Codes[l] != tolower(Code[l]))
92 const char *p = strchr(s,
'$');
98 setenv(
"LANGUAGE", Locale, 1);
99 extern int _nl_msg_cat_cntr;
105 I18nLocaleDir = LocaleDir;
110 bindtextdomain(
"vdr", I18nLocaleDir);
112 if (Locales.
Size() > 0) {
113 char *OldLocale = strdup(setlocale(LC_MESSAGES, NULL));
114 for (
int i = 0; i < Locales.
Size(); i++) {
116 if (access(FileName, F_OK) == 0) {
119 const char *TranslatedLanguageName = gettext(
LanguageName);
122 if (strstr(OldLocale, Locales[i]) == OldLocale)
124 LanguageLocales.
Append(strdup(Locales[i]));
125 LanguageNames.
Append(strdup(TranslatedLanguageName));
133 LanguageCodes.
Append(strdup(Code));
137 esyslog(
"ERROR: too many locales - increase I18N_MAX_LANGUAGES!");
149 for (
int i = 0; i < LanguageCodes.
Size(); i++) {
150 if (strcmp(*lc, LanguageCodes[i]) == 0) {
156 dsyslog(
"no locale for language code '%s'", *lc);
158 LanguageNames.
Append(strdup(*lc));
159 LanguageCodes.
Append(strdup(*lc));
167 bindtextdomain(Domain, I18nLocaleDir);
172 if (Locale && *Locale) {
173 int i = LanguageLocales.
Find(Locale);
179 dsyslog(
"unknown locale: '%s'", Locale);
190 if (Language < LanguageNames.
Size()) {
211 const char *t = Plugin ? dgettext(Plugin, s) : gettext(s);
220 return 0 <= Language && Language < LanguageLocales.
Size() ? LanguageLocales[Language] : NULL;
225 return 0 <= Language && Language < LanguageCodes.
Size() ? LanguageCodes[Language] : NULL;
230 for (
int i = 0; i < LanguageCodes.
Size(); i++) {
240 for (
int i = 0; i < 3; i++) {
253 if (!isprint(Code[i])) {
260 *((
char *)&Code[i]) =
'_';
273 while (LanguageCode) {
275 for (
int i = 0; i < LanguageCodes.
Size(); i++) {
276 if (PreferredLanguages[i] < 0)
278 if (PreferredLanguages[i] == LanguageIndex) {
279 if (OldPreference < 0 || i < OldPreference) {
288 if ((LanguageCode = strchr(LanguageCode,
'+')) != NULL) {
292 else if (pos == 1 && Position)
295 if (OldPreference < 0) {
296 OldPreference = LanguageCodes.
Size();
int Find(const char *s) const
int I18nCurrentLanguage(void)
Returns the index of the current language.
#define I18N_MAX_LANGUAGES
static const char * SkipContext(const char *s)
const char * LanguageCodeList[]
static cString sprintf(const char *fmt,...) __attribute__((format(printf
virtual void Append(T Data)
static cStringList LanguageCodes
void I18nSetLocale(const char *Locale)
Sets the current locale to Locale.
static int CurrentLanguage
const char * I18nLocale(int Language)
Returns the locale code of the given Language (which is an index as returned by I18nCurrentLanguage()...
const char * LanguageCode
#define I18N_DEFAULT_LOCALE
static void SetEnvLanguage(const char *Locale)
const char * I18nTranslate(const char *s, const char *Plugin)
Translates the given string (with optional Plugin context) into the current language.
void I18nRegister(const char *Plugin)
Registers the named plugin, so that it can use internationalized texts.
const char * I18nLanguageCode(int Language)
Returns the three letter language code of the given Language (which is an index as returned by I18nCu...
bool I18nIsPreferredLanguage(int *PreferredLanguages, const char *LanguageCode, int &OldPreference, int *Position)
Checks the given LanguageCode (which may be something like "eng" or "eng+deu") against the PreferredL...
static cString I18nLocaleDir
const cStringList * I18nLanguages(void)
Returns the list of available languages.
static cStringList LanguageLocales
int I18nNumLanguagesWithLocale(void)
Returns the number of entries in the list returned by I18nLanguages() that actually have a locale...
void I18nSetLanguage(int Language)
Sets the current language index to Language.
int I18nLanguageIndex(const char *Code)
Returns the index of the language with the given three letter language Code.
static bool ContainsCode(const char *Codes, const char *Code)
static cStringList LanguageNames
const char * I18nNormalizeLanguageCode(const char *Code)
Returns a 3 letter language code that may not be zero terminated.
void I18nInitialize(const char *LocaleDir)
Detects all available locales and loads the language names and codes.
const char * LanguageName