]> git.vomp.tv Git - vompclient.git/blob - i18n.cc
FSF address change
[vompclient.git] / i18n.cc
1 /*
2     Copyright 2007 Mark Calderbank
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "i18n.h"
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <glob.h>
26
27 #include "vdr.h"
28 #include "log.h"
29
30 using namespace std;
31 I18n::trans_table I18n::Translations;
32
33 int I18n::initialize(void)
34 {
35   VDR *vdr = VDR::getInstance();
36   char *lang = vdr->configLoad("General", "LangCode");
37   lang_code_list list = vdr->getLanguageList();
38   string code;
39   if (lang && list.count(lang) > 0)
40     code = lang;
41   else
42   {
43     // There is no LangCode in the config file, or the selected
44     // language isn't available on the server.
45     // Use 'en' if it exists on the server or if no languages
46     // are available. Otherwise use the first available language.
47     if (list.count("en") > 0 || list.empty())
48       code = "en";
49     else
50       code = list.begin()->first;
51     vdr->configSave("General", "LangCode", code.c_str());
52   }
53   vdr->getLanguageContent(code, Translations);
54   return 1;
55 }
56
57 const char* I18n::translate(const char *s)
58 {
59   string str = s;
60   if (Translations.count(str) == 0) return s;
61   return Translations[str].c_str();
62   // This isn't ideal. A call to initialize() invalidates
63   // the c_str(), so we need to make sure that no return
64   // values from this function are expected to remain
65   // valid after an initialize().
66 }