[Freeciv-Dev] i18n of names in data
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I was thinking about the issue of i18n of "data" names (names
of unit types, tech etc), and in particular which of following
to do:
1. Translate names when first acquired, and store translated
names in advances[].name etc, so that all such appearances in
the code automatically use the translated version.
2. Keep original untranslated names in advances[].name etc,
and add gettext calls to translate on the fly where needed.
Number 2 seems rather tedious, but the problem with number 1
is that sometimes it may be advantageous to have the untranslated
names available; eg for cross-referencing when loading rulesets,
or for the server sending data to client (so client can potentially
translate to some other language, at least for "client-only" usage).
Also, if server and client take different approaches from 1 and 2
above, then have problem with code in /common.
I then realized the best is probably to do both: keep translated
names in advances[].name etc, but also keep a copy of the original
to use if necessary/useful. (Re loading rulesets, actually only
translate after loading all the rulesets).
The following patch does this; note I have already checked this
into CVS, since I think it is ok, and since it help i18n alot.
I'm posting this here just for information on what I've done,
and comments if any.
-- David
diff -u -r --exclude-from exclude fc-adv/client/civclient.c
freeciv-mod/client/civclient.c
--- fc-adv/client/civclient.c Sun Sep 26 12:34:35 1999
+++ freeciv-mod/client/civclient.c Sun Sep 26 12:25:45 1999
@@ -360,6 +360,19 @@
void set_client_state(enum client_states newstate)
{
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.)
+ */
+ if (client_state==CLIENT_PRE_GAME_STATE
+ && (newstate==CLIENT_SELECT_RACE_STATE
+ || newstate==CLIENT_GAME_RUNNING_STATE)) {
+ translate_data_names();
+ }
+
client_state=newstate;
if(client_state==CLIENT_GAME_RUNNING_STATE) {
diff -u -r --exclude-from exclude fc-adv/common/city.h freeciv-mod/common/city.h
--- fc-adv/common/city.h Sun Sep 26 12:34:35 1999
+++ freeciv-mod/common/city.h Sun Sep 26 11:50:16 1999
@@ -39,6 +39,7 @@
struct improvement_type {
char name[MAX_LEN_NAME];
+ char name_orig[MAX_LEN_NAME]; /* untranslated */
int is_wonder;
int tech_requirement;
int build_cost;
diff -u -r --exclude-from exclude fc-adv/common/game.c freeciv-mod/common/game.c
--- fc-adv/common/game.c Sun Sep 26 12:34:35 1999
+++ freeciv-mod/common/game.c Sun Sep 26 11:50:16 1999
@@ -10,18 +10,26 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "city.h"
+#include "fcintl.h"
#include "government.h"
#include "log.h"
#include "map.h"
#include "mem.h"
+#include "nation.h"
#include "player.h"
#include "shared.h"
#include "spaceship.h"
+#include "tech.h"
+#include "unit.h"
#include "game.h"
@@ -894,3 +902,58 @@
}
+/***************************************************************
+ 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.)
+***************************************************************/
+void translate_data_names(void)
+{
+ int i, j;
+
+ for (i=0; i<game.num_tech_types; i++) {
+ struct advance *this = &advances[i];
+ strcpy(this->name_orig, this->name);
+ strcpy(this->name, _(this->name_orig));
+ }
+ for (i=0; i<game.num_unit_types; i++) {
+ struct unit_type *this = &unit_types[i];
+ strcpy(this->name_orig, this->name);
+ strcpy(this->name, _(this->name_orig));
+ }
+ for (i=0; i<B_LAST; i++) {
+ struct improvement_type *this = &improvement_types[i];
+ strcpy(this->name_orig, this->name);
+ strcpy(this->name, _(this->name_orig));
+ }
+ for (i=T_FIRST; i<T_COUNT; i++) {
+ struct tile_type *this = &tile_types[i];
+ strcpy(this->terrain_name_orig, this->terrain_name);
+ strcpy(this->terrain_name, _(this->terrain_name_orig));
+ strcpy(this->special_1_name_orig, this->special_1_name);
+ strcpy(this->special_1_name, _(this->special_1_name_orig));
+ strcpy(this->special_2_name_orig, this->special_2_name);
+ strcpy(this->special_2_name, _(this->special_2_name_orig));
+ }
+ for (i=0; i<game.government_count; i++) {
+ struct government *this = &governments[i];
+ strcpy(this->name_orig, this->name);
+ strcpy(this->name, _(this->name_orig));
+ for(j=0; j<this->num_ruler_titles; j++) {
+ struct ruler_title *that = &this->ruler_titles[j];
+ strcpy(that->male_title_orig, that->male_title);
+ strcpy(that->male_title, _(that->male_title_orig));
+ strcpy(that->female_title_orig, that->female_title);
+ strcpy(that->female_title, _(that->female_title_orig));
+ }
+ }
+ for (i=0; i<game.nation_count; i++) {
+ struct nation_type *this = get_nation_by_idx(i);
+ strcpy(this->name_orig, this->name);
+ strcpy(this->name, _(this->name_orig));
+ strcpy(this->name_plural_orig, this->name_plural);
+ strcpy(this->name_plural, _(this->name_plural_orig));
+ }
+}
diff -u -r --exclude-from exclude fc-adv/common/game.h freeciv-mod/common/game.h
--- fc-adv/common/game.h Sun Sep 26 12:34:35 1999
+++ freeciv-mod/common/game.h Sun Sep 26 11:50:16 1999
@@ -141,6 +141,8 @@
int civ_score(struct player *pplayer);
void initialize_globals(void);
+void translate_data_names(void);
+
struct player *get_player(int player_id);
extern struct civ_game game;
diff -u -r --exclude-from exclude fc-adv/common/government.h
freeciv-mod/common/government.h
--- fc-adv/common/government.h Sun Sep 26 12:34:36 1999
+++ freeciv-mod/common/government.h Sun Sep 26 11:50:17 1999
@@ -48,6 +48,10 @@
int nation;
char male_title[MAX_LEN_NAME];
char female_title[MAX_LEN_NAME];
+
+ /* untranslated copies: */
+ char male_title_orig[MAX_LEN_NAME];
+ char female_title_orig[MAX_LEN_NAME];
};
/* This is struct government itself. All information about
@@ -57,6 +61,7 @@
{
int index; /* index into governments[] array */
char name[MAX_LEN_NAME]; /* government name */
+ char name_orig[MAX_LEN_NAME]; /* untranslated copy */
char graphic_str[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
int required_tech; /* tech required to change to this gov */
diff -u -r --exclude-from exclude fc-adv/common/map.h freeciv-mod/common/map.h
--- fc-adv/common/map.h Sun Sep 26 12:34:36 1999
+++ freeciv-mod/common/map.h Sun Sep 26 11:50:17 1999
@@ -97,6 +97,7 @@
struct tile_type {
char terrain_name[MAX_LEN_NAME]; /* "" if unused */
+ char terrain_name_orig[MAX_LEN_NAME]; /* untranslated copy */
char graphic_str[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
struct Sprite *sprite[NUM_DIRECTION_NSEW];
@@ -109,11 +110,13 @@
int trade;
char special_1_name[MAX_LEN_NAME]; /* "" if none */
+ char special_1_name_orig[MAX_LEN_NAME]; /* untranslated copy */
int food_special_1;
int shield_special_1;
int trade_special_1;
char special_2_name[MAX_LEN_NAME]; /* "" if none */
+ char special_2_name_orig[MAX_LEN_NAME]; /* untranslated copy */
int food_special_2;
int shield_special_2;
int trade_special_2;
diff -u -r --exclude-from exclude fc-adv/common/nation.h
freeciv-mod/common/nation.h
--- fc-adv/common/nation.h Sun Sep 26 12:34:36 1999
+++ freeciv-mod/common/nation.h Sun Sep 26 11:50:17 1999
@@ -37,6 +37,10 @@
char **default_city_names;
struct Sprite *flag_sprite;
+ /* untranslated copies: */
+ char name_orig[MAX_LEN_NAME];
+ char name_plural_orig[MAX_LEN_NAME];
+
/* AI hints */
int attack; /* c 0 = optimize for food, 2 = optimize for prod
*/
/* c0 = large amount of buildings, 2 = units */
diff -u -r --exclude-from exclude fc-adv/common/tech.h freeciv-mod/common/tech.h
--- fc-adv/common/tech.h Sun Sep 26 12:34:36 1999
+++ freeciv-mod/common/tech.h Sun Sep 26 11:50:17 1999
@@ -60,6 +60,7 @@
struct advance {
char name[MAX_LEN_NAME];
+ char name_orig[MAX_LEN_NAME]; /* untranslated */
int req[2];
unsigned int flags;
char *helptext;
diff -u -r --exclude-from exclude fc-adv/common/unit.h freeciv-mod/common/unit.h
--- fc-adv/common/unit.h Sun Sep 26 12:34:36 1999
+++ freeciv-mod/common/unit.h Sun Sep 26 11:50:17 1999
@@ -169,6 +169,7 @@
struct unit_type {
char name[MAX_LEN_NAME];
+ char name_orig[MAX_LEN_NAME]; /* untranslated */
char graphic_str[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
struct Sprite *sprite;
diff -u -r --exclude-from exclude fc-adv/server/ruleset.c
freeciv-mod/server/ruleset.c
--- fc-adv/server/ruleset.c Sun Sep 26 12:34:36 1999
+++ freeciv-mod/server/ruleset.c Sun Sep 26 11:50:17 1999
@@ -1458,7 +1458,7 @@
for(u=unit_types; u<unit_types+game.num_unit_types; u++) {
packet.id = u-unit_types;
- strcpy(packet.name, u->name);
+ strcpy(packet.name, u->name_orig);
strcpy(packet.graphic_str, u->graphic_str);
strcpy(packet.graphic_alt, u->graphic_alt);
packet.move_type = u->move_type;
@@ -1503,7 +1503,7 @@
for(a=advances; a<advances+game.num_tech_types; a++) {
packet.id = a-advances;
- strcpy(packet.name, a->name);
+ strcpy(packet.name, a->name_orig);
packet.req[0] = a->req[0];
packet.req[1] = a->req[1];
packet.flags = a->flags;
@@ -1528,7 +1528,7 @@
for(b=improvement_types; b<improvement_types+B_LAST; b++) {
packet.id = b-improvement_types;
- strcpy(packet.name, b->name);
+ strcpy(packet.name, b->name_orig);
packet.is_wonder = b->is_wonder;
packet.tech_requirement = b->tech_requirement;
packet.build_cost = b->build_cost;
@@ -1568,7 +1568,7 @@
packet.id = i;
- strcpy (packet.terrain_name, t->terrain_name);
+ strcpy (packet.terrain_name, t->terrain_name_orig);
strcpy(packet.graphic_str, t->graphic_str);
strcpy(packet.graphic_alt, t->graphic_alt);
@@ -1579,12 +1579,12 @@
packet.shield = t->shield;
packet.trade = t->trade;
- strcpy (packet.special_1_name, t->special_1_name);
+ strcpy (packet.special_1_name, t->special_1_name_orig);
packet.food_special_1 = t->food_special_1;
packet.shield_special_1 = t->shield_special_1;
packet.trade_special_1 = t->trade_special_1;
- strcpy (packet.special_2_name, t->special_2_name);
+ strcpy (packet.special_2_name, t->special_2_name_orig);
packet.food_special_2 = t->food_special_2;
packet.shield_special_2 = t->shield_special_2;
packet.trade_special_2 = t->trade_special_2;
@@ -1681,7 +1681,7 @@
gov.hints = g->hints;
gov.num_ruler_titles = g->num_ruler_titles;
- strcpy(gov.name, g->name);
+ strcpy(gov.name, g->name_orig);
strcpy(gov.graphic_str, g->graphic_str);
strcpy(gov.graphic_alt, g->graphic_alt);
@@ -1724,8 +1724,8 @@
for( k=0; k<game.nation_count; k++) {
n = get_nation_by_idx(k);
packet.id = k;
- strcpy(packet.name, n->name);
- strcpy(packet.name_plural, n->name_plural);
+ strcpy(packet.name, n->name_orig);
+ strcpy(packet.name_plural, n->name_plural_orig);
strcpy(packet.graphic_str, n->flag_graphic_str);
strcpy(packet.graphic_alt, n->flag_graphic_alt);
packet.leader_count = n->leader_count;
@@ -1754,6 +1754,7 @@
load_ruleset_buildings(game.ruleset.buildings);
load_ruleset_nations(game.ruleset.nations);
load_ruleset_terrain(game.ruleset.terrain);
+ translate_data_names();
}
/**************************************************************************
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] i18n of names in data,
David Pfitzner <=
|
|