<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39427 >

This is the last of the translate_data_names() fixes.  To quote the FIXME:

  FIXME: Because of the way translate_data_names works, ruleset names
  aren't normally translated at the client until the game starts.  Obviously
  this is incorrect.  The current workaround is to duplicate the translation
  inside packhand.c.  The real solution though is to get rid of the
  translate_data_names function and do all translation when the text is
  first generated.

For these structures, that is now finished!  And there is much rejoicing!

(Actually, it turns out there are more to do, initialized in a haphazard
fashion all over the code base, even more problematic.  This was a nicely
centralized description of the problem.)

===

The city style is rarely referenced, and the change was only a few lines.
It seemed best to combine the effort.

===

The unit_class has been substantially changed from S2_1 to trunk.

The trunk has a unit_class section in the rulesets.

However, S2_1 has a static list of class names.  It *always* uses these
untranslated names in *translated* messages!  (They were completely
unused otherwise.)  They are missing the N_(), so they have never been in
the *.po -- although 2 are in *.po for other references.

This patch uses the old table as initialization for name translation.
It's a trifle messy, but it seems to run without crashing....  Although
only 2 names will be translated, that's better than none!

===

Finally, I spent some time trying to find the compile errors in SDL,
reported at PR#39405, without actually compiling or running SDL.

As I was actively comparing S2_1 with trunk for unit classes, I found
many places that had been done properly in trunk, but not ported back to
S2_1, or vice versa.  The code base is getting rather out-of-sync.

No promises, but should be a bit better....

Index: server/scripting/api.pkg
===================================================================
--- server/scripting/api.pkg    (revision 13038)
+++ server/scripting/api.pkg    (working copy)
@@ -81,8 +81,6 @@
 };
 
 struct Unit_Type {
-  const char *name_rule @ name;
-
   int build_cost;
 
   const int index @ id;
Index: server/ruleset.c
===================================================================
--- server/ruleset.c    (revision 13038)
+++ server/ruleset.c    (working copy)
@@ -864,8 +864,8 @@
     const int i = punittype->index;
     char *name = secfile_lookup_str(file, "%s.name", sec[i]);
 
-    name_strlcpy(punittype->name_rule, name);
-    punittype->name_translated = NULL;
+    name_strlcpy(punittype->name.vernacular, name);
+    punittype->name.translated = NULL;
   } unit_type_iterate_end;
 
   free(sec);
@@ -1021,7 +1021,7 @@
     const int i = u->index;
 
     u->tech_requirement = lookup_tech(file, sec[i], "tech_req",
-                                     TRUE, filename, u->name_rule);
+                                     TRUE, filename, u->name.vernacular);
     if (section_file_lookup(file, "%s.gov_req", sec[i])) {
       char tmp[200] = "\0";
       mystrlcat(tmp, sec[i], 200);
@@ -1036,7 +1036,7 @@
     const int i = u->index;
 
     u->obsoleted_by = lookup_unit_type(file, sec[i], "obsolete_by",
-                                      FALSE, filename, u->name_rule);
+                                      FALSE, filename, u->name.vernacular);
   } unit_type_iterate_end;
 
   /* main stats: */
@@ -1045,14 +1045,14 @@
     struct unit_class *pclass;
 
     u->impr_requirement = lookup_building(file, sec[i], "impr_req",
-                                         FALSE, filename, u->name_rule);
+                                         FALSE, filename, u->name.vernacular);
 
     sval = secfile_lookup_str(file, "%s.class", sec[i]);
-    pclass = unit_class_from_str(sval);
+    pclass = find_unit_class_by_rule_name(sval);
     if (!pclass) {
       freelog(LOG_FATAL, "\"%s\" unit_type \"%s\": bad class \"%s\".",
               filename,
-              u->name_rule,
+              u->name.vernacular,
               sval);
       exit(EXIT_FAILURE);
     }
@@ -1110,7 +1110,7 @@
                          "  If you want no attack ability,"
                          " set the unit's attack strength to 0.",
               filename,
-              u->name_rule,
+              u->name.vernacular,
               u->firepower);
       exit(EXIT_FAILURE);
     }
@@ -1151,7 +1151,7 @@
       if (ival==F_LAST) {
         freelog(LOG_ERROR, "\"%s\" unit_type \"%s\": bad flag name \"%s\".",
                 filename,
-                u->name_rule,
+                u->name.vernacular,
                 sval);
       }
       BV_SET(u->flags, ival);
@@ -1176,7 +1176,7 @@
       if (ival==L_LAST) {
         freelog(LOG_ERROR, "\"%s\" unit_type \"%s\": bad role name \"%s\".",
                 filename,
-                u->name_rule,
+                u->name.vernacular,
                 sval);
       }
       BV_SET(u->roles, ival - L_FIRST);
@@ -1191,7 +1191,7 @@
       freelog(LOG_ERROR,
               "\"%s\" unit_type \"%s\": depends on removed tech \"%s\".",
               filename,
-              u->name_rule,
+              u->name.vernacular,
               advances[u->tech_requirement].name_rule);
       u->tech_requirement = A_LAST;
     }
@@ -1241,7 +1241,7 @@
     if(u->move_type != SEA_MOVING) {
       freelog(LOG_FATAL, "\"%s\": Barbarian boat (%s) needs to be a sea unit.",
               filename,
-              u->name_rule);
+              u->name.vernacular);
       exit(EXIT_FAILURE);
     }
   }
@@ -2202,8 +2202,8 @@
 
     sz_strlcpy(temp_name,
               secfile_lookup_str(file, "%s.city_style", sec[i]));
