#include "tinygettext.hpp"
#include "log.hpp"
#include "physfs/physfs_stream.hpp"
-#include <unison/vfs/FileSystem.hpp>
-#include "log.hpp"
#include "findlocale.hpp"
//#define TRANSLATION_DEBUG
char c = ' ';
while(in.good() && !in.eof()) {
- while(isspace(c) && !in.eof())
+ while(isspace(static_cast<unsigned char>(c)) && !in.eof())
in.get(c);
if(c == '#') { // skip comments
}
std::string alias;
- while(!isspace(c) && !in.eof()) {
+ while(!isspace(static_cast<unsigned char>(c)) && !in.eof()) {
alias += c;
in.get(c);
}
- while(isspace(c) && !in.eof())
+ while(isspace(static_cast<unsigned char>(c)) && !in.eof())
in.get(c);
std::string language;
- while(!isspace(c) && !in.eof()) {
+ while(!isspace(static_cast<unsigned char>(c)) && !in.eof()) {
language += c;
in.get(c);
}
Dictionaries::iterator i = dictionaries.find(get_language_from_spec(lang));
if (i != dictionaries.end())
- {
- return i->second;
- }
+ {
+ return i->second;
+ }
else // Dictionary for languages lang isn't loaded, so we load it
- {
- //log_debug << "get_dictionary: " << lang << std::endl;
- Dictionary& dict = dictionaries[lang];
-
- dict.set_language(get_language_def(lang));
- if(charset != "")
- dict.set_charset(charset);
-
- for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
{
- std::vector<std::string> files = Unison::VFS::FileSystem::get().ls(*p);
- for(std::vector<std::string>::iterator iter = files.begin();iter != files.end();++iter)
- {
- // check if filename matches requested language
- std::string fname = *iter;
- std::string load_from_file = "";
- if(fname == lang + ".po") {
- load_from_file = fname;
- } else {
- std::string::size_type s = lang.find("_");
- if(s != std::string::npos) {
- std::string lang_short = std::string(lang, 0, s);
- if (fname == lang_short + ".po") {
- load_from_file = lang_short;
- }
- }
- }
+ //log_debug << "get_dictionary: " << lang << std::endl;
+ Dictionary& dict = dictionaries[lang];
- // if it matched, load dictionary
- if (load_from_file != "") {
- //log_debug << "Loading dictionary for language \"" << lang << "\" from \"" << filename << "\"" << std::endl;
- std::string pofile = *p + "/" + *iter;
- try {
- IFileStream in(pofile);
- read_po_file(dict, in);
- } catch(std::exception& e) {
- log_warning << "Error: Failure file opening: " << pofile << std::endl;
- log_warning << e.what() << "" << std::endl;
- }
- }
- }
+ dict.set_language(get_language_def(lang));
+ if(charset != "")
+ dict.set_charset(charset);
-#if 0
- char** files = PHYSFS_enumerateFiles(p->c_str());
- if(!files)
- {
- log_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
- }
- else
- {
- for(const char* const* filename = files;
- *filename != 0; filename++) {
-
- // check if filename matches requested language
- std::string fname = std::string(*filename);
- std::string load_from_file = "";
- if(fname == lang + ".po") {
- load_from_file = fname;
- } else {
- std::string::size_type s = lang.find("_");
- if(s != std::string::npos) {
- std::string lang_short = std::string(lang, 0, s);
- if (fname == lang_short + ".po") {
- load_from_file = lang_short;
- }
- }
- }
+ for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
+ {
+ char** files = PHYSFS_enumerateFiles(p->c_str());
+ if(!files)
+ {
+ log_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
+ }
+ else
+ {
+ for(const char* const* filename = files;
+ *filename != 0; filename++) {
+
+ // check if filename matches requested language
+ std::string fname = std::string(*filename);
+ std::string load_from_file = "";
+ if(fname == lang + ".po") {
+ load_from_file = fname;
+ } else {
+ std::string::size_type s = lang.find("_");
+ if(s != std::string::npos) {
+ std::string lang_short = std::string(lang, 0, s);
+ if (fname == lang_short + ".po") {
+ load_from_file = lang_short;
+ }
+ }
+ }
+
+ // if it matched, load dictionary
+ if (load_from_file != "") {
+ //log_debug << "Loading dictionary for language \"" << lang << "\" from \"" << filename << "\"" << std::endl;
+ std::string pofile = *p + "/" + *filename;
+ try {
+ IFileStream in(pofile);
+ read_po_file(dict, in);
+ } catch(std::exception& e) {
+ log_warning << "Error: Failure file opening: " << pofile << std::endl;
+ log_warning << e.what() << "" << std::endl;
+ }
+ }
- // if it matched, load dictionary
- if (load_from_file != "") {
- //log_debug << "Loading dictionary for language \"" << lang << "\" from \"" << filename << "\"" << std::endl;
- std::string pofile = *p + "/" + *filename;
- try {
- IFileStream in(pofile);
- read_po_file(dict, in);
- } catch(std::exception& e) {
- log_warning << "Error: Failure file opening: " << pofile << std::endl;
- log_warning << e.what() << "" << std::endl;
+ }
+ PHYSFS_freeList(files);
+ }
}
- }
- }
- PHYSFS_freeList(files);
- }
-#endif
+ return dict;
}
-
- return dict;
- }
}
std::set<std::string>
for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
{
- std::vector<std::string> files = Unison::VFS::FileSystem::get().ls(*p);
- for(std::vector<std::string>::iterator iter = files.begin();iter != files.end();++iter)
- {
- if(has_suffix(*iter, ".po")) {
- std::string filename = *iter;
- languages.insert(filename.substr(0, filename.length()-3));
- }
- }
-#if 0
char** files = PHYSFS_enumerateFiles(p->c_str());
if (!files)
{
}
PHYSFS_freeList(files);
}
-#endif
}
return languages;
}
}
else
{
-#ifdef TRANSLATION_DBEUG
+#ifdef TRANSLATION_DEBUG
log_warning << "Couldn't translate: " << msgid << std::endl;
#endif
return msgid;
}
else
{
-#ifdef TRANSLATION_DBEUG
+#ifdef TRANSLATION_DEBUG
log_warning << "Couldn't translate: " << msgid << std::endl;
#endif
return msgid;
void parse_header(const std::string& header)
{
- // Seperate the header in lines
+ // Separate the header in lines
typedef std::vector<std::string> Lines;
Lines lines;
{
state = SKIP_COMMENT;
}
+ else if (c == '\n')
+ {
+ }
else
{
// Read a new token
do { // Read keyword
token.keyword += c;
- } while((c = getchar(in)) != EOF && !isspace(c));
+ } while((c = getchar(in)) != EOF && !isspace(static_cast<unsigned char>(c)));
in.unget();
state = READ_CONTENT;
// Found start of content
state = READ_CONTENT_IN_STRING;
break;
- } else if (isspace(c)) {
+ } else if (isspace(static_cast<unsigned char>(c))) {
// skip
} else { // Read something that may be a keyword
in.unget();
state = READ_KEYWORD;
add_token(token);
+ token = Token();
break;
}
}
}
}
add_token(token);
+ token = Token();
}
};