projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix cr/lfs and remove trailing whitespaces...
[supertux.git]
/
src
/
tinygettext
/
tinygettext.cpp
diff --git
a/src/tinygettext/tinygettext.cpp
b/src/tinygettext/tinygettext.cpp
index
d51f627
..
a9bb964
100644
(file)
--- a/
src/tinygettext/tinygettext.cpp
+++ b/
src/tinygettext/tinygettext.cpp
@@
-45,7
+45,7
@@
std::string convert(const std::string& text,
return text;
iconv_t cd = iconv_open(to_charset.c_str(), from_charset.c_str());
return text;
iconv_t cd = iconv_open(to_charset.c_str(), from_charset.c_str());
-
+
size_t in_len = text.length();
size_t out_len = text.length()*3; // FIXME: cross fingers that this is enough
size_t in_len = text.length();
size_t out_len = text.length()*3; // FIXME: cross fingers that this is enough
@@
-174,7
+174,7
@@
get_language_def(const std::string& name)
else if (name == "sk") return lang_sk;
else if (name == "pl") return lang_pl;
else if (name == "sl") return lang_sl;
else if (name == "sk") return lang_sk;
else if (name == "pl") return lang_pl;
else if (name == "sl") return lang_sl;
- else return lang_en;
+ else return lang_en;
}
DictionaryManager::DictionaryManager()
}
DictionaryManager::DictionaryManager()
@@
-186,7
+186,7
@@
DictionaryManager::DictionaryManager()
if( lang ){
set_language( lang );
return;
if( lang ){
set_language( lang );
return;
- }
+ }
// use findlocale to setup language
FL_Locale *locale;
FL_FindLocale( &locale, FL_MESSAGES );
// use findlocale to setup language
FL_Locale *locale;
FL_FindLocale( &locale, FL_MESSAGES );
@@
-200,18
+200,18
@@
DictionaryManager::parseLocaleAliases()
{
// try to parse language alias list
std::ifstream in("/usr/share/locale/locale.alias");
{
// try to parse language alias list
std::ifstream in("/usr/share/locale/locale.alias");
-
+
char c = ' ';
while(in.good() && !in.eof()) {
while(isspace(c) && !in.eof())
in.get(c);
char c = ' ';
while(in.good() && !in.eof()) {
while(isspace(c) && !in.eof())
in.get(c);
-
+
if(c == '#') { // skip comments
while(c != '\n' && !in.eof())
in.get(c);
continue;
}
if(c == '#') { // skip comments
while(c != '\n' && !in.eof())
in.get(c);
continue;
}
-
+
std::string alias;
while(!isspace(c) && !in.eof()) {
alias += c;
std::string alias;
while(!isspace(c) && !in.eof()) {
alias += c;
@@
-230,7
+230,7
@@
DictionaryManager::parseLocaleAliases()
set_language_alias(alias, language);
}
}
set_language_alias(alias, language);
}
}
-
+
Dictionary&
DictionaryManager::get_dictionary(const std::string& spec)
{
Dictionary&
DictionaryManager::get_dictionary(const std::string& spec)
{
@@
-252,7
+252,7
@@
DictionaryManager::get_dictionary(const std::string& spec)
for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
{
char** files = PHYSFS_enumerateFiles(p->c_str());
for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
{
char** files = PHYSFS_enumerateFiles(p->c_str());
- if(!files)
+ if(!files)
{
log_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
}
{
log_warning << "Error: enumerateFiles() failed on " << *p << std::endl;
}
@@
-301,7
+301,7
@@
DictionaryManager::get_languages()
}
PHYSFS_freeList(files);
}
}
PHYSFS_freeList(files);
}
- }
+ }
return languages;
}
return languages;
}
@@
-341,12
+341,12
@@
DictionaryManager::get_language_from_spec(const std::string& spec)
if(i != language_aliases.end()) {
lang = i->second;
}
if(i != language_aliases.end()) {
lang = i->second;
}
-
+
std::string::size_type s = lang.find_first_of("_.");
if(s == std::string::npos)
return lang;
std::string::size_type s = lang.find_first_of("_.");
if(s == std::string::npos)
return lang;
- return std::string(lang, 0, s);
+ return std::string(lang, 0, s);
}
void
}
void
@@
-388,7
+388,7
@@
Dictionary::set_language(const LanguageDef& lang)
}
std::string
}
std::string
-Dictionary::translate(const std::string& msgid, const std::string& msgid2, int num)
+Dictionary::translate(const std::string& msgid, const std::string& msgid2, int num)
{
PluralEntries::iterator i = plural_entries.find(msgid);
std::map<int, std::string>& msgstrs = i->second;
{
PluralEntries::iterator i = plural_entries.find(msgid);
std::map<int, std::string>& msgstrs = i->second;
@@
-441,7
+441,7
@@
Dictionary::translate(const char* msgid)
}
std::string
}
std::string
-Dictionary::translate(const std::string& msgid)
+Dictionary::translate(const std::string& msgid)
{
Entries::iterator i = entries.find(msgid);
if (i != entries.end() && !i->second.empty())
{
Entries::iterator i = entries.find(msgid);
if (i != entries.end() && !i->second.empty())
@@
-456,7
+456,7
@@
Dictionary::translate(const std::string& msgid)
return msgid;
}
}
return msgid;
}
}
-
+
void
Dictionary::add_translation(const std::string& msgid, const std::string& ,
const std::map<int, std::string>& msgstrs)
void
Dictionary::add_translation(const std::string& msgid, const std::string& ,
const std::map<int, std::string>& msgstrs)
@@
-466,8
+466,8
@@
Dictionary::add_translation(const std::string& msgid, const std::string& ,
plural_entries[msgid] = msgstrs;
}
plural_entries[msgid] = msgstrs;
}
-void
-Dictionary::add_translation(const std::string& msgid, const std::string& msgstr)
+void
+Dictionary::add_translation(const std::string& msgid, const std::string& msgstr)
{
entries[msgid] = msgstr;
}
{
entries[msgid] = msgstr;
}
@@
-515,7
+515,7
@@
public:
// Seperate the header in lines
typedef std::vector<std::string> Lines;
Lines lines;
// Seperate the header in lines
typedef std::vector<std::string> Lines;
Lines lines;
-
+
std::string::size_type start = 0;
for(std::string::size_type i = 0; i < header.length(); ++i)
{
std::string::size_type start = 0;
for(std::string::size_type i = 0; i < header.length(); ++i)
{
@@
-549,10
+549,10
@@
public:
void add_token(const Token& token)
{
void add_token(const Token& token)
{
- switch(state)
+ switch(state)
{
case WANT_MSGID:
{
case WANT_MSGID:
- if (token.keyword == "msgid")
+ if (token.keyword == "msgid")
{
current_msgid = token.content;
state = WANT_MSGID_PLURAL;
{
current_msgid = token.content;
state = WANT_MSGID_PLURAL;
@@
-566,13
+566,13
@@
public:
log_warning << "tinygettext: expected 'msgid' keyword, got " << token.keyword << " at line " << line_num << std::endl;
}
break;
log_warning << "tinygettext: expected 'msgid' keyword, got " << token.keyword << " at line " << line_num << std::endl;
}
break;
-
+
case WANT_MSGID_PLURAL:
case WANT_MSGID_PLURAL:
- if (token.keyword == "msgid_plural")
+ if (token.keyword == "msgid_plural")
{
current_msgid_plural = token.content;
state = WANT_MSGSTR_PLURAL;
{
current_msgid_plural = token.content;
state = WANT_MSGSTR_PLURAL;
- }
+ }
else
{
state = WANT_MSGSTR;
else
{
state = WANT_MSGSTR;
@@
-581,9
+581,9
@@
public:
break;
case WANT_MSGSTR:
break;
case WANT_MSGSTR:
- if (token.keyword == "msgstr")
+ if (token.keyword == "msgstr")
{
{
- if (current_msgid == "")
+ if (current_msgid == "")
{ // .po Header is hidden in the msgid with the empty string
parse_header(token.content);
}
{ // .po Header is hidden in the msgid with the empty string
parse_header(token.content);
}
@@
-592,7
+592,7
@@
public:
dict.add_translation(current_msgid, convert(token.content, from_charset, to_charset));
}
state = WANT_MSGID;
dict.add_translation(current_msgid, convert(token.content, from_charset, to_charset));
}
state = WANT_MSGID;
- }
+ }
else
{
log_warning << "tinygettext: expected 'msgstr' keyword, got " << token.keyword << " at line " << line_num << std::endl;
else
{
log_warning << "tinygettext: expected 'msgstr' keyword, got " << token.keyword << " at line " << line_num << std::endl;
@@
-600,19
+600,19
@@
public:
break;
case WANT_MSGSTR_PLURAL:
break;
case WANT_MSGSTR_PLURAL:
- if (has_prefix(token.keyword, "msgstr["))
+ if (has_prefix(token.keyword, "msgstr["))
{
int num;
{
int num;
- if (sscanf(token.keyword.c_str(), "msgstr[%d]", &num) != 1)
+ if (sscanf(token.keyword.c_str(), "msgstr[%d]", &num) != 1)
{
log_warning << "Error: Couldn't parse: " << token.keyword << std::endl;
{
log_warning << "Error: Couldn't parse: " << token.keyword << std::endl;
- }
- else
+ }
+ else
{
msgstr_plural[num] = convert(token.content, from_charset, to_charset);
}
}
{
msgstr_plural[num] = convert(token.content, from_charset, to_charset);
}
}
- else
+ else
{
dict.add_translation(current_msgid, current_msgid_plural, msgstr_plural);
{
dict.add_translation(current_msgid, current_msgid_plural, msgstr_plural);
@@
-622,18
+622,18
@@
public:
break;
}
}
break;
}
}
-
- inline int getchar(std::istream& in)
+
+ inline int getchar(std::istream& in)
{
int c = in.get();
if (c == '\n')
line_num += 1;
return c;
}
{
int c = in.get();
if (c == '\n')
line_num += 1;
return c;
}
-
+
void tokenize_po(std::istream& in)
{
void tokenize_po(std::istream& in)
{
- enum State { READ_KEYWORD,
+ enum State { READ_KEYWORD,
READ_CONTENT,
READ_CONTENT_IN_STRING,
SKIP_COMMENT };
READ_CONTENT,
READ_CONTENT_IN_STRING,
SKIP_COMMENT };
@@
-656,8
+656,8
@@
public:
{
// Read a new token
token = Token();
{
// Read a new token
token = Token();
-
- do { // Read keyword
+
+ do { // Read keyword
token.keyword += c;
} while((c = getchar(in)) != EOF && !isspace(c));
in.unget();
token.keyword += c;
} while((c = getchar(in)) != EOF && !isspace(c));
in.unget();
@@
-669,7
+669,7
@@
public:
case READ_CONTENT:
while((c = getchar(in)) != EOF)
{
case READ_CONTENT:
while((c = getchar(in)) != EOF)
{
- if (c == '"') {
+ if (c == '"') {
// Found start of content
state = READ_CONTENT_IN_STRING;
break;
// Found start of content
state = READ_CONTENT_IN_STRING;
break;
@@
-719,7
+719,7
@@
public:
}
};
}
};
-void read_po_file(Dictionary& dict_, std::istream& in)
+void read_po_file(Dictionary& dict_, std::istream& in)
{
POFileReader reader(in, dict_);
}
{
POFileReader reader(in, dict_);
}