-    pl->city_style = get_style_by_name(temp_name);
-    if (pl->city_style == -1) {
+    pl->city_style = find_city_style_by_rule_name(temp_name);
+    if (pl->city_style < 0) {
       freelog(LOG_ERROR,
              "Nation %s: city style \"%s\" is unknown, using default.", 
              nation_rule_name(pl),
@@ -2320,8 +2320,8 @@
   /* Get names, so can lookup for replacements: */
   for (i = 0; i < game.control.styles_count; i++) {
     char *style_name = secfile_lookup_str(file, "%s.name", styles[i]);
-    name_strlcpy(city_styles[i].name_orig, style_name);
-    city_styles[i].name = city_styles[i].name_orig;
+    name_strlcpy(city_styles[i].name.vernacular, style_name);
+    city_styles[i].name.translated = NULL;
   }
   free(styles);
 }
@@ -2418,11 +2418,12 @@
     if( strcmp(replacement, "-") == 0) {
       city_styles[i].replaced_by = -1;
     } else {
-      city_styles[i].replaced_by = get_style_by_name(replacement);
-      if(city_styles[i].replaced_by == -1) {
-        freelog(LOG_FATAL, "\"%s\": style \"%s\" replacement \"%s\" not found",
-                filename, city_styles[i].name, replacement);
-        exit(EXIT_FAILURE);
+      city_styles[i].replaced_by = find_city_style_by_rule_name(replacement);
+      if (city_styles[i].replaced_by < 0) {
+        freelog(LOG_ERROR, "\"%s\": style \"%s\" replacement \"%s\" not found",
+                filename,
+                city_style_rule_name(i),
+                replacement);
       }
     }
   }
@@ -2673,7 +2674,7 @@
 
   unit_type_iterate(u) {
     packet.id = u->index;
-    sz_strlcpy(packet.name, u->name_rule);
+    sz_strlcpy(packet.name, u->name.vernacular);
     sz_strlcpy(packet.sound_move, u->sound_move);
     sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
     sz_strlcpy(packet.sound_fight, u->sound_fight);
@@ -3032,7 +3033,7 @@
     } requirement_vector_iterate_end;
     city_p.reqs_count = j;
 
-    sz_strlcpy(city_p.name, city_styles[k].name_orig);
+    sz_strlcpy(city_p.name, city_styles[k].name.vernacular);
     sz_strlcpy(city_p.graphic, city_styles[k].graphic);
     sz_strlcpy(city_p.graphic_alt, city_styles[k].graphic_alt);
     sz_strlcpy(city_p.citizens_graphic, city_styles[k].citizens_graphic);
@@ -3131,7 +3132,6 @@
   load_ruleset_nations(&nationfile);
   load_ruleset_effects(&effectfile);
   load_ruleset_game();
-  translate_data_names();
 
   precalc_tech_data();
 
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 13038)
+++ server/savegame.c   (working copy)
@@ -1936,7 +1936,9 @@
   }
   gov = find_government_by_rule_name(name);
   if (gov == NULL) {
-    freelog(LOG_FATAL, "Unsupported government found \"%s\".", name);
+    freelog(LOG_FATAL, "Player%d: unsupported government \"%s\".",
+                       plrno,
+                       name);
     exit(EXIT_FAILURE);
   }
   plr->government = gov;
@@ -1984,16 +1986,24 @@
     char* old_order[4] = {"European", "Classical", "Tropical", "Asian"};
     c_s = secfile_lookup_int_default(file, 0, "player%d.city_style", plrno);
     if (c_s < 0 || c_s > 3) {
+      freelog(LOG_ERROR, "Player%d: unsupported city_style %d."
+                         " Changed to \"%s\".",
+                         plrno,
+                         c_s,
+                         old_order[0]);
       c_s = 0;
     }
     p = old_order[c_s];
   }
-  c_s = get_style_by_name_orig(p);
-  if (c_s == -1) {
-    freelog(LOG_ERROR, "Unsupported city style found in player%d section. "
-                         "Changed to \"%s\".", plrno, get_city_style_name(0));
+  c_s = find_city_style_by_rule_name(p);
+  if (c_s < 0) {
+    freelog(LOG_ERROR, "Player%d: unsupported city_style_name \"%s\"."
+                       " Changed to \"%s\".",
+                       plrno,
+                       p,
+                       city_style_rule_name(0));
     c_s = 0;
-  }    
+  }
   plr->city_style = c_s;
 
   plr->nturns_idle=0;
@@ -2753,7 +2763,7 @@
   secfile_insert_int(file, 0, "player%d.city_style", plrno);
 
   /* This is the new city style field to be used */
