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

Joan Creus wrote:
> In #: client/gui-gtk-2.0/happiness.c:252 client/gui-win32/happiness.c:204
> 
> the sentence is:
> 
> %d additional unhappy citizens.
> 
> %d is 1 in the default ruleset, so it would be good to have an option here.
> 
Thanks for bringing this to our attention.  Actually, it is a sentence
fragment as part of:

   "... %d content before penalty with %d additional unhappy citizens."

The noun "citizens" is implied after adjective "content", so you have both
content and unhappy citizens, even should that be 1 content and 0 unhappy.
In English, this would always be plural (multiple instances of citizens).

Sentence fragments like this are virtually impossible to translate.
Therefore, I divided it into two clauses, each is now on a separate line,
and each can be plural (range 0-21):

   Cities: %d total, %d over threshold of %d cities.
   %d content before penalty.
   %d additional unhappy citizens.

That's still clumsy, but all that I could easily do in the existing space,
while older translations will still flow in the same manner (the "with"
clause instead of the period).  That period would normally be a semi-colon,
but again, I'm not sure how easy that is to translate.  Most folks don't
know how to properly use semi-colons in English, anyway!

Improvement for 2.2 would be gratefully accepted....

Moreover, nearly identical text appears in several different clients.
These are all supposed to be in client/text.c, so I've moved this there,
adding some TRANS comments.  Eventually, SDL and xaw should use this, too.

