From: Matthias Braun Date: Thu, 2 Dec 2004 01:41:57 +0000 (+0000) Subject: Made lispfiles translatable. This time the translations are stored externally X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3e1ea65bfa3cf450b9c7207831d9403a2c0f9101;p=supertux.git Made lispfiles translatable. This time the translations are stored externally in .po files in the same directory as the lisp files. So you can have translation files for complete level subsets now. Because Ricardo added a hacked solution before and because people already used that, someone has to go over all the maps now, extract the translations and put them into separate files, I'm too lazy to do that now, I just translated some files for testing. Translation-Patches are always welcome ;-) SVN-Revision: 2236 --- diff --git a/Jamfile b/Jamfile index 13259c77f..15413e165 100644 --- a/Jamfile +++ b/Jamfile @@ -1,5 +1,24 @@ SubDir TOP ; +if $(XGETTEXT) != "" +{ + actions XGetText + { + $(XGETTEXT) $(XGETTEXT_FLAGS) --keyword='_:1' -o $(<) $(>) + } + rule MakePot + { + if $(>) { + XGetText $(<) : $(>) ; + Depends $(<) : $(>) ; + Depends all : $(<) ; + } + } +} else { + rule MakePot + { } +} + # Decend into subdirs SubInclude TOP lib ; SubInclude TOP src ; @@ -10,15 +29,5 @@ UseAutoconf ; # add some additional files to package Package INSTALL NEWS README COPYING AUTHORS ChangeLog ; -if $(XGETTEXT) != "" -{ - - actions MakePot - { - $(XGETTEXT) --keyword='_:1' --c++ -o $(<) $(>) - } - MakePot supertux.pot : $(TRANSLATABLE_SOURCES) ; - Depends supertux.pot : $(TRANSLATABLE_SOURCES) ; - MakeLocate supertux.pot : data/locale ; - Depends all : supertux.pot ; -} +MakePot data/locale/supertux.pot : $(TRANSLATABLE_SOURCES) ; +XGETTEXT_FLAGS on data/locale/supertux.pot += --language=C++ ; diff --git a/data/Jamfile b/data/Jamfile index 556aadaaa..50f5115de 100644 --- a/data/Jamfile +++ b/data/Jamfile @@ -32,11 +32,15 @@ LEVELPATHS = levels/test levels/world1 levels/world2 - levels/worldmap ; for p in $(LEVELPATHS) { InstallData [ Wildcard $(p) : info *.stl *.stwm ] : $(p) ; + + local translatable_lisp = [ Wildcard $(p) : info *.stl *.stwm ] ; + SEARCH on $(translatable_lisp) = $(SEARCH_SOURCE) ; + MakePot $(SUBDIR)/$(p)/messages.pot : $(translatable_lisp) ; + XGETTEXT_FLAGS on $(SUBDIR)/$(p)/messages.pot += --language=Lisp ; } InstallData [ Wildcard *.txt ] ; InstallData [ Wildcard music : *.mod *.ogg ] : music ; diff --git a/data/levels/bonus1/de.po b/data/levels/bonus1/de.po new file mode 100644 index 000000000..e7ff6e75a --- /dev/null +++ b/data/levels/bonus1/de.po @@ -0,0 +1,78 @@ +# German translations for bonus package +# German messages for bonus. +# Copyright (C) 2004 THE bonus'S COPYRIGHT HOLDER +# This file is distributed under the same license as the bonus package. +# , 2004. +# +msgid "" +msgstr "" +"Project-Id-Version: bonus 1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2004-12-02 02:33+0100\n" +"PO-Revision-Date: 2004-12-02 02:34+0100\n" +"Last-Translator: \n" +"Language-Team: German \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: data/levels/bonus1/wansti-level1.stl:5 +msgid "Semi-Frozen" +msgstr "Halb-Gefroren" + +#: data/levels/bonus1/worldmap.stwm:4 +msgid "Bonus Island I" +msgstr "Bonusinsel I" + +#: data/levels/bonus1/worldmap.stwm:131 +msgid "You found a secret place!" +msgstr "Du hast ein Versteck gefunden!" + +#: data/levels/bonus1/worldmap.stwm:137 +msgid "Hint: Use igloos to get back here." +msgstr "Tip: Benutze die Igloos um hierher zurück zu kommen." + +#: data/levels/bonus1/worldmap.stwm:145 +msgid "Warp to Matr1x' Sector" +msgstr "Zu Matr1x' Sektor beamen" + +#: data/levels/bonus1/worldmap.stwm:151 +msgid "Warp to Thompson's Domain" +msgstr "Zu Thompsons Bereich beamen" + +#: data/levels/bonus1/worldmap.stwm:157 +msgid "Warp to the SuperTux Team Island" +msgstr "Zur SuperTux Team Insel beamen" + +#: data/levels/bonus1/worldmap.stwm:163 +msgid "Warp to Abednego's Area" +msgstr "Zu Abednegos Zone beamen" + +#: data/levels/bonus1/worldmap.stwm:169 +msgid "Warp to Torfi's Territory" +msgstr "Zu Torfis Territorium beamen" + +#: data/levels/bonus1/worldmap.stwm:175 +msgid "Leave Matrix' Sector" +msgstr "Matrix Sektor verlassen" + +#: data/levels/bonus1/worldmap.stwm:181 +msgid "Leave Thompson's Domain" +msgstr "Thompsons Bereich verlassen" + +#: data/levels/bonus1/worldmap.stwm:187 +msgid "Leave SuperTux Team Island" +msgstr "SuperTux Team Insel verlassen" + +#: data/levels/bonus1/worldmap.stwm:193 +msgid "Leave Abednego's Area" +msgstr "Abednegos Zone verlassen" + +#: data/levels/bonus1/worldmap.stwm:199 +msgid "Leave Torfi's Territory" +msgstr "Torfis Territorium verlassen" + +#: data/levels/bonus1/worldmap.stwm:207 +msgid "Warp home" +msgstr "Nach Hause beamen" diff --git a/data/levels/bonus1/wansti-level1.stl b/data/levels/bonus1/wansti-level1.stl index 1e9fd6008..5ab31ecb0 100644 --- a/data/levels/bonus1/wansti-level1.stl +++ b/data/levels/bonus1/wansti-level1.stl @@ -2,7 +2,7 @@ (supertux-level (version 1) (author "SuperTux Team") - (name "Semi-Frozen") + (name (_ "Semi-Frozen")) (width 500) (height 15) (start_pos_x 100) diff --git a/data/levels/bonus1/worldmap.stwm b/data/levels/bonus1/worldmap.stwm index 47b682efd..9044557ae 100644 --- a/data/levels/bonus1/worldmap.stwm +++ b/data/levels/bonus1/worldmap.stwm @@ -1,7 +1,7 @@ ;; Generated with Flexlay Editor (supertux-worldmap (properties - (name "Bonus Island I") + (name (_ "Bonus Island I")) (start_pos_x 35) (start_pos_y 2)) (tilemap @@ -128,13 +128,13 @@ (level (name "wansti-level5.stl") (x 50) (y 22)) - - (special-tile (map-message "You found a secret place!") + (special-tile (map-message (_ "You found a secret place!")) (x 33) (y 39) (passive-message #t) (apply-to-direction "west-north-south")) - (special-tile (map-message "Hint: Use igloos to get back here.") + (special-tile (map-message + (_ "Hint: Use igloos to get back here.")) (x 35) (y 5) (passive-message #t) (apply-to-direction "north")) @@ -142,61 +142,61 @@ (special-tile (x 33) (y 8) - (map-message "Warp to Matr1x' Sector") + (map-message (_ "Warp to Matr1x' Sector")) (teleport-to-x 20) (teleport-to-y 14)) (special-tile (x 31) (y 8) - (map-message "Warp to Thompson's Domain") + (map-message (_ "Warp to Thompson's Domain")) (teleport-to-x 34) (teleport-to-y 18)) (special-tile (x 35) (y 8) - (map-message "Warp to the SuperTux Team Island") + (map-message (_ "Warp to the SuperTux Team Island")) (teleport-to-x 51) (teleport-to-y 10)) (special-tile (x 37) (y 8) - (map-message "Warp to Abednego's Area") + (map-message (_ "Warp to Abednego's Area")) (teleport-to-x 15) (teleport-to-y 31)) (special-tile (x 39) (y 8) - (map-message "Warp to Torfi's Territory") + (map-message (_ "Warp to Torfi's Territory")) (teleport-to-x 56) (teleport-to-y 33)) (special-tile (x 19) (y 24) - (map-message "Leave Matrix' Sector") + (map-message (_ "Leave Matrix' Sector")) (teleport-to-x 32) (teleport-to-y 37)) (special-tile (x 35) (y 26) - (map-message "Leave Thompson's Domain") + (map-message (_ "Leave Thompson's Domain")) (teleport-to-x 35) (teleport-to-y 2)) (special-tile (x 54) (y 25) - (map-message "Leave SuperTux Team Island") + (map-message (_ "Leave SuperTux Team Island")) (teleport-to-x 35) (teleport-to-y 2)) (special-tile (x 18) (y 43) - (map-message "Leave Abednego's Area") + (map-message (_ "Leave Abednego's Area")) (teleport-to-x 35) (teleport-to-y 2)) (special-tile (x 60) (y 43) - (map-message "Leave Torfi's Territory") + (map-message (_ "Leave Torfi's Territory")) (teleport-to-x 35) (teleport-to-y 2)) @@ -204,7 +204,7 @@ (special-tile (x 27) (y 39) - (map-message "Warp home") + (map-message (_ "Warp home")) (teleport-to-x 35) (teleport-to-y 2)) diff --git a/data/levels/contribs/level1.stl b/data/levels/contribs/level1.stl index 012d34503..2b791034b 100644 --- a/data/levels/contribs/level1.stl +++ b/data/levels/contribs/level1.stl @@ -1,7 +1,7 @@ ;SuperTux-Level (supertux-level (version 1) - (name "The long cave") + (name (_ "The long cave")) (author "Torfi Gunnarsson") (music "cave.mod") (background "cave2.jpg") diff --git a/data/levels/misc/menu.stl b/data/levels/misc/menu.stl index 4db687858..a863ded61 100644 --- a/data/levels/misc/menu.stl +++ b/data/levels/misc/menu.stl @@ -1,7 +1,7 @@ ;SuperTux-Level (supertux-level (version 1) - (name "Hello World") + (name (_ "Menu Level")) (author "unknown author") (music "theme.mod") (background "arctis.jpg") diff --git a/data/levels/test/sectors.stl b/data/levels/test/sectors.stl index fe437fb9c..f7f781bed 100644 --- a/data/levels/test/sectors.stl +++ b/data/levels/test/sectors.stl @@ -1,6 +1,6 @@ (supertux-level (version 2) - (name "Sector Test") + (name (_ "Sector Test")) (author "Matthias Braun") (time 500) (sector diff --git a/data/levels/world1/de.po b/data/levels/world1/de.po new file mode 100644 index 000000000..f0192d98c --- /dev/null +++ b/data/levels/world1/de.po @@ -0,0 +1,26 @@ +# German translations for world package +# German messages for world. +# Copyright (C) 2004 THE world'S COPYRIGHT HOLDER +# This file is distributed under the same license as the world package. +# , 2004. +# +msgid "" +msgstr "" +"Project-Id-Version: world 1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2004-12-02 02:10+0100\n" +"PO-Revision-Date: 2004-12-02 02:25+0100\n" +"Last-Translator: \n" +"Language-Team: German \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: data/levels/world1/level1.stl:5 +msgid "Welcome to Antarctica" +msgstr "Willkommen in Antarktika" + +#: data/levels/world1/level2.stl:5 +msgid "The Journey Begins" +msgstr "Die Reise Beginnt" diff --git a/data/levels/world1/level1.stl b/data/levels/world1/level1.stl index c739efa2e..79ae25ff7 100644 --- a/data/levels/world1/level1.stl +++ b/data/levels/world1/level1.stl @@ -2,7 +2,7 @@ (supertux-level (version 1) (author "SuperTux Team") - (name "Welcome to Antarctica") + (name (_ "Welcome to Antarctica")) (name-pt_PT "Bem-vindo à Antártida") (name-de "Willkommen in Antarctica") (name-es "Bienvenido a la Antártida") diff --git a/data/levels/world1/level2.stl b/data/levels/world1/level2.stl index ec07ae062..f60a401e1 100644 --- a/data/levels/world1/level2.stl +++ b/data/levels/world1/level2.stl @@ -2,7 +2,7 @@ (supertux-level (version 1) (author "SuperTux Team") - (name "The Journey Begins") + (name (_ "The Journey Begins")) (name-pt_PT "A Aventura Começa") (name-de "Das Abenteuer beginnt") (name-es "La aventura comienza") diff --git a/data/levels/world1/level3.stl b/data/levels/world1/level3.stl index ad0da9329..4eb2f3cfd 100644 --- a/data/levels/world1/level3.stl +++ b/data/levels/world1/level3.stl @@ -2,7 +2,7 @@ (supertux-level (version 1) (author "SuperTux Team") - (name "Via Nostalgica") + (name (_ "Via Nostalgica")) (width 390) (height 19) (start_pos_x 100) diff --git a/data/levels/world2/castle.stl b/data/levels/world2/castle.stl index 1ef9251fc..8b16b99fe 100644 --- a/data/levels/world2/castle.stl +++ b/data/levels/world2/castle.stl @@ -2,7 +2,7 @@ (supertux-level (version 1) (author "SuperTux Team") - (name "Iceberg Fortress") + (name (_ "Iceberg Fortress")) (width 550) (height 105) (start_pos_x 100) diff --git a/data/levels/world2/forest1-grumbel.stl b/data/levels/world2/forest1-grumbel.stl index 4b546e3f2..f54ca43e1 100644 --- a/data/levels/world2/forest1-grumbel.stl +++ b/data/levels/world2/forest1-grumbel.stl @@ -1,7 +1,7 @@ ;; Generated by Flexlay Editor (supertux-level (version 2) - (name "Forest Level 1") + (name (_ "Forest Level 1")) (author "SuperTux Team") (time 999) (sector diff --git a/lib/app/setup.cpp b/lib/app/setup.cpp index d8c10af4c..acb17497a 100644 --- a/lib/app/setup.cpp +++ b/lib/app/setup.cpp @@ -252,6 +252,15 @@ std::set FileSystem::dfiles(const std::string& rel_path, const std return sdirs; } +std::string FileSystem::dirname(const std::string& filename) +{ + std::string::size_type p = filename.find_last_of('/'); + if(p == std::string::npos) + return ""; + + return filename.substr(0, p+1); +} + void Setup::init(const std::string& _package_name, const std::string& _package_symbol_name, const std::string& _package_version) diff --git a/lib/app/setup.h b/lib/app/setup.h index a918b4b25..ad70bd4d8 100644 --- a/lib/app/setup.h +++ b/lib/app/setup.h @@ -35,6 +35,8 @@ struct FileSystem static std::set read_directory(const std::string& pathname); static std::set dsubdirs(const std::string& rel_path, const std::string& expected_file); static std::set dfiles(const std::string& rel_path, const std::string& glob, const std::string& exception_str); + + static std::string dirname(const std::string& filename); }; /// All you need to get an application up and running diff --git a/lib/lisp/parser.cpp b/lib/lisp/parser.cpp index 415a3640a..875a4b201 100644 --- a/lib/lisp/parser.cpp +++ b/lib/lisp/parser.cpp @@ -23,21 +23,28 @@ #include #include #include +#include +#include "app/setup.h" +#include "app/tinygettext.h" #include "parser.h" #include "lisp.h" namespace lisp { -Parser::Parser() - : lexer(0) +Parser::Parser(bool translate) + : lexer(0), dictionary_manager(0), dictionary(0) { + if(translate) { + dictionary_manager = new TinyGetText::DictionaryManager(); + } } Parser::~Parser() { delete lexer; + delete dictionary_manager; } Lisp* @@ -49,6 +56,12 @@ Parser::parse(const std::string& filename) msg << "Parser problem: Couldn't open file '" << filename << "'."; throw std::runtime_error(msg.str()); } + + if(dictionary_manager) { + dictionary_manager->add_directory(SuperTux::FileSystem::dirname(filename)); + dictionary = & (dictionary_manager->get_dictionary()); + } + return parse(in); } @@ -96,6 +109,31 @@ Parser::read() break; } + if(token == Lexer::TOKEN_SYMBOL && + strcmp(lexer->getString(), "_") == 0) { + // evaluate translation function (_ str) in place here + token = lexer->getNextToken(); + if(token != Lexer::TOKEN_STRING) + throw new std::runtime_error("Expected string after '(_'"); + + result = new Lisp(Lisp::TYPE_STRING); + if(dictionary) { + std::string translation = dictionary->translate(lexer->getString()); + std::cout << "Translated '" << lexer->getString() << "' -> '" + << translation << "'\n"; + result->v.string = new char[translation.size()+1]; + memcpy(result->v.string, translation.c_str(), translation.size()+1); + } else { + size_t len = strlen(lexer->getString()) + 1; + result->v.string = new char[len]; + memcpy(result->v.string, lexer->getString(), len); + } + token = lexer->getNextToken(); + if(token != Lexer::TOKEN_CLOSE_PAREN) + throw new std::runtime_error("Expected ')' after '(_ string'"); + break; + } + Lisp* cur = result; do { cur->v.cons.car = read(); diff --git a/lib/lisp/parser.h b/lib/lisp/parser.h index 726648e04..507fb1041 100644 --- a/lib/lisp/parser.h +++ b/lib/lisp/parser.h @@ -23,6 +23,11 @@ #include #include "lexer.h" +namespace TinyGetText { +class Dictionary; +class DictionaryManager; +} + namespace lisp { @@ -31,7 +36,7 @@ class Lisp; class Parser { public: - Parser(); + Parser(bool translate = true); ~Parser(); Lisp* parse(const std::string& filename); @@ -41,6 +46,8 @@ private: Lisp* read(); Lexer* lexer; + TinyGetText::DictionaryManager* dictionary_manager; + TinyGetText::Dictionary* dictionary; Lexer::TokenType token; }; diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 53d8fc28c..18469174d 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -368,11 +368,7 @@ WorldMap::~WorldMap() void WorldMap::load_map() { - std::string::size_type p = map_filename.find_last_of('/'); - if(p == std::string::npos) - levels_path = ""; - else - levels_path = map_filename.substr(0, p+1); + levels_path = FileSystem::dirname(map_filename); try { lisp::Parser parser;