Re: [Freeciv-Dev] (PR#16350) Beta1: Tutorial translation not possible

2007-01-13 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=16350 >

 S2_1 version of the tutorial patch.


 - ML

diff -Nurd -X.diff_ignore freeciv/data/scenario/tutorial.sav freeciv/data/scenario/tutorial.sav
--- freeciv/data/scenario/tutorial.sav	2006-07-17 14:28:11.0 +0300
+++ freeciv/data/scenario/tutorial.sav	2007-01-14 04:37:21.0 +0200
@@ -4,15 +4,15 @@
 description=_("Tutorial Scenario.")
 
 [script]
-code="
+code=$
 function turn_callback(turn, year)
   if turn == 0 then
 notify.event(nil, nil, E.TUTORIAL,
-_('Welcome to Freeciv.  You lead a civilization.  Your\\n\
+_("Welcome to Freeciv.  You lead a civilization.  Your\\n\
 task is to conquer the world!  You should start by\\n\
 exploring the land around you with your explorer,\\n\
 and using your settlers to find a good place to build\\n\
-a city.  Use the number pad to move units around.'))
+a city.  Use the number pad to move units around."))
   end
 end
 signal.connect('turn_started', 'turn_callback')
@@ -24,12 +24,12 @@
   and (dst_tile:terrain().name == 'Grassland'
or dst_tile:terrain().name == 'Plains') then  
   notify.event(unit.owner, dst_tile, E.TUTORIAL,
-_('This looks like a good place to build a city.  The next time this\\n\
+_("This looks like a good place to build a city.  The next time this\\n\
 unit gets a chance to move, press (b) to found a city.\\n\
 \\n\
 In general you want to build cities on open ground near water.  Food\\n\
 is the most important resource for any city.  Grassland and plains\\n\
-provide plenty of food.'))
+provide plenty of food."))
 end
   end
 end
@@ -39,7 +39,7 @@
   if city.owner:is_human() then
 if citiesbuilt == 0 then
   notify.event(city.owner, city.tile, E.TUTORIAL,
-_('Now you have built your first city.  The city window should have\\n\
+_("Now you have built your first city.  The city window should have\\n\
 opened automatically; if not click on the city to open it.  Cities are\\n\
 a fundamental concept in Freeciv, so you should familiarize yourself\\n\
 with them by playing around in the window.  See the help menu for more.\\n\
@@ -49,31 +49,31 @@
 settler unit from the list of possible productions, then click on the\\n\
 Change button to begin building it.  When you are done, close the city\\n\
 dialog.  If all goes well the city should display the settler\\n\
-production on the map view.'))
+production on the map view."))
 elseif citiesbuilt == 1 then
   notify.event(city.owner, city.tile, E.TUTORIAL,
-_('Congratulations, you have founded your second city.  This city will\\n\
+_("Congratulations, you have founded your second city.  This city will\\n\
 behave almost exactly like the first one - it will be slightly different\\n\
 because of the terrain around it.  You probably want to build\\n\
-settlers here too.'))
+settlers here too."))
 elseif citiesbuilt == 2 then
   notify.event(city.owner, city.tile, E.TUTORIAL,
-_('You have built your third city!  Your civilization seems to be\\n\
+_("You have built your third city!  Your civilization seems to be\\n\
 thriving.  It might be time to think about a military.  Pick one of\\n\
 the cities that has a high production, and convert it into a military\\n\
 base. Build a Barracks there first, then start work on a military\\n\
 unit.  Pick the best unit you have available - at the beginning of\\n\
-the game, Warriors will be the only choice, but soon you wi have \\n\
+the game, Warriors will be the only choice, but soon you will have \\n\
 plenty of options.\\n\
 \\n\
 This might also be a good time to use the worklist feature of the\\n\
 city dialog production report.  Click on Barracks, then click Change\\n\
 to begin building them.  Then double-click on a military unit to\\n\
 append it to the worklist.  As soon as the Barracks are complete the\\n\
-city will automatically switch over to producing the unit.'))
+city will automatically switch over to producing the unit."))
 elseif citiesbuilt == 3 then
   notify.event(city.owner, city.tile, E.TUTORIAL,
-_('Another city!  You are really getting the hang of this.  You\\n\
+_("Another city!  You are really getting the hang of this.  You\\n\
 probably have a pretty good idea what to do with new cities by\\n\
 now.  Take a moment to look at the bar below the city on the map\\n\
 view.  This display shows some useful information about the city.\\n\
@@ -83,17 +83,17 @@
 will show one or more starts to indicate if there are units in the\\n\
 city.  The bottom row shows what the city is building, and how long it\\n\
 will take; it also shows how long the city will take to grow to the\\n\
-next largest size.'))
+next largest size."))
 elseif citiesbuilt == 4 then
   notify.event(city.owner, city.tile, E.TUTORIAL,
-_('As the number of cities in your empire grows, it becomes harder to\\n\
+_("As the number of cities in your empire grows, it becomes harder to\\n\
 manage individual cities.  This is where the city report becomes\\n\

[Freeciv-Dev] (PR#16350) Beta1: Tutorial translation not possible

2007-01-13 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=16350 >

>>> This leads to the fact that the complete tutorial is not translatable.

> I believe this is because the translatable strings are marked as
> _('...') instead of _("...")
>
> I tried changing this which made gettext recognize the strings, but
> broke the tutorial - because the [script] section is surrounded by
> code="..." I suppose.

 First patch allows ' and $ characters as border characters to strings
in addition to ". Ending character has to be same as starting
character and it can appear in between only if escaped with \,

 Second patch changes tutorial code section to use '$' border
characters and marks translatable strings with ".


 - ML

diff -Nurd -X.diff_ignore freeciv/utility/inputfile.c freeciv/utility/inputfile.c
--- freeciv/utility/inputfile.c	2006-07-17 23:56:21.0 +0300
+++ freeciv/utility/inputfile.c	2007-01-14 03:50:55.0 +0200
@@ -779,6 +779,7 @@
   char *c, *start;
   char trailing;
   bool has_i18n_marking = FALSE;
+  char border_character = '\"';
   
   assert(have_line(inf));
 
@@ -823,8 +824,13 @@
   return NULL;
   }
 
-  if (!(*c == '\"'))
+  border_character = *c;
+
+  if (border_character != '\"'
+  && border_character != '\''
+  && border_character != '$') {
 return NULL;
+  }
 
   /* From here, we know we have a string, we just have to find the
  trailing (un-escaped) double-quote.  We read in extra lines if
@@ -852,7 +858,7 @@
   for(;;) {
 int pos;
 
-while(*c != '\0' && *c != '\"') {
+while(*c != '\0' && *c != border_character) {
   /* skip over escaped chars, including backslash-doublequote,
 	 and backslash-backslash: */
   if (*c == '\\' && *(c+1) != '\0') {  
@@ -860,8 +866,11 @@
   }
   c++;
 }
-if (*c == '\"') 
-  break;  /* found end of string */
+
+if (*c == border_character) {
+  /* Found end of string */
+  break;
+}
 
 /* Accumulate to partial string and try more lines;
  * note partial->n must be _exactly_ the right size, so we
diff -Nurd -X.diff_ignore freeciv/utility/registry.c freeciv/utility/registry.c
--- freeciv/utility/registry.c	2007-01-13 03:18:47.0 +0200
+++ freeciv/utility/registry.c	2007-01-14 03:49:56.0 +0200
@@ -367,7 +367,9 @@
   pentry = sbuf_malloc(sb, sizeof(struct entry));
   pentry->name = sbuf_strdup(sb, name);
   pentry->comment = NULL;
-  if (tok[0] == '\"') {
+  if (tok[0] != '-' && !my_isdigit(tok[0])) {
+/* It is not integer, but string with some border character.
+ * We don't care what that border character is, we just skip it. */
 pentry->svalue = minstrdup(sb, tok+1);
 pentry->ivalue = 0;
 if (SECF_DEBUG_ENTRIES) {
diff -Nurd -X.diff_ignore freeciv/data/scenario/tutorial.sav freeciv/data/scenario/tutorial.sav
--- freeciv/data/scenario/tutorial.sav	2006-07-17 23:56:23.0 +0300
+++ freeciv/data/scenario/tutorial.sav	2007-01-14 03:59:06.0 +0200
@@ -4,15 +4,15 @@
 description=_("Tutorial Scenario.")
 
 [script]
-code="
+code=$
 function turn_callback(turn, year)
   if turn == 0 then
 notify.event(nil, nil, E.TUTORIAL,
-_('Welcome to Freeciv.  You lead a civilization.  Your\\n\
+_("Welcome to Freeciv.  You lead a civilization.  Your\\n\
 task is to conquer the world!  You should start by\\n\
 exploring the land around you with your explorer,\\n\
 and using your settlers to find a good place to build\\n\
-a city.  Use the number pad to move units around.'))
+a city.  Use the number pad to move units around."))
   end
 end
 signal.connect('turn_started', 'turn_callback')
@@ -24,12 +24,12 @@
   and (dst_tile.terrain.name == 'Grassland'
or dst_tile.terrain.name == 'Plains') then  
   notify.event(unit.owner, dst_tile, E.TUTORIAL,
-_('This looks like a good place to build a city.  The next time this\\n\
+_("This looks like a good place to build a city.  The next time this\\n\
 unit gets a chance to move, press (b) to found a city.\\n\
 \\n\
 In general you want to build cities on open ground near water.  Food\\n\
 is the most important resource for any city.  Grassland and plains\\n\
-provide plenty of food.'))
+provide plenty of food."))
 end
   end
 end
@@ -39,7 +39,7 @@
   if city.owner:is_human() then
 if citiesbuilt == 0 then
   notify.event(city.owner, city.tile, E.TUTORIAL,
-_('Now you have built your first city.  The city window should have\\n\
+_("Now you have built your first city.  The city window should have\\n\
 opened automatically; if not click on the city to open it.  Cities are\\n\
 a fundamental concept in Freeciv, so you should familiarize yourself\\n\
 with them by playing around in the window.  See the help menu for more.\\n\
@@ -49,31 +49,31 @@
 settler unit from the list of possible productions, then click on the\\n\
 Change button to begin building it.  When you are done, close the city\\n\
 dialog.  If all goes well the city should display the settler\\n\
-production on