Also, this fixes an obscure calculation bug in gui-win32, that probably had
gotten out-of-sync with the code base.  Multiple copies of nearly identical
code is usually a bad idea!  (PR#15747 and PR#33445)

Committed S2_1 revision 14245 with update-po to add TRANS comments.

I'll handle S2_1 and trunk later.

Index: client/gui-gtk-2.0/happiness.c
===================================================================
--- client/gui-gtk-2.0/happiness.c      (revision 14244)
+++ client/gui-gtk-2.0/happiness.c      (working copy)
@@ -64,16 +64,6 @@
 static struct happiness_dialog *get_happiness_dialog(struct city *pcity);
 static struct happiness_dialog *create_happiness_dialog(struct city
                                                        *pcity);
-static void happiness_dialog_update_cities(struct happiness_dialog
-                                          *pdialog);
-static void happiness_dialog_update_luxury(struct happiness_dialog
-                                          *pdialog);
-static void happiness_dialog_update_buildings(struct happiness_dialog
-                                             *pdialog);
-static void happiness_dialog_update_units(struct happiness_dialog
-                                         *pdialog);
-static void happiness_dialog_update_wonders(struct happiness_dialog
-                                           *pdialog);
 
 /****************************************************************
 ...
@@ -187,11 +177,16 @@
     refresh_pixcomm(GTK_PIXCOMM(pdialog->hpixmaps[i]), pdialog->pcity, i);
   }
 
-  happiness_dialog_update_cities(pdialog);
-  happiness_dialog_update_luxury(pdialog);
-  happiness_dialog_update_buildings(pdialog);
-  happiness_dialog_update_units(pdialog);
-  happiness_dialog_update_wonders(pdialog);
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[CITIES]),
+                    text_happiness_cities(pdialog->pcity));
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[LUXURIES]),
+                    text_happiness_luxuries(pdialog->pcity));
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[BUILDINGS]),
+                    text_happiness_buildings(pdialog->pcity));
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[UNITS]),
+                    text_happiness_units(pdialog->pcity));
+  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[WONDERS]),
+                    text_happiness_wonders(pdialog->pcity));
 }
 
 /**************************************************************************
@@ -216,125 +211,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void happiness_dialog_update_cities(struct happiness_dialog
-                                          *pdialog)
-{
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-
-  struct city *pcity = pdialog->pcity;
-  struct player *pplayer = city_owner(pcity);
-  int cities = city_list_size(pplayer->cities);
-  int content = game.info.unhappysize;
-  int basis = game.info.cityfactor 
-              + get_player_bonus(pplayer, EFT_EMPIRE_SIZE_MOD);
-  int step = get_player_bonus(pplayer, EFT_EMPIRE_SIZE_STEP);
-  int excess = cities - basis;
-  int penalty = 0;
-
-  if (excess > 0) {
-    if (step > 0)
-      penalty = 1 + (excess - 1) / step;
-    else
-      penalty = 1;
-  } else {
-    excess = 0;
-    penalty = 0;
-  }
-
-  my_snprintf(bptr, nleft,
-             _("Cities: %d total, %d over threshold of %d cities.\n"),
-             cities, excess, basis);
-  bptr = end_of_strn(bptr, &nleft);
-
-  my_snprintf(bptr, nleft, _("%d content before penalty with "), content);
-  bptr = end_of_strn(bptr, &nleft);
-  my_snprintf(bptr, nleft, _("%d additional unhappy citizens."), penalty);
-  bptr = end_of_strn(bptr, &nleft);
-
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[CITIES]), buf);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_luxury(struct happiness_dialog
-                                          *pdialog)
-{
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-
-  my_snprintf(bptr, nleft, _("Luxury: %d total."),
-             pcity->prod[O_LUXURY]);
-
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[LUXURIES]), buf);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_buildings(struct happiness_dialog
-                                             *pdialog)
-{
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[BUILDINGS]),
-                    get_happiness_buildings(pdialog->pcity));
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_units(struct happiness_dialog *pdialog)
-{
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-  int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
-  int uhcfac = get_city_bonus(pcity, EFT_UNHAPPY_FACTOR);
-
-  my_snprintf(bptr, nleft, _("Units: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (mlmax > 0) {
-    my_snprintf(bptr, nleft, _("Martial law in effect ("));
-    bptr = end_of_strn(bptr, &nleft);
-
-    if (mlmax == 100)
-      my_snprintf(bptr, nleft, _("no maximum, "));
-    else
-      my_snprintf(bptr, nleft, PL_("%d unit maximum, ",
-                                  "%d units maximum, ", mlmax), mlmax);
-    bptr = end_of_strn(bptr, &nleft);
-
-    my_snprintf(bptr, nleft, _("%d per unit). "), 
-                get_city_bonus(pcity, EFT_MARTIAL_LAW_EACH));
-  } 
-  else if (uhcfac > 0) {
-    my_snprintf(bptr, nleft,
-               _("Military units in the field may cause unhappiness. "));
-  }
-  else {
-    my_snprintf(bptr, nleft,
-               _("Military units have no happiness effect. "));
-
-  }
-
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[UNITS]), buf);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_wonders(struct happiness_dialog
-                                           *pdialog)
-{
-  gtk_label_set_text(GTK_LABEL(pdialog->hlabels[WONDERS]),
-                    get_happiness_wonders(pdialog->pcity));
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 GtkWidget *get_top_happiness_display(struct city *pcity)
 {
   return create_happiness_dialog(pcity)->shell;
Index: client/text.c
===================================================================
--- client/text.c       (revision 14244)
+++ client/text.c       (working copy)
@@ -1137,9 +1137,9 @@
 }
 
 /****************************************************************************
-  Get the text describing buildings that affect happiness.
+  Describing buildings that affect happiness.
 ****************************************************************************/
-const char *get_happiness_buildings(const struct city *pcity)
+const char *text_happiness_buildings(const struct city *pcity)
 {
   char buf[512];
   int faces = 0;
@@ -1174,9 +1174,9 @@
 }
 
 /****************************************************************************
-  Get the text describing wonders that affect happiness.
+  Describing wonders that affect happiness.
 ****************************************************************************/
-const char *get_happiness_wonders(const struct city *pcity)
+const char *text_happiness_wonders(const struct city *pcity)
 {
   char buf[512];
   int faces = 0;
@@ -1211,3 +1211,105 @@
 
   return str.str;
 }
+
+/****************************************************************************
+  Describing city factors that affect happiness.
+****************************************************************************/
+const char *text_happiness_cities(const struct city *pcity)
+{
+  struct player *pplayer = city_owner(pcity);
+  int cities = city_list_size(pplayer->cities);
+  int content = game.info.unhappysize;
+  int basis = game.info.cityfactor
+            + get_player_bonus(pplayer, EFT_EMPIRE_SIZE_MOD);
+  int step = get_player_bonus(pplayer, EFT_EMPIRE_SIZE_STEP);
+  int excess = cities - basis;
+  int penalty = 0;
+  static struct astring str = ASTRING_INIT;
+
+  astr_clear(&str);
+
+  if (excess > 0) {
+    if (step > 0)
+      penalty = 1 + (excess - 1) / step;
+    else
+      penalty = 1;
+  } else {
+    excess = 0;
+    penalty = 0;
+  }
+
+  astr_add_line(&str,
+                _("Cities: %d total, %d over threshold of %d cities."),
+              cities, excess, basis);
+  astr_add_line(&str,
+                /* TRANS: 0-21 content [citizen(s)] ... */
+                PL_("%d content before penalty.",
+                    "%d content before penalty.",
+                    content),
+                content);
+  astr_add_line(&str,
+                /* TRANS: 0-21 unhappy citizen(s). */
+                PL_("%d additional unhappy citizen.",
+                    "%d additional unhappy citizens.",
+                    penalty),
+                penalty);
+  return str.str;
+}
+
+/****************************************************************************
+  Describing units that affect happiness.
+  FIXME: sentence fragments with parenthesis are hard to translate!
+****************************************************************************/
+const char *text_happiness_units(const struct city *pcity)
+{
+  int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
+  int uhcfac = get_city_bonus(pcity, EFT_UNHAPPY_FACTOR);
+  static struct astring str = ASTRING_INIT;
+
+  astr_clear(&str);
+
+  if (mlmax > 0) {
+    astr_add_line(&str,
+                  /* TRANS: Martial law opening parenthesis */
+                  _("Martial law in effect ("));
+
+    if (mlmax == 100) {
+      astr_add(&str,
+               /* TRANS: no [unit] maximum */
+               _("no maximum, "));
+    } else {
+      astr_add(&str,
+               PL_("%d unit maximum, ",
+                   "%d units maximum, ",
+                   mlmax),
+               mlmax);
+    }
+    astr_add(&str,
+             /* TRANS: Martial law closing parenthesis */
+             _("%d per unit). "),
+             get_city_bonus(pcity, EFT_MARTIAL_LAW_EACH));
+  } else if (uhcfac > 0) {
+    astr_add_line(&str,
+                  _("Military units in the field may cause unhappiness. "));
+  } else {
+    astr_add_line(&str,
+                  _("Military units have no happiness effect. "));
+  }
+  return str.str;
+}
+
+/****************************************************************************
+  Describing luxuries that affect happiness.
+****************************************************************************/
+const char *text_happiness_luxuries(const struct city *pcity)
+{
+  static struct astring str = ASTRING_INIT;
+
+  astr_clear(&str);
+
+  astr_add_line(&str,
+                _("Luxury: %d total."),
+                pcity->prod[O_LUXURY]);
+  return str.str;
+}
Index: client/text.h
===================================================================
--- client/text.h       (revision 14244)
+++ client/text.h       (working copy)
@@ -45,7 +45,11 @@
 const char *get_ping_time_text(const struct player *pplayer);
 const char *get_score_text(const struct player *pplayer);
 const char *get_report_title(const char *report_name);
-const char *get_happiness_buildings(const struct city *pcity);
-const char *get_happiness_wonders(const struct city *pcity);
 
+const char *text_happiness_buildings(const struct city *pcity);
+const char *text_happiness_cities(const struct city *pcity);
+const char *text_happiness_luxuries(const struct city *pcity);
+const char *text_happiness_units(const struct city *pcity);
+const char *text_happiness_wonders(const struct city *pcity);
+
 #endif /* FC__TEXT_H */
Index: client/gui-win32/happiness.c
===================================================================
--- client/gui-win32/happiness.c        (revision 14244)
+++ client/gui-win32/happiness.c        (working copy)
@@ -46,16 +46,6 @@
   POINT mod_bmp_pos[NUM_HAPPINESS_MODIFIERS];
 };
 
