- Also check without country code. ie. Germany is the same for German and Austria.
- Only check for translation when the code asks for. (translatable flag)
SVN-Revision: 1544
void
Level::load_old_format(LispReader& reader)
{
- reader.read_string("name", name);
+ reader.read_string("name", name, true);
reader.read_string("author", author);
reader.read_int("time", time_left);
}
bool
-LispReader::read_string (const char* name, std::string& str)
+LispReader::read_string (const char* name, std::string& str, bool translatable)
{
- char str_[1024];
- sprintf(str_, "%s-%s", name, getenv("LANG"));
- lisp_object_t* obj = search_for (str_);
+ lisp_object_t* obj;
+ if(translatable)
+ {
+ /* Internationalization support: check for the suffix: str + "-" + $LANG variable.
+ If not found, use the regular string.
+ So, translating a string in a Lisp file would result in something like:
+ (text "Hello World!")
+ (text-fr "Bonjour Monde!")
+ being fr the value of LANG (echo $LANG) for the language we want to translate to */
- if(!obj)
+ char str_[1024]; // check, for instance, for (title-fr_FR "Bonjour")
+ sprintf(str_, "%s-%s", name, getenv("LANG"));
+
+ obj = search_for (str_);
+
+ if(!obj) // check, for instance, for (title-fr "Bonjour")
+ {
+ char lang[3];
+ strncpy(lang, getenv("LANG"), 2);
+ lang[2] = '\0';
+ sprintf(str_, "%s-%s", name, lang);
+
+ obj = search_for (str_);
+ }
+
+ if(!obj) // check, for instance, for (title "Hello")
+ obj = search_for (name);
+ }
+ else
obj = search_for (name);
if (!obj)
bool read_int_vector(const char* name, std::vector<unsigned int>& vec);
bool read_char_vector(const char* name, std::vector<char>& vec);
bool read_string_vector(const char* name, std::vector<std::string>& vec);
- bool read_string(const char* name, std::string& str);
+ bool read_string(const char* name, std::string& str, bool translatable = false);
bool read_int(const char* name, int& i);
bool read_float(const char* name, float& f);
bool read_bool(const char* name, bool& b);
}
- reader->read_string("text", text);
+ reader->read_string("text", text, true);
delete reader;
names.clear();
else if (strcmp(lisp_symbol(lisp_car(element)), "properties") == 0)
{
LispReader reader(lisp_cdr(element));
- reader.read_string("name", name);
+ reader.read_string("name", name, true);
reader.read_string("music", music);
}
else if (strcmp(lisp_symbol(lisp_car(element)), "levels") == 0)
level.west = true;
reader.read_string("extro-filename", level.extro_filename);
- reader.read_string("name", level.name);
+ reader.read_string("name", level.name, true);
reader.read_int("x", level.x);
reader.read_int("y", level.y);
level.vertical_flip = false;
if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
{
LispReader reader(lisp_cdr(root_obj));
- reader.read_string("name", level.title);
+ reader.read_string("name", level.title, true);
}
lisp_free(root_obj);
bool solved = false;
LispReader level_reader(data);
- level_reader.read_string("name", name);
+ level_reader.read_string("name", name, true);
level_reader.read_bool("solved", solved);
for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)