Merge branch 'develop'

This commit is contained in:
Enno Rehling 2018-05-17 22:49:03 +02:00
commit 0d6abd3811
18 changed files with 55 additions and 5783 deletions

View File

@ -1688,12 +1688,6 @@
<string name="mallornseed_p"> <string name="mallornseed_p">
<text locale="de">Mallornsamen</text> <text locale="de">Mallornsamen</text>
</string> </string>
<string name="birthday_firework">
<text locale="de">Feuerwerk</text>
</string>
<string name="birthday_firework_p">
<text locale="de">Feuerwerke</text>
</string>
<string name="lebkuchenherz"> <string name="lebkuchenherz">
<text locale="de">Lebkuchenherz mit der Aufschrift 'Erz und <text locale="de">Lebkuchenherz mit der Aufschrift 'Erz und
Stein, das ist fein'</text> Stein, das ist fein'</text>

View File

@ -874,12 +874,6 @@
<string name="mallornseed_p"> <string name="mallornseed_p">
<text locale="en">mallorn seeds</text> <text locale="en">mallorn seeds</text>
</string> </string>
<string name="birthday_firework">
<text locale="en">firework</text>
</string>
<string name="birthday_firework_p">
<text locale="en">fireworks</text>
</string>
<string name="lebkuchenherz"> <string name="lebkuchenherz">
<text locale="en">gingerbread heart</text> <text locale="en">gingerbread heart</text>
</string> </string>

View File

@ -881,12 +881,6 @@
<string name="mallornseed_p"> <string name="mallornseed_p">
<text locale="fr">graines de mallorn</text> <text locale="fr">graines de mallorn</text>
</string> </string>
<string name="birthday_firework">
<text locale="fr">feu d'artifice</text>
</string>
<string name="birthday_firework_p">
<text locale="fr">feux d'artifice</text>
</string>
<string name="lebkuchenherz"> <string name="lebkuchenherz">
<text locale="fr">coeur de pain d'épices</text> <text locale="fr">coeur de pain d'épices</text>
</string> </string>

View File