-static void happiness_dialog_update_cities(struct happiness_dlg
-                                           *pdialog);
-static void happiness_dialog_update_luxury(struct happiness_dlg
-                                           *pdialog);
-static void happiness_dialog_update_buildings(struct happiness_dlg
-                                              *pdialog);
-static void happiness_dialog_update_units(struct happiness_dlg
-                                          *pdialog);
-static void happiness_dialog_update_wonders(struct happiness_dlg
-                                            *pdialog);
 static void refresh_happiness_bitmap(HBITMAP bmp,
                                     struct city *pcity,
                                     enum citizen_feeling index);
@@ -145,148 +135,9 @@
   DeleteDC(hdcsrc);
 }
 
-/****************************************************************
-...
-*****************************************************************/
-void refresh_happiness_box(struct happiness_dlg *dlg)
-{
-  HDC hdc;
-  int i;
-  for(i=0;i<NUM_HAPPINESS_MODIFIERS;i++) {
-    refresh_happiness_bitmap(dlg->mod_bmp[i],dlg->pcity,i);
-  }
-  hdc=GetDC(dlg->win);
-  repaint_happiness_box(dlg,hdc);
-  ReleaseDC(dlg->win,hdc);
-  happiness_dialog_update_cities(dlg);
-  happiness_dialog_update_luxury(dlg);
-  happiness_dialog_update_buildings(dlg);
-  happiness_dialog_update_units(dlg);
-  happiness_dialog_update_wonders(dlg);
-}
-
 /**************************************************************************
 ...
 **************************************************************************/
