From: Ricardo Cruz Date: Thu, 8 Jul 2004 10:11:08 +0000 (+0000) Subject: I18N: X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=059db3830c678ae03528bc29adf08a81c03d54d1;p=supertux.git I18N: - 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 --- diff --git a/src/level.cpp b/src/level.cpp index 7b42e5287..06d6426b4 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -89,7 +89,7 @@ Level::load(const std::string& filename) 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); diff --git a/src/lispreader.cpp b/src/lispreader.cpp index 0c52260a7..2c49aad51 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -1206,13 +1206,37 @@ LispReader::read_char_vector (const char* name, std::vector& vec) } 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) diff --git a/src/lispreader.h b/src/lispreader.h index 33aad4f2f..f177a94a8 100644 --- a/src/lispreader.h +++ b/src/lispreader.h @@ -187,7 +187,7 @@ public: bool read_int_vector(const char* name, std::vector& vec); bool read_char_vector(const char* name, std::vector& vec); bool read_string_vector(const char* name, std::vector& 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); diff --git a/src/screen/font.cpp b/src/screen/font.cpp index decdc6595..43e416527 100644 --- a/src/screen/font.cpp +++ b/src/screen/font.cpp @@ -151,7 +151,7 @@ void display_text_file(const std::string& file, Surface* surface, float scroll_s } - reader->read_string("text", text); + reader->read_string("text", text, true); delete reader; names.clear(); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index af1c3a9ad..a9e49ae56 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -402,7 +402,7 @@ WorldMap::load_map() 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) @@ -425,7 +425,7 @@ WorldMap::load_map() 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; @@ -475,7 +475,7 @@ void WorldMap::get_level_title(Level& level) 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); @@ -1067,7 +1067,7 @@ WorldMap::loadgame(const std::string& filename) 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)