@ -750,38 +750,6 @@
<text locale="de">"$unit($unit) hat Glück und findet einen Hort von $int($amount) $resource($item,$amount)."</text> <text locale="de">"$unit($unit) hat Glück und findet einen Hort von $int($amount) $resource($item,$amount)."</text>
<text locale="en">"$unit($unit) luckily finds a cache of $int($amount) $resource($item,$amount)."</text> <text locale="en">"$unit($unit) luckily finds a cache of $int($amount) $resource($item,$amount)."</text>
</message> </message>
<message name="birthday_firework_noname_local" section="events">
<type>
<arg name="unit" type="unit"/>
</type>
<text locale="de">"$unit($unit) brennt ein großes Feuerwerk ab und Kaskaden bunter Sterne, leuchtende Wasserfälle aus Licht und strahlende Feuerdrachen erhellen den Himmel."</text>
<text locale="en">"A large firework is visible all over the sky."</text>
</message>
<message name="birthday_firework_noname" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
</type>
<text locale="de">"In $region($region) wird ein großes Feuerwerk abgebrannt, welches noch hier zu bewundern ist. Kaskaden bunter Sterne, leuchtende Wasserfälle aus Licht und strahlende Feuerdrachen erhellen den Himmel."</text>
<text locale="en">"A large firework, visible all over the sky, has been started in $region($region)."</text>
</message>
<message name="birthday_firework_local" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="name" type="string"/>
</type>
<text locale="de">"Zur Feier des Geburtstags von ${name} brennt $unit($unit) ein großes Feuerwerk ab. Kaskaden bunter Sterne, leuchtende Wasserfälle aus Licht und strahlende Feuerdrachen erhellen den Himmel."</text>
<text locale="en">"A large firework in honor of ${name} is visible all over the sky."</text>
</message>
<message name="birthday_firework" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="name" type="string"/>
</type>
<text locale="de">"Zur Feier des Geburtstags von ${name} wird in $region($region) ein großes Feuerwerk abgebrannt, welches noch hier zu bewundern ist. Kaskaden bunter Sterne, leuchtende Wasserfälle aus Licht und strahlende Feuerdrachen erhellen den Himmel."</text>
<text locale="en">"A large firework in honor of ${name}, visible all over the sky, has been started in $region($region)."</text>
</message>
<message name="battle_critical" section="battle"> <message name="battle_critical" section="battle">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>
@ -1682,7 +1650,7 @@
<text locale="de">"$string"</text> <text locale="de">"$string"</text>
<text locale="en">"$string"</text> <text locale="en">"$string"</text>
</message> </message>
<message name="battle_army" section="battle"> <message name="para_army_index" section="battle">
<type> <type>
<arg name="index" type="int"/> <arg name="index" type="int"/>
<arg name="name" type="string"/> <arg name="name" type="string"/>
@ -7211,20 +7179,13 @@
<text locale="en">"$unit($mage) casts $spell($spell), but nobody was in range."</text> <text locale="en">"$unit($mage) casts $spell($spell), but nobody was in range."</text>
</message> </message>
<message name="after_battle" section="battle"> <message name="para_after_battle" section="battle">
<type> <type>
</type> </type>
<text locale="de">"Einheiten nach dem Kampf:"</text> <text locale="de">"Einheiten nach dem Kampf:"</text>
<text locale="en">"Units after the battle:"</text> <text locale="en">"Units after the battle:"</text>
</message> </message>
<message name="section_battle" section="battle">
<type>
</type>
<text locale="de">""</text>
<text locale="en">""</text>
</message>
<message name="sp_wolfhowl_effect" section="battle"> <message name="sp_wolfhowl_effect" section="battle">
<type> <type>
<arg name="mage" type="unit"/> <arg name="mage" type="unit"/>
@ -7284,7 +7245,7 @@
<text locale="en">"$unit($mage) causes the walls of $building($building) to glow in an eerie magic light."</text> <text locale="en">"$unit($mage) causes the walls of $building($building) to glow in an eerie magic light."</text>
</message> </message>
<message name="lineup_battle" section="battle"> <message name="para_lineup_battle" section="battle">
<type> <type>
<arg name="turn" type="int"/> <arg name="turn" type="int"/>
</type> </type>
@ -7628,7 +7589,7 @@
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The $ship($ship) will now be faster."</text> <text locale="en">"$unit($unit) in $region($region): '$order($command)' - The $ship($ship) will now be faster."</text>
</message> </message>
<message name="aurapotion50" section="magic"> <message name="aurapotion50_effect" section="magic">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>
<arg name="region" type="region"/> <arg name="region" type="region"/>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,7 @@ function test_aurapotion50()
turn_begin() turn_begin()
turn_process() turn_process()
assert_equal(0, u:get_item("aurapotion50")) assert_equal(0, u:get_item("aurapotion50"))
assert_equal(1, f:count_msg_type('aurapotion50')) assert_equal(1, f:count_msg_type('aurapotion50_effect'))
assert_equal(50, u.aura) assert_equal(50, u.aura)
turn_end() turn_end()
end end

View File

@ -110,8 +110,6 @@ typedef enum combatmagic {
static int missile_range[2] = { FIGHT_ROW, BEHIND_ROW }; static int missile_range[2] = { FIGHT_ROW, BEHIND_ROW };
static int melee_range[2] = { FIGHT_ROW, FIGHT_ROW }; static int melee_range[2] = { FIGHT_ROW, FIGHT_ROW };
static message *msg_separator;
const troop no_troop = { 0, 0 }; const troop no_troop = { 0, 0 };
#define FORMULA_ORIG 0 #define FORMULA_ORIG 0
@ -2888,9 +2886,7 @@ static void print_stats(battle * b)
message *msg; message *msg;
char buf[1024]; char buf[1024];
battle_message_faction(b, f, msg_separator); msg = msg_message("para_army_index", "index name", army_index(s), sname);
msg = msg_message("battle_army", "index name", army_index(s), sname);
battle_message_faction(b, f, msg); battle_message_faction(b, f, msg);
msg_release(msg); msg_release(msg);
@ -2959,8 +2955,6 @@ static void print_stats(battle * b)
print_fighters(b, s); print_fighters(b, s);
} }
message_all(b, msg_separator);
/* Besten Taktiker ermitteln */ /* Besten Taktiker ermitteln */
b->max_tactics = 0; b->max_tactics = 0;
@ -3501,12 +3495,11 @@ static int battle_report(battle * b)
bool komma = false; bool komma = false;
sbs_init(&sbs, buf, sizeof(buf)); sbs_init(&sbs, buf, sizeof(buf));
battle_message_faction(b, fac, msg_separator);
if (cont) if (cont)
m = msg_message("lineup_battle", "turn", b->turn); m = msg_message("para_lineup_battle", "turn", b->turn);
else else
m = msg_message("after_battle", ""); m = msg_message("para_after_battle", "");
battle_message_faction(b, fac, m); battle_message_faction(b, fac, m);
msg_release(m); msg_release(m);
@ -4008,9 +4001,6 @@ void do_battle(region * r)
battle *b = NULL; battle *b = NULL;
bool fighting = false; bool fighting = false;
ship *sh; ship *sh;
if (msg_separator == NULL) {
msg_separator = msg_message("section_battle", "");
}
fighting = start_battle(r, &b); fighting = start_battle(r, &b);

