]> git.vomp.tv Git - vompclient.git/blob - i18n.cc
I18n
[vompclient.git] / i18n.cc
1 /*\r
2  * i18n.c: Internationalization\r
3  *\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
7 \r
8      This file is part of VOMP.\r
9 \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
14 \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
19 \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
23 */\r
24 \r
25 /*\r
26  * How to add a new language:\r
27  *\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
37  *    supported\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
49  *\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
57  */\r
58 \r
59 #include "i18n.h"\r
60 #include "log.h"\r
61 #include "vdr.h"\r
62 \r
63   // The names of the languages (English MUST be first!):\r
64 static char *Languages[] =\r
65   { "English",\r
66     "Test"\r
67   };\r
68 \r
69   // The character set needed for each language:\r
70 const static char *charSets[] =\r
71   { "iso8859-1",\r
72     "iso8859-1"\r
73   };\r
74 \r
75   // The 3-letter names of the language (this MUST be the third phrase!):\r
76 const char *languageCodes[] =\r
77   { "eng,dos",\r
78     "tst,xxx"\r
79   };\r
80 \r
81   // The phrases to be translated:\r
82 \r
83 const static tI18nPhrase Phrases[] = {\r
84   // Menu titles:\r
85   { "VDR",\r
86     "VDR",\r
87   },\r
88   { "Schedule",\r
89     "0",\r
90   },\r
91   // Welcome screen\r
92   { "Welcome",\r
93     "1",\r
94   },\r
95   { "1. Live TV",\r
96     "2",\r
97   },\r
98   { "2. Radio",\r
99     "3",\r
100   },\r
101   { "3. Recordings",\r
102     "4",\r
103   },\r
104   { "4. Options",\r
105     "5",\r
106   },\r
107   { "5. Stand by",\r
108     "6",\r
109   },\r
110   { "6. Reboot",\r
111     "7",\r
112   },\r
113   { "\n                  Downloading recordings list",\r
114     "8",\r
115   },\r
116   // Recordings list\r
117   { "Recordings - %s",\r
118     "9 - %s",\r
119   },\r
120   { "Recordings",\r
121     "10",\r
122   },\r
123   { "<dir> %lu\t%s",\r
124     "11 %lu\t%s",\r
125   },\r
126   { "[ok] = menu",\r
127     "12",\r
128   },\r
129   { "%lu%% used, %iGB free",\r
130     "13 %lu%% %i",\r
131   },\r
132   { "%i to %i of %i", // Also used in channels list\r
133     "14 %i %i %i",\r
134   },\r
135   // Question\r
136   { "Yes",\r
137     "15",\r
138   },\r
139   { "No",\r
140     "16",\r
141   },\r
142   // Recording Menu\r
143   { "Programme menu",\r
144     "17",\r
145   },\r
146   { "Play",\r
147     "18",\r
148   },\r
149   { "Resume",\r
150     "19",\r
151   },\r
152   { "Summary",\r
153     "20",\r
154   },\r
155   { "Delete",\r
156     "21",\r
157   },\r
158   { "Programme summary",\r
159     "22",\r
160   },\r
161   { "Summary unavailable",\r
162     "23",\r
163   },\r
164   { "Delete recording",\r
165     "24",\r
166   },\r
167   { "Are you sure you want to delete this recording?",\r
168     "25",\r
169   },\r
170   // Server select\r
171   { "Choose a VDR server",\r
172     "26",\r
173   },\r
174 \r
175   // Option menus\r
176   { "Options",\r
177     "27",\r
178   },\r
179   { "TV connection type",\r
180     "28",\r
181   },\r
182   { "Remote control type",\r
183     "29",\r
184   },\r
185   { "TV aspect ratio",\r
186     "30",\r
187   },\r
188   { "16:9 on 4:3 display mode",\r
189     "30a",\r
190   },\r
191   { "Power state after bootup",\r
192     "31",\r
193   },\r
194   { "Display channels",\r
195     "32",\r
196   },\r
197   { "Language",\r
198     "33",\r
199   },\r
200   { "Press back to exit, <, > or [ok] to change",\r
201     "34",\r
202   },\r
203   { "VDR-Pri 0=OK !See forums!",\r
204     "34a",\r
205   },\r
206   // Option choices\r
207   { "Old",\r
208     "35",\r
209   },\r
210   { "New",\r
211     "36",\r
212   },\r
213   { "RGB+composite",\r
214     "37",\r
215   },\r
216   { "S-Video",\r
217     "38",\r
218   },\r
219   { "Chop sides",\r
220     "39",\r
221   },\r
222   { "Letterbox",\r
223     "40",\r
224   },\r
225   { "Last state",\r
226     "41",\r
227   },\r
228   { "All",\r
229     "42",\r
230   },\r
231   { "FTA only",\r
232     "43",\r
233   },\r
234   { "On",\r
235     "44",\r
236   },\r
237   { "Off",\r
238     "45",\r
239   },\r
240 \r
241   // Channel Lists\r
242   { "Channels",\r
243     "46",\r
244   },\r
245   { "Radio Stations",\r
246     "47",\r
247   },\r
248   // Banners\r
249   { "No channel data available",\r
250     "48",\r
251   },\r
252   { "info",\r
253     "49",\r
254   },\r
255   { "info",\r
256     "50",\r
257   },\r
258   { "\n                    Channel unavailable",\r
259     "51",\r
260   },\r
261   // Connect screen\r
262   { "\n                        Locating server",\r
263     "52",\r
264   },\r
265   { "\n                     Connecting to VDR",\r
266     "53",\r
267   },\r
268   { "\n                           Login failed",\r
269     "54",\r
270   },\r
271   { "\n                      Connection failed",\r
272     "55",\r
273   },\r
274   // Command\r
275   { "\n               Connected, loading config",\r
276     "56",\r
277   },\r
278   // End marker.\r
279   { NULL }\r
280   };\r
281 \r
282   static int LanguageID = INITIAL_LANGUAGE_INDEX;\r
283 \r
284 \r
285 int I18n::Initialize(void) {\r
286 \r
287   VDR *vdr = VDR::getInstance();\r
288   char *lang = vdr->configLoad("General", "Language");\r
289   if (lang) {\r
290     LanguageID = LanguageIndex(lang);\r
291     if (LanguageID == -1) {\r
292       LanguageID = 0;\r
293     }\r
294   }\r
295   else {\r
296     LanguageID = LanguageIndex(INITIAL_LANGUAGE);\r
297   }\r
298   return LanguageID;\r
299 }\r
300 \r
301 char *I18n::Translate(char *s)\r
302 {\r
303   if (LanguageID >= 0) {\r
304      const tI18nPhrase *p = Phrases;\r
305      for (int i = ((p == Phrases) ? 1 : 2); i--; ) {\r
306          for (; **p; p++) {\r
307              if (strcmp(s, **p) == 0) {\r
308                 char *t = (*p)[LanguageID];\r
309                 if (t && *t) return t;\r
310              }\r
311          }\r
312          p = Phrases;\r
313      }\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
316   }\r
317   char *p = strchr(s, '$');\r
318   return p ? p + 1 : s;\r
319 }\r
320 \r
321 const char * const * I18n::CharSets(void)\r
322 {\r
323   return charSets;\r
324 }\r
325 \r
326 const char * I18n::LanguageCode(int Index)\r
327 {\r
328   return 0 <= Index && Index < I18nNumLanguages ? languageCodes[Index] : NULL;\r
329 }\r
330 \r
331 char * I18n::LanguageName(int Index)\r
332 {\r
333   return 0 <= Index && Index < I18nNumLanguages ? Languages[Index] : NULL;\r
334 }\r
335 \r
336 int I18n::LanguageIndex(const char *Name)\r
337 {\r
338   for (int i = 0; i < I18nNumLanguages; i++) {\r
339       if (strcasestr(Languages[i], Name))\r
340          return i;\r
341   }\r
342   Log::getInstance()->log("I18n", Log::ERR, "unknown language: '%s'", Name);\r
343   return -1;\r
344 }\r
345 \r
346 int I18n::GetNumLanguages(void) {\r
347   return I18nNumLanguages;\r
348 }\r
349 \r