-static void happiness_dialog_update_cities(struct happiness_dlg
-                                           *pdialog)
-{
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-
-  struct city *pcity = pdialog->pcity;
-  struct player *pplayer = city_owner(pcity);
-  int cities = city_list_size(pplayer->cities);
-  int content = game.info.unhappysize;
-  int basis = game.info.cityfactor 
-             + get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_MOD);
-  int step = get_player_bonus(game.player_ptr, EFT_EMPIRE_SIZE_STEP);
-  int excess = cities - basis;
-  int penalty = 0;
-
-  if (excess > 0) {
-    if (step > 0)
-      penalty = 1 + (excess - 1) / step;
-    else
-      penalty = 1;
-  } else {
-    excess = 0;
-    penalty = 0;
-  }
-
-  my_snprintf(bptr, nleft,
-              _("Cities: %d total, %d over threshold of %d cities.\n"),
-              cities, excess, basis);
-  bptr = end_of_strn(bptr, &nleft);
-
-  my_snprintf(bptr, nleft, _("%d content before penalty with "), content);
-  bptr = end_of_strn(bptr, &nleft);
-  my_snprintf(bptr, nleft, _("%d additional unhappy citizens."), penalty);
-  bptr = end_of_strn(bptr, &nleft);
-
-  SetWindowText(pdialog->mod_label[CITIES], buf);
-}
-
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_luxury(struct happiness_dlg
-                                           *pdialog)
-{
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-
-  my_snprintf(bptr, nleft, _("Luxury: %d total."),
-              pcity->prod[O_LUXURY]);
-
-  SetWindowText(pdialog->mod_label[LUXURIES], buf);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_buildings(struct happiness_dlg
-                                              *pdialog)
-{
-  SetWindowText(pdialog->mod_label[BUILDINGS],
-               get_happiness_buildings(pdialog->pcity));
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_units(struct happiness_dlg *pdialog)
-{
-  char buf[512], *bptr = buf;
-  int nleft = sizeof(buf);
-  struct city *pcity = pdialog->pcity;
-  int mlmax = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
-  int uhcfac = get_player_bonus(city_owner(pcity), EFT_UNHAPPY_FACTOR);
-
-  my_snprintf(bptr, nleft, _("Units: "));
-  bptr = end_of_strn(bptr, &nleft);
-
-  if (mlmax > 0) {
-    my_snprintf(bptr, nleft, _("Martial law in effect ("));
-    bptr = end_of_strn(bptr, &nleft);
-
-    if (mlmax == 100)
-      my_snprintf(bptr, nleft, _("no maximum, "));
-    else
-      my_snprintf(bptr, nleft, PL_("%d unit maximum, ",
-                                   "%d units maximum", mlmax), mlmax);
-    bptr = end_of_strn(bptr, &nleft);
-
-    my_snprintf(bptr, nleft, _("%d per unit). "),
-               get_city_bonus(pcity, EFT_MARTIAL_LAW_EACH));
-  }
-  else if (uhcfac > 0) {
-    my_snprintf(bptr, nleft,
-                _("Military units in the field may cause unhappiness. "));
-  }
-  else {
-    my_snprintf(bptr, nleft,
-                _("Military units have no happiness effect. "));
-  }
-
-  SetWindowText(pdialog->mod_label[UNITS], buf);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void happiness_dialog_update_wonders(struct happiness_dlg
-                                            *pdialog)
-{
-  SetWindowText(pdialog->mod_label[WONDERS],
-               get_happiness_wonders(pdialog->pcity));
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 static void refresh_happiness_bitmap(HBITMAP bmp,
                                     struct city *pcity,
                                     enum citizen_feeling index)
@@ -315,3 +166,29 @@
   SelectObject(hdc,old);
   DeleteDC(hdc);
 }
+
+/****************************************************************
+...
+*****************************************************************/
+void refresh_happiness_box(struct happiness_dlg *dlg)
+{
+  HDC hdc;
+  int i;
+  for(i=0;i<NUM_HAPPINESS_MODIFIERS;i++) {
+    refresh_happiness_bitmap(dlg->mod_bmp[i],dlg->pcity,i);
+  }
+  hdc=GetDC(dlg->win);
+  repaint_happiness_box(dlg,hdc);
+  ReleaseDC(dlg->win,hdc);
+
+  SetWindowText(pdialog->mod_label[CITIES],
+               text_happiness_cities(dlg->pcity));
+  SetWindowText(dlg->mod_label[LUXURIES],
+               text_happiness_luxuries(dlg->pcity));
+  SetWindowText(dlg->mod_label[BUILDINGS],
+               text_happiness_buildings(dlg->pcity));
+  SetWindowText(pdialog->mod_label[UNITS],
+               text_happiness_units(dlg->pcity));
+  SetWindowText(dlg->mod_label[WONDERS],
+               text_happiness_wonders(dlg->pcity));
+}
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to