View File

@ -918,12 +918,6 @@ static void export_locale(const struct locale *lang, const char *name) {
char fname[64]; char fname[64];
FILE * F; FILE * F;
sprintf(fname, "strings.%2s.po", name);
F = fopen(fname, "wt");
if (F) {
export_strings(lang, F);
fclose(F);
}
sprintf(fname, "messages.%2s.po", name); sprintf(fname, "messages.%2s.po", name);
F = fopen(fname, "wt"); F = fopen(fname, "wt");
if (F) { if (F) {

View File

@ -512,14 +512,14 @@ static void report_crtypes(FILE * F, const struct locale *lang)
for (i = 0; i != MTMAXHASH; ++i) { for (i = 0; i != MTMAXHASH; ++i) {
struct known_mtype *kmt; struct known_mtype *kmt;
for (kmt = mtypehash[i]; kmt; kmt = kmt->nexthash) { for (kmt = mtypehash[i]; kmt; kmt = kmt->nexthash) {
const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype); const struct nrmessage_type *nrt = nrt_find(kmt->mtype);
if (nrt) { if (nrt) {
char buffer[DISPLAYSIZE]; char buffer[DISPLAYSIZE];
int hash = (int)kmt->mtype->key; int hash = (int)kmt->mtype->key;
assert(hash > 0); assert(hash > 0);
fprintf(F, "MESSAGETYPE %d\n", hash); fprintf(F, "MESSAGETYPE %d\n", hash);
fputc('\"', F); fputc('\"', F);
fputs(str_escape(nrt_string(nrt), buffer, sizeof(buffer)), F); fputs(str_escape(nrt_string(nrt, lang), buffer, sizeof(buffer)), F);
fputs("\";text\n", F); fputs("\";text\n", F);
fprintf(F, "\"%s\";section\n", nrt_section(nrt)); fprintf(F, "\"%s\";section\n", nrt_section(nrt));
} }

View File

@ -224,7 +224,7 @@ int amount, struct order *ord)
change_spellpoints(u, 50); change_spellpoints(u, 50);
ADDMSG(&u->faction->msgs, msg_message("aurapotion50", ADDMSG(&u->faction->msgs, msg_message("aurapotion50_effect",
"unit region command", u, u->region, ord)); "unit region command", u, u->region, ord));
use_pooled(u, itype->rtype, GET_DEFAULT, 1); use_pooled(u, itype->rtype, GET_DEFAULT, 1);

View File

@ -743,6 +743,10 @@ rp_messages(struct stream *out, message_list * msgs, faction * viewer, int inden
k = 1; k = 1;
} }
nr_render(m->msg, viewer->locale, lbuf, sizeof(lbuf), viewer); nr_render(m->msg, viewer->locale, lbuf, sizeof(lbuf), viewer);
/* Hack: some messages should start a new paragraph with a newline: */
if (strncmp("para_", m->msg->type->name, 5) == 0) {
newline(out);
}
paragraph(out, lbuf, indent, 2, 0); paragraph(out, lbuf, indent, 2, 0);
} }
m = m->next; m = m->next;

View File

@ -258,29 +258,6 @@ void po_write_msg(FILE *F, const char *id, const char *str, const char *ctxt) {
fputs("\"\n\n", F); fputs("\"\n\n", F);
} }
void export_strings(const struct locale * lang, FILE *F) {
int i;
for (i = 0; i != SMAXHASH; ++i) {
const struct locale_str *find = lang->strings[i];
while (find) {
const char *dcolon = strstr(find->key, "::");
if (dcolon) {
size_t len = dcolon - find->key;
char ctxname[16];
assert(sizeof(ctxname) > len);
memcpy(ctxname, find->key, len);
ctxname[len] = '\0';
po_write_msg(F, dcolon + 2, find->str, ctxname);
}
else {
po_write_msg(F, find->key, find->str, NULL);
}
find = find->nexthash;
}
}
}
const char *locale_name(const locale * lang) const char *locale_name(const locale * lang)
{ {
return lang ? lang->name : "(null)"; return lang ? lang->name : "(null)";

View File

@ -58,7 +58,6 @@ extern "C" {
void make_locales(const char *str); void make_locales(const char *str);
void locale_foreach(void(*callback)(const struct locale *lang, const char *name)); void locale_foreach(void(*callback)(const struct locale *lang, const char *name));
void export_strings(const struct locale * lang, FILE *F);
void po_write_msg(FILE *F, const char *id, const char *str, const char *ctxt); void po_write_msg(FILE *F, const char *id, const char *str, const char *ctxt);
#define LOC(lang, s) (lang?locale_string(lang, s, true):s) #define LOC(lang, s) (lang?locale_string(lang, s, true):s)

View File

@ -30,38 +30,31 @@
#define NRT_MAXHASH 1021 #define NRT_MAXHASH 1021
static nrmessage_type *nrtypes[NRT_MAXHASH]; static nrmessage_type *nrtypes[NRT_MAXHASH];
const char *nrt_string(const struct nrmessage_type *type) const char *nrt_string(const struct nrmessage_type *nrt, const struct locale *lang)
{ {
if (type->string) { const char * str = locale_getstring(lang, nrt->mtype->name);
return type->string; if (!str) {
str = locale_getstring(default_locale, nrt->mtype->name);
} }
return locale_get(type->lang, type->mtype->name); assert(str);
return str;
} }
nrmessage_type *nrt_find(const struct locale * lang, nrmessage_type *nrt_find(const struct message_type * mtype)
const struct message_type * mtype)
{ {
nrmessage_type *found = NULL; nrmessage_type *found = NULL;
unsigned int hash = mtype->key % NRT_MAXHASH; unsigned int hash = mtype->key % NRT_MAXHASH;
nrmessage_type *type = nrtypes[hash]; nrmessage_type *type = nrtypes[hash];
while (type) { while (type) {
if (type->mtype == mtype) { if (type->mtype == mtype) {
if (found == NULL) if (found == NULL) {
found = type; found = type;
else if (type->lang == NULL)
found = type;
if (lang == type->lang) {
found = type;
break;
} }
} }
type = type->next; type = type->next;
} }
if (!found) { if (!found) {
log_warning("could not find nr-type %s for locale %s\n", mtype->name, locale_name(lang)); log_warning("could not find nr-type %s\n", mtype->name);
}
if (lang && found && found->lang != lang) {
log_warning("could not find nr-type %s for locale %s, using %s\n", mtype->name, locale_name(lang), locale_name(found->lang));
} }
return found; return found;
} }
@ -100,12 +93,11 @@ const nrsection *section_add(const char *name)
} }
void void
nrt_register(const struct message_type *mtype, const struct locale *lang, nrt_register(const struct message_type *mtype, const char *section)
const char *string, int level, const char *section)
{ {
unsigned int hash = mtype->key % NRT_MAXHASH; unsigned int hash = mtype->key % NRT_MAXHASH;
nrmessage_type *nrt = nrtypes[hash]; nrmessage_type *nrt = nrtypes[hash];
while (nrt && (nrt->lang != lang || nrt->mtype != mtype)) { while (nrt && nrt->mtype != mtype) {
nrt = nrt->next; nrt = nrt->next;
} }
if (nrt) { if (nrt) {
@ -117,10 +109,8 @@ const char *string, int level, const char *section)
char zNames[256]; char zNames[256];
char *c = zNames; char *c = zNames;
nrt = malloc(sizeof(nrmessage_type)); nrt = malloc(sizeof(nrmessage_type));
nrt->lang = lang;
nrt->mtype = mtype; nrt->mtype = mtype;
nrt->next = nrtypes[hash]; nrt->next = nrtypes[hash];
nrt->level = level;
if (section) { if (section) {
const nrsection *s = section_find(section); const nrsection *s = section_find(section);
if (s == NULL) { if (s == NULL) {
@ -131,8 +121,6 @@ const char *string, int level, const char *section)
else else
nrt->section = NULL; nrt->section = NULL;
nrtypes[hash] = nrt; nrtypes[hash] = nrt;
assert(string && *string);
nrt->string = str_strdup(string);
*c = '\0'; *c = '\0';
for (i = 0; i != mtype->nparameters; ++i) { for (i = 0; i != mtype->nparameters; ++i) {
if (i != 0) if (i != 0)
@ -147,11 +135,11 @@ size_t
nr_render(const struct message *msg, const struct locale *lang, char *buffer, nr_render(const struct message *msg, const struct locale *lang, char *buffer,
size_t size, const void *userdata) size_t size, const void *userdata)
{ {
struct nrmessage_type *nrt = nrt_find(lang, msg->type); struct nrmessage_type *nrt = nrt_find(msg->type);
if (nrt) { if (nrt) {
const char *m = const char *m =
translate(nrt_string(nrt), userdata, nrt->vars, msg->parameters); translate(nrt_string(nrt, lang), userdata, nrt->vars, msg->parameters);
if (m) { if (m) {
return str_strlcpy((char *)buffer, m, size); return str_strlcpy((char *)buffer, m, size);
} }
@ -164,15 +152,9 @@ size_t size, const void *userdata)
return 0; return 0;
} }
int nr_level(const struct message *msg)
{
nrmessage_type *nrt = nrt_find(NULL, msg->type);
return nrt ? nrt->level : 0;
}
const char *nr_section(const struct message *msg) const char *nr_section(const struct message *msg)
{ {
nrmessage_type *nrt = nrt_find(default_locale, msg->type); nrmessage_type *nrt = nrt_find(msg->type);
return nrt ? nrt->section : NULL; return nrt ? nrt->section : NULL;
} }
@ -187,19 +169,18 @@ void free_nrmesssages(void) {
while (nrtypes[i]) { while (nrtypes[i]) {
nrmessage_type *nr = nrtypes[i]; nrmessage_type *nr = nrtypes[i];
nrtypes[i] = nr->next; nrtypes[i] = nr->next;
free(nr->string);
free(nr->vars); free(nr->vars);
free(nr); free(nr);
} }
} }
} }
void export_messages(const struct locale * lang, FILE *F, const char *context) { void export_messages(const struct locale * lang, FILE *F, const char *msgctxt) {
int i; int i;
for (i = 0; i != NRT_MAXHASH; ++i) { for (i = 0; i != NRT_MAXHASH; ++i) {
nrmessage_type *nrt = nrtypes[i]; nrmessage_type *nrt = nrtypes[i];
while (nrt) { while (nrt) {
po_write_msg(F, nrt->mtype->name, nrt->string, context); po_write_msg(F, nrt->mtype->name, nrt_string(nrt, lang), msgctxt);
nrt = nrt->next; nrt = nrt->next;
} }
} }

View File

@ -34,20 +34,16 @@ extern "C" {
void free_nrmesssages(void); void free_nrmesssages(void);
void nrt_register(const struct message_type *mtype, void nrt_register(const struct message_type *mtype, const char *section);
const struct locale *lang, const char *script, struct nrmessage_type *nrt_find(const struct message_type *);
int level, const char *section); const char *nrt_string(const struct nrmessage_type *nrt, const struct locale *lang);
struct nrmessage_type *nrt_find(const struct locale *, const char *nrt_section(const struct nrmessage_type *nrt);
const struct message_type *);
const char *nrt_string(const struct nrmessage_type *type);
const char *nrt_section(const struct nrmessage_type *mt);
size_t nr_render(const struct message *msg, const struct locale *lang, size_t nr_render(const struct message *msg, const struct locale *lang,
char *buffer, size_t size, const void *userdata); char *buffer, size_t size, const void *userdata);
int nr_level(const struct message *msg);
const char *nr_section(const struct message *msg); const char *nr_section(const struct message *msg);
void export_messages(const struct locale * lang, FILE *F, const char *context); void export_messages(const struct locale * lang, FILE *F, const char *msgctxt);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -7,11 +7,8 @@
typedef struct nrmessage_type { typedef struct nrmessage_type {
const struct message_type *mtype; const struct message_type *mtype;
const struct locale *lang;
char *string;
char *vars; char *vars;
struct nrmessage_type *next; struct nrmessage_type *next;
int level;
const char *section; const char *section;
} nrmessage_type; } nrmessage_type;

View File

@ -1368,6 +1368,8 @@ static int parse_messages(xmlDocPtr doc)
if (propSection == NULL) if (propSection == NULL)
propSection = BAD_CAST default_section; propSection = BAD_CAST default_section;
nrt_register(mtype, (const char *)propSection);
/* strings */ /* strings */
xpath->node = node; xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "text", xpath); result = xmlXPathEvalExpression(BAD_CAST "text", xpath);
@ -1380,8 +1382,7 @@ static int parse_messages(xmlDocPtr doc)
xml_readtext(node, &lang, &propText); xml_readtext(node, &lang, &propText);
if (lang) { if (lang) {
xml_cleanup_string(propText); xml_cleanup_string(propText);
nrt_register(mtype, lang, (const char *)propText, 0, locale_setstring(lang, mtype->name, (const char *)propText);
(const char *)propSection);
} }
xmlFree(propText); xmlFree(propText);