1
//Please refer to http://dansguardian.org/?page=copyright
2
//for the license for this code.
3
//Written by Daniel Barron (daniel@//jadeb/.com).
4
//For support go to http://groups.yahoo.com/group/dansguardian
6
// This program 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.
11
// This program 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.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include "LanguageContainer.hpp"
40
extern bool is_daemonised;
45
// wipe loaded language file
46
void LanguageContainer::reset()
52
// look for the translated string corresponding to the given key
53
const char *LanguageContainer::getTranslation(const unsigned int index)
57
for (i = 0; i < s; i++) {
58
if (keys[i] == index) {
59
return values[i].toCharArray();
62
return "MISSING TRANSLATION KEY";
65
// open a language file, containing message names (keys) and translated messages (values)
66
bool LanguageContainer::readLanguageList(const char *filename)
68
std::string linebuffer; // a string line buffer ;)
72
ifstream languagefile(filename, ios::in); // open the file for reading
73
if (!languagefile.good()) {
75
std::cerr << "Error opening messages file (does it exist?): " << filename << std::endl;
77
syslog(LOG_ERR, "%s", "Error opening messages file (does it exist?): ");
78
syslog(LOG_ERR, "%s", filename);
81
while (!languagefile.eof()) { // keep going until end of file
82
getline(languagefile, linebuffer); // grab a line
83
if (linebuffer.length() == 0) {
86
line = linebuffer.c_str();
87
k = line.after("\"").before("\",\"").toInteger();
88
v = line.after("\",\"").before("\"");
89
if (k > 0 && v.length() > 0) {
95
return true; // successful read