Hi,
we have included tinygettext in supertuxkart, and have applied a few minor patches over time. A full list can be found on our github:
https://github.com/supertuxkart/stk-code/commits/master/src/tinygettext
But here in short the somewhat important and portable ones:
Fix missing include for some newer compilers:
--- a/src/tinygettext/language.cpp
+++ b/src/tinygettext/language.cpp
@@ -20,6 +20,7 @@
#include <map>
#include <assert.h>
#include <vector>
+#include <algorithm>
namespace tinygettext {
Change pt-BR name to be more accurate:
--- a/src/tinygettext/language.cpp
+++ b/src/tinygettext/language.cpp
@@ -213,7 +213,7 @@ static const LanguageSpec languages[] = {
{ "pl", "PL", 0, "Polish (Poland)" },
{ "ps", 0, 0, "Pashto" },
{ "pt", 0, 0, "Portuguese" },
- { "pt", "BR", 0, "Brazilian" },
+ { "pt", "BR", 0, "Portuguese (Brazil)" },
{ "pt", "PT", 0, "Portuguese (Portugal)" },
{ "qu", 0, 0, "Quechua" },
{ "rm", 0, 0, "Rhaeto-Romance" },
Fix 64 bit compilation:
--- a/src/tinygettext/po_parser.cpp
+++ b/src/tinygettext/po_parser.cpp
@@ -207,7 +207,7 @@ next:
if (pedantic)
warning("leading whitespace before string");
- get_string_line(out, i);
+ get_string_line(out, (unsigned int) i);
goto next;
}
else if (isspace(current_line[i]))
@@ -245,7 +245,7 @@ POParser::parse_header(const std::string& header)
if (has_prefix(line, "Content-Type:"))
{
// from_charset = line.substr(len);
- unsigned int len = strlen("Content-Type: text/plain; charset=");
+ unsigned int len = (unsigned int) strlen("Content-Type: text/plain; charset=");
if (line.compare(0, len, "Content-Type: text/plain; charset=") == 0)
{
from_charset = line.substr(len);
tinygettext const fix
This moves ~8kb of writable data to RO, and improves optimization. There is no need for the initial array to be writable anyhow.
--- a/src/tinygettext/language.cpp
+++ b/src/tinygettext/language.cpp
@@ -39,7 +39,7 @@ struct LanguageSpec {
/** Language Definitions */
//*{
-LanguageSpec languages[] = {
+static const LanguageSpec languages[] = {
{ "aa", 0, 0, "Afar" },
{ "af", 0, 0, "Afrikaans" },
{ "af", "ZA", 0, "Afrikaans (South Africa)" },
@@ -364,7 +364,7 @@ resolve_language_alias(const std::string& name)
Language
Language::from_spec(const std::string& language, const std::string& country, const std::string& modifier)
{
- static std::map<std::string, std::vector<LanguageSpec*> > language_map;
+ static std::map<std::string, std::vector<const LanguageSpec*> > language_map;
if (language_map.empty())
{ // Init language_map
@@ -372,10 +372,10 @@ Language::from_spec(const std::string& language, const std::string& country, con
language_map[languages[i].language].push_back(&languages[i]);
}
- std::map<std::string, std::vector<LanguageSpec*> >::iterator i = language_map.find(language);
+ std::map<std::string, std::vector<const LanguageSpec*> >::iterator i = language_map.find(language);
if (i != language_map.end())
{
- std::vector<LanguageSpec*>& lst = i->second;
+ std::vector<const LanguageSpec*>& lst = i->second;
LanguageSpec tmpspec;
tmpspec.language = language.c_str();
@@ -383,9 +383,9 @@ Language::from_spec(const std::string& language, const std::string& country, con
tmpspec.modifier = modifier.c_str();
Language tmplang(&tmpspec);
- LanguageSpec* best_match = 0;
+ const LanguageSpec* best_match = 0;
int best_match_score = 0;
- for(std::vector<LanguageSpec*>::iterator j = lst.begin(); j != lst.end(); ++j)
+ for(std::vector<const LanguageSpec*>::iterator j = lst.begin(); j != lst.end(); ++j)
{ // Search for the language that best matches the given spec, value country more then modifier
int score = Language::match(Language(*j), tmplang);
@@ -445,7 +445,7 @@ Language::from_env(const std::string& env)
return from_spec(language, country, modifier);
}
-Language::Language(LanguageSpec* language_spec_)
+Language::Language(const LanguageSpec* language_spec_)
: language_spec(language_spec_)
{
}
diff --git a/src/tinygettext/language.hpp b/src/tinygettext/language.hpp
index bd4a3ea..0ab2f32 100644
--- a/src/tinygettext/language.hpp
+++ b/src/tinygettext/language.hpp
@@ -28,9 +28,9 @@ struct LanguageSpec;
class Language
{
private:
- LanguageSpec* language_spec;
+ const LanguageSpec* language_spec;
- Language(LanguageSpec* language_spec);
+ Language(const LanguageSpec* language_spec);
public:
/** Create a language from language and country code: