From: Ricardo Cruz Date: Wed, 7 Jul 2004 19:19:19 +0000 (+0000) Subject: Added support for data files internationalization by a simple 3 lines code in lisprea... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e99d667f6b4fd64c4ac422a3945374306c7f3363;p=supertux.git Added support for data files internationalization by a simple 3 lines code in lispreader's read_string(). To translate a level's title to European Portuguese, I would look at: (title "Hello World!") and add: (title-pt_PT "Ol� Mundo!") Also, made display_text_file() using lispreader (to make it i18n too). Unfortunately, there is a crash of lisp_reader in my system (not related), so I wasn't able to give it a try. data/*.txt files also need updating to work. Else, it should just skip it, without crashing. SVN-Revision: 1537 --- diff --git a/src/lispreader.cpp b/src/lispreader.cpp index 3750b1cf5..58e184cfe 100644 --- a/src/lispreader.cpp +++ b/src/lispreader.cpp @@ -1208,7 +1208,13 @@ LispReader::read_char_vector (const char* name, std::vector& vec) bool LispReader::read_string (const char* name, std::string& str) { - lisp_object_t* obj = search_for (name); + char str_[1204]; + sprintf(str_, "%s-%s", name, getenv("LANG")); + lisp_object_t* obj = search_for (str_); + + if(!obj) + obj = search_for (name); + if (!obj) return false; diff --git a/src/screen/font.cpp b/src/screen/font.cpp index 4ea0469f5..d414e1fc8 100644 --- a/src/screen/font.cpp +++ b/src/screen/font.cpp @@ -26,6 +26,7 @@ #include "screen.h" #include "font.h" #include "drawing_context.h" +#include "../lispreader.h" Font::Font(const std::string& file, FontType ntype, int nw, int nh, int nshadowsize) @@ -138,36 +139,40 @@ void display_text_file(const std::string& file, const std::string& surface, floa void display_text_file(const std::string& file, Surface* surface, float scroll_speed) { - int done; - float scroll; - float speed; - FILE* fi; - char temp[1024]; + std::string text; std::vector names; - char filename[1024]; - sprintf(filename,"%s/%s", datadir.c_str(), file.c_str()); - if((fi = fopen(filename,"r")) != NULL) + lisp_object_t* root_obj = lisp_read_from_file(datadir + file); + lisp_object_t* cur = lisp_car(root_obj); + + if (lisp_symbol_p(cur) && strcmp(lisp_symbol(cur), "text") == 0) { - while(fgets(temp, sizeof(temp), fi) != NULL) - { - temp[strlen(temp)-1]='\0'; - names.push_back(temp); - } - fclose(fi); + LispReader reader(lisp_cdr(root_obj)); + reader.read_string("text", text); } else { - names.push_back("File was not found!"); - names.push_back(filename); - names.push_back("Shame on the guy, who"); - names.push_back("forgot to include it"); - names.push_back("in your SuperTux distribution."); + std::cerr << "Error: Could not open text. Ignoring...\n"; + return; + } + + unsigned int l, i; + l = 0; + while(true) + { + i = l; + l = text.find("\n", i); + if(l != std::string::npos) + break; + + char* temp = 0; + text.copy(temp, l, i); + names.push_back(temp); } - scroll = 0; - speed = scroll_speed / 50; - done = 0; + int done = 0; + float scroll = 0; + float speed = scroll_speed / 50; DrawingContext context; SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);