2 * i18n.c: Internationalization
\r
4 * This code is taken from the VDR project and modified for VOMP.
\r
5 * See the main source file 'vdr.c' for original copyright information.
\r
6 * Modifications (C) 2005 D Pickles.
\r
8 This file is part of VOMP.
\r
10 VOMP is free software; you can redistribute it and/or modify
\r
11 it under the terms of the GNU General Public License as published by
\r
12 the Free Software Foundation; either version 2 of the License, or
\r
13 (at your option) any later version.
\r
15 VOMP is distributed in the hope that it will be useful,
\r
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
18 GNU General Public License for more details.
\r
20 You should have received a copy of the GNU General Public License
\r
21 along with VOMP; if not, write to the Free Software
\r
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
26 * How to add a new language:
\r
28 * 1. Announce your translation action on the VOMP mailing
\r
29 * list to avoid duplicate work.
\r
30 * 2. Increase the value of 'NUM_LANGUAGES' in i18n.h.
\r
31 * 3. Insert a new line in the 'Languages' array containing the name of your
\r
32 * language IN YOUR LANGUAGE, so 'Italiano' not 'Italian' for example.
\r
33 * Append your language after the last existing language
\r
34 * but before the 'test' language
\r
35 * 4. Insert a new line in the charSets array containing the name of the character
\r
36 * set needed for your language. Note that at present only ISO8859-1 is
\r
38 * 5. Insert a new line in the languageCodes array containing the 3-letter
\r
39 * abbreviation(s) for your language as used in the channels.conf.
\r
40 * 6. Insert a line in evry member of the 'Phrases[]' array,
\r
41 * containing the translated text for your language. You can use the 'test'
\r
42 * language to see where the phrases appear on the screen.
\r
43 * 7. Add the name of your language to the i18nLanguages array in voptions.h.
\r
44 * 8. If your language requires a character set other than the default iso8859-1
\r
45 * then work will be needed elsewhere in vomp to manage multiple font files.
\r
46 * 9. Compile VOMP and test the new language by switching to it
\r
47 * in the "Options" menu.
\r
48 *10. Send the modified files to Chris to have it included in the next version.
\r
50 * In case an English phrase is used in more than one context (and might need
\r
51 * different translations in other languages) it can be preceeded with an
\r
52 * arbitrary string to describe its context, separated from the actual phrase
\r
53 * by a '$' character (see for instance "Button$Stop" vs. "Stop").
\r
54 * Of course this means that no English phrase may contain the '$' character!
\r
55 * If this should ever become necessary, the existing '$' would have to be
\r
56 * replaced with something different...
\r
63 // The names of the languages (English MUST be first!):
\r
64 static char *Languages[] =
\r
69 // The character set needed for each language:
\r
70 const static char *charSets[] =
\r
75 // The 3-letter names of the language (this MUST be the third phrase!):
\r
76 const char *languageCodes[] =
\r
81 // The phrases to be translated:
\r
83 const static tI18nPhrase Phrases[] = {
\r
113 { "\n Downloading recordings list",
\r
117 { "Recordings - %s",
\r
129 { "%lu%% used, %iGB free",
\r
132 { "%i to %i of %i", // Also used in channels list
\r
143 { "Programme menu",
\r
158 { "Programme summary",
\r
161 { "Summary unavailable",
\r
164 { "Delete recording",
\r
167 { "Are you sure you want to delete this recording?",
\r
171 { "Choose a VDR server",
\r
179 { "TV connection type",
\r
182 { "Remote control type",
\r
185 { "TV aspect ratio",
\r
188 { "16:9 on 4:3 display mode",
\r
191 { "Power state after bootup",
\r
194 { "Display channels",
\r
200 { "Press back to exit, <, > or [ok] to change",
\r
203 { "VDR-Pri 0=OK !See forums!",
\r
245 { "Radio Stations",
\r
249 { "No channel data available",
\r
258 { "\n Channel unavailable",
\r
262 { "\n Locating server",
\r
265 { "\n Connecting to VDR",
\r
268 { "\n Login failed",
\r
271 { "\n Connection failed",
\r
275 { "\n Connected, loading config",
\r
282 static int LanguageID = INITIAL_LANGUAGE_INDEX;
\r
285 int I18n::Initialize(void) {
\r
287 VDR *vdr = VDR::getInstance();
\r
288 char *lang = vdr->configLoad("General", "Language");
\r
290 LanguageID = LanguageIndex(lang);
\r
291 if (LanguageID == -1) {
\r
296 LanguageID = LanguageIndex(INITIAL_LANGUAGE);
\r
301 char *I18n::Translate(char *s)
\r
303 if (LanguageID >= 0) {
\r
304 const tI18nPhrase *p = Phrases;
\r
305 for (int i = ((p == Phrases) ? 1 : 2); i--; ) {
\r
307 if (strcmp(s, **p) == 0) {
\r
308 char *t = (*p)[LanguageID];
\r
309 if (t && *t) return t;
\r
314 Log::getInstance()->log("I18n", Log::ERR, "no translation found for '%s' in language %d (%s)\n",
\r
315 s, LanguageID, LanguageName(LanguageID));
\r
317 char *p = strchr(s, '$');
\r
318 return p ? p + 1 : s;
\r
321 const char * const * I18n::CharSets(void)
\r
326 const char * I18n::LanguageCode(int Index)
\r
328 return 0 <= Index && Index < I18nNumLanguages ? languageCodes[Index] : NULL;
\r
331 char * I18n::LanguageName(int Index)
\r
333 return 0 <= Index && Index < I18nNumLanguages ? Languages[Index] : NULL;
\r
336 int I18n::LanguageIndex(const char *Name)
\r
338 for (int i = 0; i < I18nNumLanguages; i++) {
\r
339 if (strcasestr(Languages[i], Name))
\r
342 Log::getInstance()->log("I18n", Log::ERR, "unknown language: '%s'", Name);
\r
346 int I18n::GetNumLanguages(void) {
\r
347 return I18nNumLanguages;
\r