Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#10930) i18n in ukrainian: "Translated name is too long
Home

[Freeciv-Dev] (PR#10930) i18n in ukrainian: "Translated name is too long

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ktocomp@xxxxxxxx
Subject: [Freeciv-Dev] (PR#10930) i18n in ukrainian: "Translated name is too long. Aborting."
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 8 Nov 2004 17:38:23 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10930 >

> [ktocomp@xxxxxxxx - Sun Nov 07 13:05:47 2004]:

> 2. Problem with i18n in ukrainian lang FreeCiv says: "Translated name is 
> too long. Aborting."

Here is a patch for this.

-----

Technical details:

This is actually quite easy to fix.  We already have a name and
name_orig field.  All we have to do is change the name field (the
translated value) to be a pointer instead of an array.  Less code, less
memory, very pretty.

The only failure in this system is there is no check on the length of
translations so a translator may easily put in an arbitrarily long
string which could give GUI problems or just look ugly.

This is of course incomplete because it only deals with nation->name and
nation->name_plural.  We also have to deal with all other stored
translated strings.  This includes unit names, improvement names,
legends, etc.  All post-translated strings should be pointers; we should
never do a copy of a translated string into a static array.  Unless
anyone objects to the design in this patch I'll do the same thing in
other places.

For city and leader names (which are untranslated utf-8), we have a much
bigger problem.  This method won't work there.

jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.408.2.6
diff -u -r1.408.2.6 packhand.c
--- client/packhand.c   4 Nov 2004 20:57:49 -0000       1.408.2.6
+++ client/packhand.c   9 Nov 2004 01:30:06 -0000
@@ -2547,8 +2547,8 @@
   }
   pl = get_nation_by_idx(p->id);
 
-  sz_strlcpy(pl->name, p->name);
-  sz_strlcpy(pl->name_plural, p->name_plural);
+  sz_strlcpy(pl->name_orig, p->name);
+  sz_strlcpy(pl->name_plural_orig, p->name_plural);
   sz_strlcpy(pl->flag_graphic_str, p->graphic_str);
   sz_strlcpy(pl->flag_graphic_alt, p->graphic_alt);
   pl->leader_count = p->leader_count;
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.187
diff -u -r1.187 game.c
--- common/game.c       29 Sep 2004 02:24:22 -0000      1.187
+++ common/game.c       9 Nov 2004 01:30:06 -0000
@@ -594,10 +594,9 @@
   } government_iterate_end;
   for (i=0; i<game.nation_count; i++) {
     struct nation_type *tthis = get_nation_by_idx(i);
-    sz_strlcpy(tthis->name_orig, tthis->name);
-    name_strlcpy(tthis->name, Q_(tthis->name_orig));
-    sz_strlcpy(tthis->name_plural_orig, tthis->name_plural);
-    name_strlcpy(tthis->name_plural, Q_(tthis->name_plural_orig));
+
+    tthis->name = Q_(tthis->name_orig);
+    tthis->name_plural = Q_(tthis->name_plural_orig);
   }
   for (i=0; i<game.styles_count; i++) {
     struct citystyle *tthis = &city_styles[i];
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.31
diff -u -r1.31 nation.h
--- common/nation.h     6 Sep 2004 02:58:11 -0000       1.31
+++ common/nation.h     9 Nov 2004 01:30:06 -0000
@@ -66,10 +66,10 @@
 };
 
 struct nation_type {
-  /* Pointer values are allocated in load_ruleset_nations() then freed in
-   * free_nations(). */
-  char name[MAX_LEN_NAME];
-  char name_plural[MAX_LEN_NAME];
+  /* These are pointers to static strings - no need to free them. */
+  const char *name, *name_plural;
+
+  /* Pointer values are allocated on load then freed in free_nations(). */
   char flag_graphic_str[MAX_LEN_NAME];
   char flag_graphic_alt[MAX_LEN_NAME];
   int  leader_count;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.196.2.1
diff -u -r1.196.2.1 ruleset.c
--- server/ruleset.c    23 Oct 2004 18:54:41 -0000      1.196.2.1
+++ server/ruleset.c    9 Nov 2004 01:30:07 -0000
@@ -2072,8 +2072,14 @@
     char *name_plural = secfile_lookup_str(file, "%s.plural", sec[i]);
     struct nation_type *pl = get_nation_by_idx(i);
 
-    name_strlcpy(pl->name, name);
-    name_strlcpy(pl->name_plural, name_plural);
+    name_strlcpy(pl->name_orig, name);
+    name_strlcpy(pl->name_plural_orig, name_plural);
+
+    /* These are overwritten later when translations are done.  However
+     * in the meantime some code (like the check below) accesses the name
+     * directly.  This isn't great but it would take some work to fix. */
+    pl->name = pl->name_orig;
+    pl->name_plural = pl->name_plural_orig;
 
     /* Check if nation name is already defined. */
     for(j = 0; j < i; j++) {

[Prev in Thread] Current Thread [Next in Thread]