-  secfile_insert_str(file, get_city_style_name_orig(plr->city_style),
+  secfile_insert_str(file, city_style_rule_name(plr->city_style),
                       "player%d.city_style_by_name", plrno);
 
   secfile_insert_bool(file, plr->is_male, "player%d.is_male", plrno);
Index: server/plrhand.c
===================================================================
--- server/plrhand.c    (revision 13038)
+++ server/plrhand.c    (working copy)
@@ -855,7 +855,7 @@
   packet->team = plr->team ? plr->team->index : -1;
   packet->is_ready = plr->is_ready;
   if (city_styles != NULL) {
-    packet->city_style = get_player_city_style(plr);
+    packet->city_style = city_style_of_player(plr);
   } else {
     packet->city_style = 0;
   }
Index: common/unittype.c
===================================================================
--- common/unittype.c   (revision 13038)
+++ common/unittype.c   (working copy)
@@ -33,6 +33,7 @@
 #include "unittype.h"
 
 static struct unit_type unit_types[U_LAST];
+static struct unit_class unit_classes[UCL_LAST];
 /* the unit_types array is now setup in:
    server/ruleset.c (for the server)
    client/packhand.c (for the client)
@@ -57,15 +58,21 @@
   "GameLoss", "Diplomat", "Hunter"
 };
 static const char *unit_class_names[] = {
-  "Missile",
-  "Land",
-  "Sea",
-  "Helicopter",
-  "Air",
-  "Nuclear",
+  N_("Missile"),
+  N_("Land"),
+  N_("Sea"),
+  N_("Helicopter"),
+  N_("Air"),
+  N_("Nuclear"),
 };
 
-struct unit_class unit_classes[] = {
+struct unit_class_setup {
+  Unit_Class_id id;
+  struct move_params move;
+  int hp_loss_pct;
+};
+
+struct unit_class_setup unit_class_setup[] = {
   { UCL_MISSILE,    { FALSE, FALSE },  0 },
   { UCL_LAND,       { TRUE,  TRUE  },  0 },
   { UCL_SEA,        { TRUE,  TRUE  },  0 },
@@ -208,13 +215,13 @@
 **************************************************************************/
 const char *utype_name_translation(struct unit_type *punittype)
 {
-  if (NULL == punittype->name_translated) {
+  if (NULL == punittype->name.translated) {
     /* delayed (unified) translation */
-    punittype->name_translated = ('\0' == punittype->name_rule[0])
-                                ? punittype->name_rule
-                                : Q_(punittype->name_rule);
+    punittype->name.translated = ('\0' == punittype->name.vernacular[0])
+                                ? punittype->name.vernacular
+                                : Q_(punittype->name.vernacular);
   }
-  return punittype->name_translated;
+  return punittype->name.translated;
 }
 
 /**************************************************************************
@@ -232,7 +239,7 @@
 **************************************************************************/
 const char *utype_rule_name(const struct unit_type *punittype)
 {
-  return punittype->name_rule;
+  return punittype->name.vernacular;
 }
 
 /**************************************************************************
@@ -283,12 +290,19 @@
 }
 
 /**************************************************************************
-  Returns the name of the unit class.
+  Return the (translated) name of the unit class.
+  You don't have to free the return pointer.
 **************************************************************************/
-const char *unit_class_name(const struct unit_class *pclass)
+const char *uclass_name_translation(struct unit_class *pclass)
 {
   assert(pclass != NULL && &unit_classes[pclass->id] == pclass);
-  return unit_class_names[pclass->id];
+  if (NULL == pclass->name.translated) {
+    /* delayed (unified) translation */
+    pclass->name.translated = ('\0' == pclass->name.vernacular[0])
+                             ? pclass->name.vernacular
+                             : Q_(pclass->name.vernacular);
+  }
+  return pclass->name.translated;
 }
 
 /**************************************************************************
@@ -408,17 +422,17 @@
 }
 
 /**************************************************************************
-  Convert Unit_Class_id names to enum; case insensitive;
-  returns NULL if can't match.
+  Returns the unit class that has the given (untranslated) rule name.
+  Returns NULL if none match.
 **************************************************************************/
-struct unit_class *unit_class_from_str(const char *s)
+struct unit_class *find_unit_class_by_rule_name(const char *s)
 {
   Unit_Class_id i;
 
   assert(ARRAY_SIZE(unit_class_names) == UCL_LAST);
 
   for (i = 0; i < UCL_LAST; i++) {
-    if (mystrcasecmp(unit_class_names[i], s)==0) {
+    if (0 == mystrcasecmp(unit_classes[i].name.vernacular, s)) {
       return &unit_classes[i];
     }
   }
@@ -767,3 +781,24 @@
 {
   return utype_class(unit_type(punit));
 }
+
+/****************************************************************************
+  Initialize unit_class structures.
+****************************************************************************/
+void unit_classes_init(void)
+{
+  int i;
+
+  assert(ARRAY_SIZE(unit_classes) == ARRAY_SIZE(unit_class_setup));
+
+  /* Can't use unit_class_iterate or uclass_by_number here because
+   * num_unit_classes isn't known yet. */
+  for (i = 0; i < ARRAY_SIZE(unit_classes); i++) {
+    unit_classes[i].id = i;
+    assert(i == unit_class_setup[i].id);
+    sz_strlcpy(unit_classes[i].name.vernacular, unit_class_names[i]);
+    unit_classes[i].name.translated = NULL;
+    unit_classes[i].move = unit_class_setup[i].move;
+    unit_classes[i].hp_loss_pct = unit_class_setup[i].hp_loss_pct;
+  }
+}
Index: common/unittype.h
===================================================================
--- common/unittype.h   (revision 13038)
+++ common/unittype.h   (working copy)
@@ -32,6 +32,7 @@
 
 struct unit_class {
   Unit_Class_id id;
+  struct translation_cache name;
   struct move_params move;
   int hp_loss_pct;         /* Percentage of hitpoints lost each turn not in 
city or airbase */
 };
@@ -145,8 +146,7 @@
 
 struct unit_type {
   int index;
-  const char *name_translated;         /* string doesn't need freeing */
-  char name_rule[MAX_LEN_NAME];                /* original name for 
comparisons */
+  struct translation_cache name;
   char graphic_str[MAX_LEN_NAME];
   char graphic_alt[MAX_LEN_NAME];
   char sound_move[MAX_LEN_NAME];
@@ -210,12 +210,6 @@
 int unit_disband_shields(const struct unit_type *punittype);
 int unit_pop_value(const struct unit_type *punittype);
 
-struct unit_class *unit_class(const struct unit *punit);
-struct unit_class *uclass_by_number(const int id);
-struct unit_class *utype_class(const struct unit_type *punittype);
-
-const char *unit_class_name(const struct unit_class *pclass);
-
 const char *unit_rule_name(const struct unit *punit);
 const char *utype_rule_name(const struct unit_type *punittype);
 
@@ -238,7 +232,14 @@
 struct unit_type *find_unit_type_by_rule_name(const char *name);
 struct unit_type *find_unit_type_by_translated_name(const char *name);
 
-struct unit_class *unit_class_from_str(const char *s);
+struct unit_class *unit_class(const struct unit *punit);
+struct unit_class *utype_class(const struct unit_type *punittype);
+struct unit_class *uclass_by_number(const int id);
+
+const char *uclass_name_translation(struct unit_class *pclass);
+
+struct unit_class *find_unit_class_by_rule_name(const char *s);
+
 enum unit_flag_id unit_flag_from_str(const char *s);
 enum unit_role_id unit_role_from_str(const char *s);
 
@@ -264,6 +265,8 @@
 void unit_types_init(void);
 void unit_types_free(void);
 
+void unit_classes_init(void);
+
 #define unit_type_iterate(punittype)                                       \
 {                                                                          \
   int _index;                                                              \
Index: common/city.c
===================================================================
--- common/city.c       (revision 13038)
+++ common/city.c       (working copy)
@@ -1096,9 +1096,9 @@
 /**************************************************************************
 Evaluate which style should be used to draw a city.
 **************************************************************************/
-int get_city_style(const struct city *pcity)
+int style_of_city(const struct city *pcity)
 {
-  return get_player_city_style(city_owner(pcity));
+  return city_style_of_player(city_owner(pcity));
 }
 
 /**************************************************************************
@@ -1106,7 +1106,7 @@
   the client) for this city.  The city style depends on the
   start-of-game choice by the player as well as techs researched.
 **************************************************************************/
-int get_player_city_style(const struct player *plr)
+int city_style_of_player(const struct player *plr)
 {
   int replace, style, prev;
 
@@ -1123,61 +1123,65 @@
   return style;
 }
 
-/**************************************************************************
-  Get index to city_styles for style name.
-**************************************************************************/
-int get_style_by_name(const char *style_name)
+/****************************************************************************
+  Returns the city style that has the given (translated) name.
+  Returns -1 if none match.
+****************************************************************************/
+int find_city_style_by_translated_name(const char *s)
 {
   int i;
 
   for (i = 0; i < game.control.styles_count; i++) {
-    /* City styles use Q_ so a city style may be called "?citystyle:Asian".
-     * We use Qn_ so that this string will match against "Asian". */
-    if (strcmp(Qn_(style_name), Qn_(city_styles[i].name)) == 0) {
-      break;
+    if (0 == strcmp(city_style_name_translation(i), s)) {
+      return i;
     }
   }
-  if (i < game.control.styles_count) {
-    return i;
-  } else {
-    return -1;
-  }
+
+  return -1;
 }
 
-/**************************************************************************
-  Get index to city_styles for untranslated style name.
-**************************************************************************/
-int get_style_by_name_orig(const char *style_name)
+/****************************************************************************
+  Returns the city style that has the given (untranslated) rule name.
+  Returns -1 if none match.
+****************************************************************************/
+int find_city_style_by_rule_name(const char *s)
 {
   int i;
 
   for (i = 0; i < game.control.styles_count; i++) {
-    if (strcmp(style_name, city_styles[i].name_orig) == 0) {
-      break;
+    if (0 == mystrcasecmp(city_style_rule_name(i), s)) {
+      return i;
     }
   }
-  if (i < game.control.styles_count) {
-    return i;
-  } else {
-    return -1;
-  }
+
+  return -1;
 }
 
-/**************************************************************************
-  Get name of given city style.
-**************************************************************************/
-const char *get_city_style_name(int style)
+/****************************************************************************
+  Return the (translated) name of the given city style. 
+  You don't have to free the return pointer.
+****************************************************************************/
+const char *city_style_name_translation(const int style)
 {
-   return city_styles[style].name;
+  struct citystyle *csp = &city_styles[style];
+
+  if (NULL == csp->name.translated) {
+    /* delayed (unified) translation */
+    csp->name.translated = ('\0' == csp->name.vernacular[0])
+                          ? csp->name.vernacular
+                          : Q_(csp->name.vernacular);
+  }
+  return csp->name.translated;
 }
 
 
-/**************************************************************************
-  Get untranslated name of city style.
-**************************************************************************/
-char* get_city_style_name_orig(int style)
+/****************************************************************************
+  Return the (untranslated) rule name of the city style.
+  You don't have to free the return pointer.
+****************************************************************************/
+const char* city_style_rule_name(const int style)
 {
-   return city_styles[style].name_orig;
+   return city_styles[style].name.vernacular;
 }
 
 /****************************************************************************
Index: common/city.h
===================================================================
--- common/city.h       (revision 13038)
+++ common/city.h       (working copy)
@@ -310,8 +310,7 @@
 };
 
 struct citystyle {
-  const char *name; /* Translated string - doesn't need freeing. */
-  char name_orig[MAX_LEN_NAME];              /* untranslated */
+  struct translation_cache name;
   char graphic[MAX_LEN_NAME];
   char graphic_alt[MAX_LEN_NAME];
   char citizens_graphic[MAX_LEN_NAME];
@@ -458,13 +457,15 @@
 int city_name_compare(const void *p1, const void *p2);
 
 /* city style functions */
-int get_city_style(const struct city *pcity);
-int get_player_city_style(const struct player *plr);
-int get_style_by_name(const char *);
-int get_style_by_name_orig(const char *);
-const char *get_city_style_name(int style);
-char* get_city_style_name_orig(int style);
+const char *city_style_rule_name(const int style);
+const char *city_style_name_translation(const int style);
+
+int find_city_style_by_rule_name(const char *s);
+int find_city_style_by_translated_name(const char *s);
+
 bool city_style_has_requirements(const struct citystyle *style);
+int city_style_of_player(const struct player *plr);
+int style_of_city(const struct city *pcity);
 
 struct city *is_enemy_city_tile(const struct tile *ptile,
                                const struct player *pplayer);
Index: common/game.c
===================================================================
--- common/game.c       (revision 13038)
+++ common/game.c       (working copy)
@@ -293,6 +293,7 @@
   terrains_init();
   improvements_init();
   techs_init();
+  unit_classes_init();
   unit_types_init();
   specialists_init();
   teams_init();
@@ -576,40 +577,6 @@
   return game.info.simultaneous_phases || pplayer->player_no == phase;
 }
 
-/***************************************************************
-  For various data, copy eg .name to .name_orig and put
-  translated version in .name
-  (These could be in the separate modules, but since they are
-  all almost the same, and all needed together, it seems a bit
-  easier to just do them all here.)
-
-  FIXME: Because of the way translate_data_names works, ruleset names
-  aren't normally translated at the client until the game starts.  Obviously
-  this is incorrect.  The current workaround is to duplicate the translation
-  inside packhand.c.  The real solution though is to get rid of the
-  translate_data_names function  and do all translation when the text is
-  first generated.
-***************************************************************/
-void translate_data_names(void)
-{
-  int i;
-
-  /* advance_name_translation now handled in tech.c */
-  /* utype_name_translation now handled in unittype.c */
-  /* improvement_name_translation now handled in improvement.c */
-  /* terrain_name_translation now handled in terrain.c */
-  /* resource_name_translation now handled in terrain.c */
-  /* government_name_translation now handled in government.c */
-  /* nation_name_translation now handled in nation.c */
-
-  for (i = 0; i < game.control.styles_count; i++) {
-    struct citystyle *tthis = &city_styles[i];
-
-    tthis->name = Q_(tthis->name_orig);
-  }
-
-}
-
 /****************************************************************************
   Return a prettily formatted string containing the population text.  The
   population is passed in as the number of citizens, in thousands.
Index: common/game.h
===================================================================
--- common/game.h       (revision 13038)
+++ common/game.h       (working copy)
@@ -137,8 +137,6 @@
 void game_remove_city(struct city *pcity);
 void initialize_globals(void);
 
-void translate_data_names(void);
-
 struct player *get_player(int player_id);
 bool is_valid_player_id(int player_id);
 int get_num_human_and_ai_players(void);
Index: common/requirements.c
===================================================================
--- common/requirements.c       (revision 13038)
+++ common/requirements.c       (working copy)
@@ -152,7 +152,7 @@
     }
     break;
   case REQ_UNITCLASS:
-    source.value.unitclass = unit_class_from_str(value);
+    source.value.unitclass = find_unit_class_by_rule_name(value);
     if (source.value.unitclass) {
       return source;
     }
@@ -1027,7 +1027,7 @@
     break;
   case REQ_UNITCLASS:
     cat_snprintf(buf, bufsz, _("%s units"),
-                unit_class_name(psource->value.unitclass));
+                uclass_name_translation(psource->value.unitclass));
     break;
   case REQ_OUTPUTTYPE:
     mystrlcat(buf, get_output_name(psource->value.outputtype), bufsz);
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c        (revision 13038)
+++ client/gui-gtk-2.0/dialogs.c        (working copy)
@@ -893,7 +893,7 @@
     g_object_ref(img);
     free_sprite(s);
     gtk_list_store_set(store, &it, 0, i, 1, img, 2,
-                       get_city_style_name(i), -1);
+                       city_style_name_translation(i), -1);
     g_object_unref(img);
   }
 
Index: client/gui-xaw/dialogs.c
===================================================================
--- client/gui-xaw/dialogs.c    (revision 13038)
+++ client/gui-xaw/dialogs.c    (working copy)
@@ -1226,7 +1226,7 @@
 
   for(i=0; i<b_s_num; i++) {
     XtVaSetValues(races_style_toggles[i], XtNlabel,
-                 (XtArgVal)city_styles[city_style_idx[i]].name, NULL);
+                 (XtArgVal)city_style_name_translation(city_style_idx[i]), 
NULL);
   }
 
   select_random_race();
Index: client/gui-win32/dialogs.c
===================================================================
--- client/gui-win32/dialogs.c  (revision 13038)
+++ client/gui-win32/dialogs.c  (working copy)
@@ -589,7 +589,7 @@
     }
   }
   for(i = 0; i < b_s_num; i++) {
-    fcwin_box_add_radiobutton(input_box, city_styles[city_style_idx[i]].name,
+    fcwin_box_add_radiobutton(input_box, 
city_style_name_translation(city_style_idx[i]),
                              ID_RACESDLG_STYLE_BASE + i, 0, TRUE, TRUE, 0);
   }
 
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 13038)
+++ client/packhand.c   (working copy)
@@ -2151,8 +2151,8 @@
   }
   u = utype_by_number(p->id);
 
-  sz_strlcpy(u->name_rule, p->name);
-  u->name_translated = NULL;   /* unittype.c utype_name_translation */
+  sz_strlcpy(u->name.vernacular, p->name);
+  u->name.translated = NULL;   /* unittype.c utype_name_translation */
   sz_strlcpy(u->graphic_str, p->graphic_str);
   sz_strlcpy(u->graphic_alt, p->graphic_alt);
   sz_strlcpy(u->sound_move, p->sound_move);
@@ -2554,8 +2554,8 @@
   assert(cs->reqs.size == packet->reqs_count);
   cs->replaced_by = packet->replaced_by;
 
-  sz_strlcpy(cs->name_orig, packet->name);
-  cs->name = Q_(cs->name_orig); /* See translate_data_names */
+  sz_strlcpy(cs->name.vernacular, packet->name);
+  cs->name.translated = NULL;
   sz_strlcpy(cs->graphic, packet->graphic);
   sz_strlcpy(cs->graphic_alt, packet->graphic_alt);
   sz_strlcpy(cs->citizens_graphic, packet->citizens_graphic);
Index: client/gui-sdl/citydlg.c
===================================================================
--- client/gui-sdl/citydlg.c    (revision 13038)
+++ client/gui-sdl/citydlg.c    (working copy)
@@ -693,7 +693,8 @@
     pUType = unit_type(pUnit);
     pHome_City = find_city_by_id(pUnit->homecity);
     my_snprintf(cBuf, sizeof(cBuf), "%s (%d,%d,%d)%s\n%s\n(%d/%d)\n%s",
-               pUType->name, pUType->attack_strength,
+               utype_name_translation(pUType),
+               pUType->attack_strength,
                pUType->defense_strength, pUType->move_rate / SINGLE_MOVE,
                 (pUnit->veteran ? _("\nveteran") : ""),
                 unit_activity_text(pUnit),
@@ -3873,7 +3874,7 @@
   pCityDlg->pBeginCityWidgetList = pBuf;
   
   /* check if Citizen Icons style was loaded */
-  cs = get_city_style(pCity);
+  cs = style_of_city(pCity);
 
   if (cs != pIcons->style) {
     reload_citizens_icons(cs);
Index: client/gui-sdl/mapview.c
===================================================================
--- client/gui-sdl/mapview.c    (revision 13038)
+++ client/gui-sdl/mapview.c    (working copy)
@@ -309,7 +309,7 @@
   
   if (game.player_ptr) {
     my_snprintf(cBuf, sizeof(cBuf), "%s (%s)\n%s", _("Revolution"), "Shift+R",
-                                    
government_of_player(game.player_ptr)->name);
+                                    
government_name_for_player(game.player_ptr));
   } else {
     my_snprintf(cBuf, sizeof(cBuf), "%s (%s)\n%s", _("Revolution"), "Shift+R",
                                     "None");
@@ -489,14 +489,15 @@
   static char s[256];
   bool first;
 
-  sz_strlcpy(s, ptile->terrain->name);
+  sz_strlcpy(s, terrain_name_translation(ptile->terrain));
   if (tile_has_special(ptile, S_RIVER)) {
     sz_strlcat(s, "/");
     sz_strlcat(s, get_special_name(S_RIVER));
   }
 
   if (ptile->resource) {
-    cat_snprintf(s, sizeof(s), " (%s)", ptile->resource->name);
+    cat_snprintf(s, sizeof(s), " (%s)",
+                resource_name_translation(ptile->resource));
   }
 
   first = TRUE;
@@ -633,7 +634,7 @@
     mil -= types_count[top[i]->index];
   }
   astr_add_line(&str, "%d: %s",
-          types_count[top[i]->index], top[i]->name);
+          types_count[top[i]->index], utype_name_translation(top[i]));
       } else {
   astr_add_line(&str, " ");
       }
@@ -934,7 +935,8 @@
          pUType = unit_type(aunit);
           pHome_City = find_city_by_id(aunit->homecity);
           my_snprintf(buffer, sizeof(buffer), "%s 
(%d,%d,%d)%s\n%s\n(%d/%d)\n%s",
-               pUType->name, pUType->attack_strength,
+               utype_name_translation(pUType),
+               pUType->attack_strength,
                pUType->defense_strength, pUType->move_rate / SINGLE_MOVE,
                 (aunit->veteran ? _("\nveteran") : ""),
                 unit_activity_text(aunit),
@@ -1138,7 +1140,6 @@
   redraw_unit_info_label(punitlist);
   
   if (punitlist) {
-
     if(!is_anim_enabled()) {
       enable_focus_animation();
     }
Index: client/gui-sdl/repodlgs.c
===================================================================
--- client/gui-sdl/repodlgs.c   (revision 13038)
+++ client/gui-sdl/repodlgs.c   (working copy)
@@ -183,7 +183,8 @@
     my_snprintf(cBuf, sizeof(cBuf),
           _("Upgrade as many %s to %s as possible for %d gold each?\n"
             "Treasury contains %d gold."),
-          ut1.name, ut2->name,
+          utype_name_translation(&ut1),
+          utype_name_translation(ut2),
           value, game.player_ptr->economic.gold);
    
     
Index: client/gui-sdl/menu.c
===================================================================
--- client/gui-sdl/menu.c       (revision 13038)
+++ client/gui-sdl/menu.c       (working copy)
@@ -1035,18 +1035,18 @@
       if (can_unit_do_activity(pUnit, ACTIVITY_IRRIGATE)) {
        time = tile_activity_time(ACTIVITY_IRRIGATE, pUnit->tile);
 
-        if (!strcmp(pTile->terrain->name, "Forest") ||
-          !strcmp(pTile->terrain->name, "Jungle")) {
+        if (!strcmp(terrain_rule_name(pTile->terrain), "Forest") ||
+          !strcmp(terrain_rule_name(pTile->terrain), "Jungle")) {
          /* set Crop Forest Icon */
          my_snprintf(cBuf, sizeof(cBuf),"%s %s%s %d %s",
                        _("Cut Down to"),
-                pTile->terrain->irrigation_result->name
+                terrain_name_translation(pTile->terrain->irrigation_result)
                        ," (I)", time , PL_("turn", "turns", time));
          pOrder_Irrigation_Button->theme = pTheme->OCutDownForest_Icon;
-        }      else if (!strcmp(pTile->terrain->name, "Swamp")) {
+        }      else if (!strcmp(terrain_rule_name(pTile->terrain), "Swamp")) {
          my_snprintf(cBuf, sizeof(cBuf),"%s %s%s %d %s",
                        _("Irrigate to"),
-                pTile->terrain->irrigation_result->name
+                terrain_name_translation(pTile->terrain->irrigation_result)
                        ," (I)", time , PL_("turn", "turns", time));
          pOrder_Irrigation_Button->theme = pTheme->OIrrigation_Icon;
         } else {
@@ -1066,17 +1066,17 @@
       if (can_unit_do_activity(pUnit, ACTIVITY_MINE)) {
        time = tile_activity_time(ACTIVITY_MINE, pUnit->tile);
 
-   if (!strcmp(pTile->terrain->name, "Forest")) {  
+   if (!strcmp(terrain_rule_name(pTile->terrain), "Forest")) {  
          /* set Irrigate Icon -> make swamp */
          my_snprintf(cBuf, sizeof(cBuf),"%s %s%s %d %s",
                        _("Irrigate to"),
-                       pTile->terrain->mining_result->name
+                       terrain_name_translation(pTile->terrain->mining_result)
                        ," (M)", time , PL_("turn", "turns", time));
          pOrder_Mine_Button->theme = pTheme->OIrrigation_Icon;
-   } else if (!strcmp(pTile->terrain->name, "Jungle") ||
-              !strcmp(pTile->terrain->name, "Plains") ||
-              !strcmp(pTile->terrain->name, "Grassland") ||
-              !strcmp(pTile->terrain->name, "Swamp")) {
+   } else if (!strcmp(terrain_rule_name(pTile->terrain), "Jungle") ||
+              !strcmp(terrain_rule_name(pTile->terrain), "Plains") ||
+              !strcmp(terrain_rule_name(pTile->terrain), "Grassland") ||
+              !strcmp(terrain_rule_name(pTile->terrain), "Swamp")) {
          /* set Forest Icon -> plant Forrest*/
          my_snprintf(cBuf, sizeof(cBuf),"%s%s %d %s",
                        _("Plant Forest"), " (M)", time , 
@@ -1101,7 +1101,7 @@
        time = tile_activity_time(ACTIVITY_TRANSFORM, pUnit->tile);
        my_snprintf(cBuf, sizeof(cBuf),"%s %s%s %d %s",
          _("Transform to"),
-         pTile->terrain->transform_result->name,
+         terrain_name_translation(pTile->terrain->transform_result),
                        " (M)", time , 
                        PL_("turn", "turns", time));
        copy_chars_to_string16(pOrder_Transform_Button->string16, cBuf);
Index: client/gui-sdl/cma_fe.c
===================================================================
--- client/gui-sdl/cma_fe.c     (revision 13038)
+++ client/gui-sdl/cma_fe.c     (working copy)
@@ -1197,7 +1197,7 @@
   
   /* ------------------------ */
   /* check if Citizen Icons style was loaded */
-  cs = get_city_style(pCma->pCity);
+  cs = style_of_city(pCma->pCity);
 
   if (cs != pIcons->style) {
     reload_citizens_icons(cs);
Index: client/gui-sdl/dialogs.c
===================================================================
--- client/gui-sdl/dialogs.c    (revision 13038)
+++ client/gui-sdl/dialogs.c    (working copy)
@@ -667,7 +667,7 @@
       int att_chance, def_chance;
       
       my_snprintf(cBuf , sizeof(cBuf), _("%s %s %s(A:%d D:%d M:%d FP:%d) 
HP:%d%%"),
-            nation_of_player(unit_owner(pUnit))->name,
+            nation_name_translation(nation_of_unit(pUnit)),
             (pUnit->veteran ? _("Veteran") : ""),
             utype_name_translation(pUnitType),
             pUnitType->attack_strength,
@@ -1408,7 +1408,7 @@
          int att_chance, def_chance;
          
           my_snprintf(cBuf, sizeof(cBuf), _("%s %s %s (A:%d D:%d M:%d FP:%d) 
HP:%d%%"),
-            nation_of_player(unit_owner(pUnit))->name,
+            nation_name_translation(nation_of_unit(pUnit)),
             (pUnit->veteran ? _("Veteran") : ""),
             utype_name_translation(pUnitType),
             pUnitType->attack_strength,
@@ -1533,7 +1533,7 @@
          int att_chance, def_chance;
        
           my_snprintf(cBuf, sizeof(cBuf), _("%s %s %s (A:%d D:%d M:%d FP:%d) 
HP:%d%%"),
-            nation_of_player(unit_owner(pUnit))->name,
+            nation_name_translation(nation_of_unit(pUnit)),
             (pUnit->veteran ? _("Veteran") : ""),
             utype_name_translation(pUnitType),
             pUnitType->attack_strength,
@@ -2496,7 +2496,7 @@
       pStr->fgcol = *get_game_colorRGB(COLOR_THEME_NATIONDLG_LEGEND);
       pText = create_text_surf_smaller_that_w(pStr, Main.screen->w - 
adj_size(20));
     
-      copy_chars_to_string16(pStr, Q_(pNation->name_plural));
+      copy_chars_to_string16(pStr, nation_plural_translation(pNation));
       pText2 = create_text_surf_from_str16(pStr);
     
       FREESTRING16(pStr);
@@ -2579,7 +2579,7 @@
   FREESURFACE(pLabel->theme);
   pLabel->theme = pTmp_Surf_zoomed;
   
-  copy_chars_to_string16(pLabel->string16, Q_(pNation->name_plural));
+  copy_chars_to_string16(pLabel->string16, nation_plural_translation(pNation));
   
   remake_label_size(pLabel);
   
@@ -2716,7 +2716,7 @@
 
     pTmp_Surf = crop_rect_from_surface(pMain_Bg, NULL);
           
-    copy_chars_to_string16(pStr, Q_(pNation->name_plural));
+    copy_chars_to_string16(pStr, nation_plural_translation(pNation));
     change_ptsize16(pStr, adj_font(12));
     pText_Name = create_text_surf_smaller_that_w(pStr, pTmp_Surf->w - 
adj_size(4));
     
Index: client/gui-sdl/helpdlg.c
===================================================================
--- client/gui-sdl/helpdlg.c    (revision 13038)
+++ client/gui-sdl/helpdlg.c    (working copy)
@@ -786,7 +786,8 @@
   } else {
     struct unit_type *utype = pUnitType->obsoleted_by;
     pBuf = create_iconlabel_from_chars(NULL, pWindow->dst,
-             utype->name, adj_font(12), WF_RESTORE_BACKGROUND);
+             utype_name_translation(utype),
+             adj_font(12), WF_RESTORE_BACKGROUND);
     pBuf->string16->fgcol = *get_tech_color(utype->tech_requirement);
     pBuf->ID = MAX_ID - pUnitType->obsoleted_by->index;
     pBuf->action = change_unit_callback;
Index: client/gui-sdl/wldlg.c
===================================================================
--- client/gui-sdl/wldlg.c      (revision 13038)
+++ client/gui-sdl/wldlg.c      (working copy)
@@ -828,9 +828,9 @@
   assert(cost != NULL);
         
   if(prod.is_unit) {
-    struct unit_type *pType = utype_by_number(prod.value);
-    *cost = unit_build_shield_cost(utype_by_number(prod.value));
-    return pType->name;
+    struct unit_type *pUType = utype_by_number(prod.value);
+    *cost = unit_build_shield_cost(pUType);
+    return utype_name_translation(pUType);
   } else {
     *cost = impr_build_shield_cost(prod.value);
     return get_impr_name_ex(pCity, prod.value);
Index: client/helpdata.c
===================================================================
--- client/helpdata.c   (revision 13038)
+++ client/helpdata.c   (working copy)
@@ -196,7 +196,7 @@
     return;
   case REQ_UNITCLASS:
     cat_snprintf(buf, bufsz, _("Only applies to %s units.\n\n"),
-                unit_class_name(req->source.value.unitclass));
+                uclass_name_translation(req->source.value.unitclass));
     return;
   case REQ_OUTPUTTYPE:
     cat_snprintf(buf, bufsz, _("Applies only to %s.\n\n"),
@@ -764,7 +764,7 @@
 
   if (utype->impr_requirement != B_LAST) {
     sprintf(buf + strlen(buf),
-            _("* Can only be built if there is %s in the city.\n"), 
+           _("* Can only be built if there is %s in the city.\n"), 
             improvement_name_translation(utype->impr_requirement));
   }
 
@@ -773,6 +773,7 @@
            _("* Can only be built with %s as government.\n"), 
             government_name_translation(utype->gov_requirement));
   }
+  
   if (utype_has_flag(utype, F_NOBUILD)) {
     sprintf(buf + strlen(buf),
            _("* May not be built in cities.\n"));
@@ -1414,7 +1415,7 @@
       case EFT_VETERAN_BUILD:
         if (unitclass) {
           sprintf(buf + strlen(buf), _("* Veteran %s units.\n"),
-                  unit_class_name(unitclass));
+                  uclass_name_translation(unitclass));
         } else if (unitflag != F_LAST) {
           sprintf(buf + strlen(buf), _("* Veteran %s units.\n"),
                   get_unit_flag_name(unitflag));
Index: client/gui-mui/dialogs.c
===================================================================
--- client/gui-mui/dialogs.c    (revision 13038)
+++ client/gui-mui/dialogs.c    (working copy)
@@ -1603,7 +1603,7 @@
       if(city_styles[i].techreq == A_NONE)
       {
         styles_basic_index[styles_basic_nums] = i;
-        styles_entries[styles_basic_nums] = city_styles[i].name;
+        styles_entries[styles_basic_nums] = city_style_name_translation(i);
         styles_basic_nums++;
       }
     }
Index: client/tilespec.c
===================================================================
--- client/tilespec.c   (revision 13038)
+++ client/tilespec.c   (working copy)
@@ -1907,7 +1907,7 @@
                                      const struct city *pcity)
 {
   /* get style and match the best tile based on city size */
-  int style = get_city_style(pcity);
+  int style = style_of_city(pcity);
   int num_thresholds = city_sprite->styles[style].num_thresholds;
   int t;
 
@@ -4286,18 +4286,18 @@
 
     for (style = 0; style < game.control.styles_count; style++) {
       if (t->sprites.city.tile->styles[style].num_thresholds == 0) {
-       freelog(LOG_ERROR, "No city graphics for \"%s\" style.",
-               city_styles[style].name);
+       freelog(LOG_FATAL, "City style \"%s\": no city graphics.",
+               city_style_rule_name(style));
        exit(EXIT_FAILURE);
       }
       if (t->sprites.city.wall->styles[style].num_thresholds == 0) {
-       freelog(LOG_ERROR, "No wall graphics for \"%s\" style.",
-               city_styles[style].name);
+       freelog(LOG_FATAL, "City style \"%s\": no wall graphics.",
+               city_style_rule_name(style));
        exit(EXIT_FAILURE);
       }
       if (t->sprites.city.occupied->styles[style].num_thresholds == 0) {
-       freelog(LOG_ERROR, "No occupied graphics for \"%s\" style.",
-               city_styles[style].name);
+       freelog(LOG_FATAL, "City style \"%s\": no occupied graphics.",
+               city_style_rule_name(style));
        exit(EXIT_FAILURE);
       }
     }
Index: client/civclient.c
===================================================================
--- client/civclient.c  (revision 13038)
+++ client/civclient.c  (working copy)
@@ -500,14 +500,10 @@
   if (client_state != newstate) {
 
     /* If changing from pre-game state to _either_ select race
-       or running state, then we have finished getting ruleset data,
-       and should translate data, for joining running game or for
-       selecting nations.  (Want translated nation names in nation
-       select dialog.)
+       or running state, then we have finished getting ruleset data.
     */
     if (client_state==CLIENT_PRE_GAME_STATE
        && newstate == CLIENT_GAME_RUNNING_STATE) {
-      translate_data_names();
       audio_stop();            /* stop intro sound loop */
     }
       
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to