Get the NR message text from locale.

This commit is contained in:
Enno Rehling 2018-05-17 22:47:16 +02:00
parent c0ed53b679
commit 615dfe7ec5
10 changed files with 47 additions and 5659 deletions

View file

@ -1650,7 +1650,7 @@
<text locale="de">"$string"</text>
<text locale="en">"$string"</text>
</message>
<message name="battle_army_index" section="battle">
<message name="para_army_index" section="battle">
<type>
<arg name="index" type="int"/>
<arg name="name" type="string"/>
@ -7179,7 +7179,7 @@
<text locale="en">"$unit($mage) casts $spell($spell), but nobody was in range."</text>
</message>
<message name="after_battle" section="battle">
<message name="para_after_battle" section="battle">
<type>
</type>
<text locale="de">"Einheiten nach dem Kampf:"</text>
@ -7245,7 +7245,7 @@
<text locale="en">"$unit($mage) causes the walls of $building($building) to glow in an eerie magic light."</text>
</message>
<message name="lineup_battle" section="battle">
<message name="para_lineup_battle" section="battle">
<type>
<arg name="turn" type="int"/>
</type>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2886,7 +2886,7 @@ static void print_stats(battle * b)
message *msg;
char buf[1024];
msg = msg_message("battle_army_index", "index name", army_index(s), sname);
msg = msg_message("para_army_index", "index name", army_index(s), sname);
battle_message_faction(b, f, msg);
msg_release(msg);
@ -3497,9 +3497,9 @@ static int battle_report(battle * b)
sbs_init(&sbs, buf, sizeof(buf));
if (cont)
m = msg_message("lineup_battle", "turn", b->turn);
m = msg_message("para_lineup_battle", "turn", b->turn);
else
m = msg_message("after_battle", "");
m = msg_message("para_after_battle", "");
battle_message_faction(b, fac, m);
msg_release(m);

View file

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

View file

@ -743,6 +743,10 @@ rp_messages(struct stream *out, message_list * msgs, faction * viewer, int inden
k = 1;
}
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);
}
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);
}
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)
{
return lang ? lang->name : "(null)";

View file

@ -58,7 +58,6 @@ extern "C" {
void make_locales(const char *str);
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);
#define LOC(lang, s) (lang?locale_string(lang, s, true):s)

View file

@ -32,7 +32,12 @@ static nrmessage_type *nrtypes[NRT_MAXHASH];
const char *nrt_string(const struct nrmessage_type *nrt, const struct locale *lang)
{
return locale_getstring(lang, nrt->mtype->name);
const char * str = locale_getstring(lang, nrt->mtype->name);
if (!str) {
str = locale_getstring(default_locale, nrt->mtype->name);
}
assert(str);
return str;
}
nrmessage_type *nrt_find(const struct message_type * mtype)
@ -169,3 +174,14 @@ void free_nrmesssages(void) {
}
}
}
void export_messages(const struct locale * lang, FILE *F, const char *msgctxt) {
int i;
for (i = 0; i != NRT_MAXHASH; ++i) {
nrmessage_type *nrt = nrtypes[i];
while (nrt) {
po_write_msg(F, nrt->mtype->name, nrt_string(nrt, lang), msgctxt);
nrt = nrt->next;
}
}
}

View file

@ -43,6 +43,8 @@ extern "C" {
char *buffer, size_t size, const void *userdata);
const char *nr_section(const struct message *msg);
void export_messages(const struct locale * lang, FILE *F, const char *msgctxt);
#ifdef __cplusplus
}
#endif