2 * i18n.c: Internationalization
4 * This code is taken from the VDR project and modified for VOMP.
5 * See the main source file 'vdr.c' for original copyright information.
6 * Modifications (C) 2005 D Pickles.
8 This file is part of VOMP.
10 VOMP is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 VOMP is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with VOMP; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "language-data.h"
28 int I18n::LanguageID = DEFAULT_LANGUAGE_INDEX;
30 int I18n::initialize(void)
32 VDR *vdr = VDR::getInstance();
33 char *lang = vdr->configLoad("General", "Language");
36 LanguageID = LanguageIndex(lang);
45 LanguageID = DEFAULT_LANGUAGE_INDEX;
50 char* I18n::translate(char* s)
54 const tI18nPhrase *p = Phrases;
55 for (int i = ((p == Phrases) ? 1 : 2); i--; )
59 if (strcmp(s, **p) == 0)
61 char *t = (*p)[LanguageID];
62 if (t && *t) return t;
67 Log::getInstance()->log("I18n", Log::ERR, "No translation found for '%s' in language %d (%s)",
68 s, LanguageID, LanguageName(LanguageID));
71 char *p = strchr(s, '$');
75 const char* const * I18n::CharSets(void)
80 const char* const I18n::LanguageCode(int Index)
82 return 0 <= Index && Index < NumLanguages ? languageCodes[Index] : NULL;
85 const char* I18n::LanguageName(int Index)
87 return 0 <= Index && Index < NumLanguages ? Languages[Index] : NULL;
90 int I18n::LanguageIndex(const char* Name)
92 for (int i = 0; i < NumLanguages; i++)
94 if (STRCASESTR(Languages[i], Name)) return i;
96 Log::getInstance()->log("I18n", Log::ERR, "Unknown language: '%s'", Name);
100 int I18n::GetNumLanguages(void)