call init_locales after parse_json from Lua, downgrade missing string warnings during that to DEBUG (because it's quite common not to have them).

also, these int to bool conversion warnings made a good point, even if I could not reproduce them.
This commit is contained in:
Enno Rehling 2015-01-08 20:55:29 +01:00
parent d3524b9eab
commit 23b8f2bc8a
20 changed files with 83 additions and 86 deletions

View File

@ -32,6 +32,7 @@ int config_parse(const char *json)
if (conf) { if (conf) {
json_config(conf); json_config(conf);
cJSON_Delete(conf); cJSON_Delete(conf);
init_locales();
return 0; return 0;
} else { } else {
int line; int line;

View File

@ -193,7 +193,7 @@ static int tolua_translate(lua_State * L)
const char *lang = tolua_tostring(L, 2, 0); const char *lang = tolua_tostring(L, 2, 0);
struct locale *loc = lang ? get_locale(lang) : default_locale; struct locale *loc = lang ? get_locale(lang) : default_locale;
if (loc) { if (loc) {
str = locale_string(loc, str); str = LOC(loc, str);
tolua_pushstring(L, str); tolua_pushstring(L, str);
return 1; return 1;
} }

View File

@ -92,7 +92,7 @@ static const char *crtag(const char *key)
static const struct locale *lang = NULL; static const struct locale *lang = NULL;
if (!lang) if (!lang)
lang = get_locale(TAG_LOCALE); lang = get_locale(TAG_LOCALE);
return locale_string(lang, key); return LOC(lang, key);
} }
#else #else
#define crtag(x) (x) #define crtag(x) (x)
@ -274,7 +274,7 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty
fputs("EFFECTS\n", F); fputs("EFFECTS\n", F);
} }
fprintf(F, "\"%d %s\"\n", data->value, translate(key, fprintf(F, "\"%d %s\"\n", data->value, translate(key,
locale_string(default_locale, key))); LOC(default_locale, key)));
} }
} }
a = a->next; a = a->next;
@ -331,7 +331,7 @@ static int cr_resource(variant var, char *buffer, const void *userdata)
if (r) { if (r) {
const char *key = resourcename(r, 0); const char *key = resourcename(r, 0);
sprintf(buffer, "\"%s\"", sprintf(buffer, "\"%s\"",
translate(key, locale_string(report->locale, key))); translate(key, LOC(report->locale, key)));
return 0; return 0;
} }
return -1; return -1;
@ -343,7 +343,7 @@ static int cr_race(variant var, char *buffer, const void *userdata)
const struct race *rc = (const race *)var.v; const struct race *rc = (const race *)var.v;
const char *key = rc_name_s(rc, NAME_SINGULAR); const char *key = rc_name_s(rc, NAME_SINGULAR);
sprintf(buffer, "\"%s\"", sprintf(buffer, "\"%s\"",
translate(key, locale_string(report->locale, key))); translate(key, LOC(report->locale, key)));
return 0; return 0;
} }
@ -649,7 +649,7 @@ const faction * f, const region * r)
if (sh->display && sh->display[0]) if (sh->display && sh->display[0])
fprintf(F, "\"%s\";Beschr\n", sh->display); fprintf(F, "\"%s\";Beschr\n", sh->display);
fprintf(F, "\"%s\";Typ\n", translate(sh->type->_name, fprintf(F, "\"%s\";Typ\n", translate(sh->type->_name,
locale_string(f->locale, sh->type->_name))); LOC(f->locale, sh->type->_name)));
fprintf(F, "%d;Groesse\n", sh->size); fprintf(F, "%d;Groesse\n", sh->size);
if (sh->damage) { if (sh->damage) {
int percent = int percent =
@ -839,20 +839,20 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
const char *zRace = rc_name_s(u_race(u), NAME_PLURAL); const char *zRace = rc_name_s(u_race(u), NAME_PLURAL);
fprintf(F, "\"%s\";wahrerTyp\n", fprintf(F, "\"%s\";wahrerTyp\n",
translate(zRace, locale_string(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
} }
} }
else { else {
const race *irace = u_irace(u); const race *irace = u_irace(u);
const char *zRace = rc_name_s(irace, NAME_PLURAL); const char *zRace = rc_name_s(irace, NAME_PLURAL);
fprintf(F, "\"%s\";Typ\n", fprintf(F, "\"%s\";Typ\n",
translate(zRace, locale_string(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
if (u->faction == f && irace != u_race(u)) { if (u->faction == f && irace != u_race(u)) {
assert(skill_enabled(SK_STEALTH) assert(skill_enabled(SK_STEALTH)
|| !"we're resetting this on load, so.. ircase should never be used"); || !"we're resetting this on load, so.. ircase should never be used");
zRace = rc_name_s(u_race(u), NAME_PLURAL); zRace = rc_name_s(u_race(u), NAME_PLURAL);
fprintf(F, "\"%s\";wahrerTyp\n", fprintf(F, "\"%s\";wahrerTyp\n",
translate(zRace, locale_string(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
} }
} }
@ -902,7 +902,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
c = hp_status(u); c = hp_status(u);
if (c && *c && (u->faction == f || omniscient(f))) { if (c && *c && (u->faction == f || omniscient(f))) {
fprintf(F, "\"%s\";hp\n", translate(c, fprintf(F, "\"%s\";hp\n", translate(c,
locale_string(u->faction->locale, c))); LOC(u->faction->locale, c)));
} }
if (fval(u, UFL_HERO)) { if (fval(u, UFL_HERO)) {
fputs("1;hero\n", F); fputs("1;hero\n", F);
@ -998,8 +998,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
pr = 1; pr = 1;
fputs("GEGENSTAENDE\n", F); fputs("GEGENSTAENDE\n", F);
} }
fprintf(F, "%d;%s\n", in, translate(ic, locale_string(f->locale, fprintf(F, "%d;%s\n", in, translate(ic, LOC(f->locale, ic)));
ic)));
} }
cr_output_curses(F, f, u, TYP_UNIT); cr_output_curses(F, f, u, TYP_UNIT);
@ -1294,8 +1293,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
} }
tname = terrain_name(r); tname = terrain_name(r);
fprintf(F, "\"%s\";Terrain\n", translate(tname, locale_string(f->locale, fprintf(F, "\"%s\";Terrain\n", translate(tname, LOC(f->locale, tname)));
tname)));
if (sr->mode != see_unit) if (sr->mode != see_unit)
fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]); fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]);
if (sr->mode == see_neighbour) { if (sr->mode == see_neighbour) {
@ -1359,12 +1357,12 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
if (lux) { if (lux) {
const char *ch = resourcename(lux->rtype, 0); const char *ch = resourcename(lux->rtype, 0);
fprintf(F, "%d;%s\n", 1, translate(ch, fprintf(F, "%d;%s\n", 1, translate(ch,
locale_string(f->locale, ch))); LOC(f->locale, ch)));
} }
if (herb) { if (herb) {
const char *ch = resourcename(herb->rtype, 0); const char *ch = resourcename(herb->rtype, 0);
fprintf(F, "%d;%s\n", 1, translate(ch, fprintf(F, "%d;%s\n", 1, translate(ch,
locale_string(f->locale, ch))); LOC(f->locale, ch)));
} }
} }
} }
@ -1376,7 +1374,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
fprintf(F, "%d;%s\n", (dmd->value fprintf(F, "%d;%s\n", (dmd->value
? dmd->value * dmd->type->price ? dmd->value * dmd->type->price
: -dmd->type->price), : -dmd->type->price),
translate(ch, locale_string(f->locale, ch))); translate(ch, LOC(f->locale, ch)));
dmd = dmd->next; dmd = dmd->next;
} }
} }
@ -1491,7 +1489,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
faction *f = ctx->f; faction *f = ctx->f;
const char *prefix; const char *prefix;
region *r; region *r;
const char *mailto = locale_string(f->locale, "mailto"); const char *mailto = LOC(f->locale, "mailto");
const attrib *a; const attrib *a;
seen_region *sr = NULL; seen_region *sr = NULL;
#if SCORE_MODULE #if SCORE_MODULE
@ -1530,7 +1528,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
fprintf(F, "%d.%d.%d;Build\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); fprintf(F, "%d.%d.%d;Build\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
if (mailto != NULL) { if (mailto != NULL) {
fprintf(F, "\"%s\";mailto\n", mailto); fprintf(F, "\"%s\";mailto\n", mailto);
fprintf(F, "\"%s\";mailcmd\n", locale_string(f->locale, "mailcmd")); fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd"));
} }
show_alliances_cr(F, f); show_alliances_cr(F, f);
@ -1651,8 +1649,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
continue; continue;
ch = resourcename(ptype->itype->rtype, 0); ch = resourcename(ptype->itype->rtype, 0);
fprintf(F, "TRANK %d\n", hashstring(ch)); fprintf(F, "TRANK %d\n", hashstring(ch));
fprintf(F, "\"%s\";Name\n", translate(ch, locale_string(f->locale, fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch)));
ch)));
fprintf(F, "%d;Stufe\n", ptype->level); fprintf(F, "%d;Stufe\n", ptype->level);
if (description == NULL) { if (description == NULL) {
@ -1669,8 +1666,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
while (m->number) { while (m->number) {
ch = resourcename(m->rtype, 0); ch = resourcename(m->rtype, 0);
fprintf(F, "\"%s\"\n", translate(ch, locale_string(f->locale, fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch)));
ch)));
m++; m++;
} }
} }

View File

@ -43,7 +43,7 @@ void init_directions(struct locale *lang) {
register_special_direction(lang, "vortex"); register_special_direction(lang, "vortex");
for (i = 0; dirs[i].direction != NODIRECTION; ++i) { for (i = 0; dirs[i].direction != NODIRECTION; ++i) {
const char *str = locale_string(lang, dirs[i].name); const char *str = locale_string(lang, dirs[i].name, false);
if (str) { if (str) {
variant token; variant token;
token.i = dirs[i].direction; token.i = dirs[i].direction;

View File

@ -305,7 +305,7 @@ const building_type *findbuildingtype(const char *name,
for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) { for (qi = 0, ql = buildingtypes; ql; ql_advance(&ql, &qi, 1)) {
building_type *btype = (building_type *)ql_get(ql, qi); building_type *btype = (building_type *)ql_get(ql, qi);
const char *n = locale_string(lang, btype->_name); const char *n = LOC(lang, btype->_name);
type.v = (void *)btype; type.v = (void *)btype;
addtoken(&bn->names, n, type); addtoken(&bn->names, n, type);
} }

View File

@ -144,7 +144,7 @@ bool ExpensiveMigrants(void)
gamecookie = global.cookie; gamecookie = global.cookie;
value = get_param_int(global.parameters, "study.expensivemigrants", 0); value = get_param_int(global.parameters, "study.expensivemigrants", 0);
} }
return value; return value!=0;
} }
/** Specifies automatic alliance modes. /** Specifies automatic alliance modes.
@ -932,12 +932,12 @@ void init_terrains_translation(const struct locale *lang) {
variant var; variant var;
const char *name; const char *name;
var.v = (void *)terrain; var.v = (void *)terrain;
name = LOC(lang, terrain->_name); name = locale_string(lang, terrain->_name, false);
if (name) { if (name) {
addtoken(tokens, name, var); addtoken(tokens, name, var);
} }
else { else {
log_error("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang)); log_debug("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang));
} }
} }
} }
@ -951,12 +951,12 @@ void init_options_translation(const struct locale * lang) {
variant var; variant var;
var.i = i; var.i = i;
if (options[i]) { if (options[i]) {
const char *name = LOC(lang, options[i]); const char *name = locale_string(lang, options[i], false);
if (name) { if (name) {
addtoken(tokens, name, var); addtoken(tokens, name, var);
} }
else { else {
log_error("no translation for OPTION %s in locale %s", options[i], locale_name(lang)); log_debug("no translation for OPTION %s in locale %s", options[i], locale_name(lang));
} }
} }
} }
@ -1006,9 +1006,9 @@ void init_locale(struct locale *lang)
for (rc = races; rc; rc = rc->next) { for (rc = races; rc; rc = rc->next) {
const char *name; const char *name;
var.v = (void *)rc; var.v = (void *)rc;
name = LOC(lang, rc_name_s(rc, NAME_PLURAL)); name = locale_string(lang, rc_name_s(rc, NAME_PLURAL), false);
if (name) addtoken(tokens, name, var); if (name) addtoken(tokens, name, var);
name = LOC(lang, rc_name_s(rc, NAME_SINGULAR)); name = locale_string(lang, rc_name_s(rc, NAME_SINGULAR), false);
if (name) addtoken(tokens, name, var); if (name) addtoken(tokens, name, var);
} }
@ -1693,7 +1693,7 @@ order *default_order(const struct locale *lang)
assert(i < MAXLOCALES); assert(i < MAXLOCALES);
result = defaults[i]; result = defaults[i];
if (!result && usedefault) { if (!result && usedefault) {
const char * str = locale_string(lang, "defaultorder"); const char * str = LOC(lang, "defaultorder");
if (str) { if (str) {
result = defaults[i] = parse_order(str, lang); result = defaults[i] = parse_order(str, lang);
} }

View File

@ -1045,7 +1045,7 @@ static int add_resourcename_cb(const void * match, const void * key, size_t keyl
cb_get_kv(match, &rtype, sizeof(rtype)); cb_get_kv(match, &rtype, sizeof(rtype));
for (i = 0; i != 2; ++i) { for (i = 0; i != 2; ++i) {
char buffer[128]; char buffer[128];
const char * name = locale_string(lang, resourcename(rtype, (i==0) ? 0 : NMF_PLURAL)); const char * name = LOC(lang, resourcename(rtype, (i == 0) ? 0 : NMF_PLURAL));
if (name && transliterate(buffer, sizeof(buffer), name)) { if (name && transliterate(buffer, sizeof(buffer), name)) {
size_t len = strlen(buffer); size_t len = strlen(buffer);
@ -1096,7 +1096,7 @@ static int add_itemname_cb(const void * match, const void * key, size_t keylen,
int i; int i;
for (i = 0; i != 2; ++i) { for (i = 0; i != 2; ++i) {
char buffer[128]; char buffer[128];
const char * name = locale_string(lang, resourcename(rtype, (i == 0) ? 0 : NMF_PLURAL)); const char * name = LOC(lang, resourcename(rtype, (i == 0) ? 0 : NMF_PLURAL));
if (name && transliterate(buffer, sizeof(buffer), name)) { if (name && transliterate(buffer, sizeof(buffer), name)) {
size_t len = strlen(buffer); size_t len = strlen(buffer);

View File

@ -373,8 +373,8 @@ static void test_skills(CuTest * tc)
CuAssertIntEquals(tc, SK_CROSSBOW, get_skill("kreuz", lang)); CuAssertIntEquals(tc, SK_CROSSBOW, get_skill("kreuz", lang));
CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang)); CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang));
CuAssertStrEquals(tc, "ALCHEMIE", locale_string(lang, "skill::alchemy")); CuAssertStrEquals(tc, "ALCHEMIE", LOC(lang, "skill::alchemy"));
CuAssertStrEquals(tc, "ARMBRUST", locale_string(lang, "skill::crossbow")); CuAssertStrEquals(tc, "ARMBRUST", LOC(lang, "skill::crossbow"));
test_cleanup(); test_cleanup();
} }
@ -396,8 +396,8 @@ static void test_keywords(CuTest * tc)
CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang)); CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang)); CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study")); CuAssertStrEquals(tc, "LERNEN", LOC(lang, "keyword::study"));
CuAssertStrEquals(tc, "NACH", locale_string(lang, "keyword::move")); CuAssertStrEquals(tc, "NACH", LOC(lang, "keyword::move"));
test_cleanup(); test_cleanup();
} }
@ -413,10 +413,10 @@ static void test_strings(CuTest * tc)
test_cleanup(); test_cleanup();
lang = get_or_create_locale("de"); lang = get_or_create_locale("de");
CuAssertPtrNotNull(tc, lang); CuAssertPtrNotNull(tc, lang);
CuAssertPtrEquals(tc, NULL, (void *)locale_string(lang, "move")); CuAssertPtrEquals(tc, NULL, (void *)LOC(lang, "move"));
json_config(json); json_config(json);
CuAssertStrEquals(tc, "NACH", locale_string(lang, "move")); CuAssertStrEquals(tc, "NACH", LOC(lang, "move"));
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "study")); CuAssertStrEquals(tc, "LERNEN", LOC(lang, "study"));
} }
static void test_infinitive_from_config(CuTest *tc) { static void test_infinitive_from_config(CuTest *tc) {

View File

@ -388,8 +388,6 @@ order *parse_order(const char *s, const struct locale * lang)
bool is_repeated(const order * ord) bool is_repeated(const order * ord)
{ {
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
int result = 0;
switch (kwd) { switch (kwd) {
case K_CAST: case K_CAST:
case K_BUY: case K_BUY:
@ -411,13 +409,12 @@ bool is_repeated(const order * ord)
case K_MAKE: case K_MAKE:
case K_LOOT: case K_LOOT:
case K_DESTROY: case K_DESTROY:
result = 1; return true;
break;
default: default:
result = 0; break;
} }
return result; return false;
} }
/** /**
@ -431,7 +428,6 @@ bool is_repeated(const order * ord)
bool is_exclusive(const order * ord) bool is_exclusive(const order * ord)
{ {
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
int result = 0;
switch (kwd) { switch (kwd) {
case K_MOVE: case K_MOVE:
@ -452,13 +448,12 @@ bool is_exclusive(const order * ord)
case K_MAKE: case K_MAKE:
case K_LOOT: case K_LOOT:
case K_DESTROY: case K_DESTROY:
result = 1; return true;
break;
default: default:
result = 0; break;
} }
return result; return false;
} }
/** /**

View File

@ -1568,7 +1568,7 @@ int readgame(const char *filename, int backup)
sh->type = st_find(name); sh->type = st_find(name);
if (sh->type == NULL) { if (sh->type == NULL) {
/* old datafiles */ /* old datafiles */
sh->type = st_find((const char *)locale_string(default_locale, name)); sh->type = st_find((const char *)LOC(default_locale, name));
} }
assert(sh->type || !"ship_type not registered!"); assert(sh->type || !"ship_type not registered!");

View File

@ -76,7 +76,7 @@ const ship_type *findshiptype(const char *name, const struct locale *lang)
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
ship_type *stype = (ship_type *)ql_get(ql, qi); ship_type *stype = (ship_type *)ql_get(ql, qi);
variant var2; variant var2;
const char *n = locale_string(lang, stype->_name); const char *n = LOC(lang, stype->_name);
var2.v = (void *)stype; var2.v = (void *)stype;
addtoken(&sn->names, n, var2); addtoken(&sn->names, n, var2);
} }

View File

@ -1883,7 +1883,7 @@ char *write_unitname(const unit * u, char *buffer, size_t size)
} else { } else {
const struct locale * lang = u->faction ? u->faction->locale : default_locale; const struct locale * lang = u->faction ? u->faction->locale : default_locale;
const char * name = rc_name_s(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL); const char * name = rc_name_s(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL);
slprintf(buffer, size, "%s (%s)", locale_string(lang, name), itoa36(u->no)); slprintf(buffer, size, "%s (%s)", LOC(lang, name), itoa36(u->no));
} }
buffer[size - 1] = 0; buffer[size - 1] = 0;
return buffer; return buffer;
@ -1902,8 +1902,8 @@ bool unit_name_equals_race(const unit *u) {
rc_name(u->_race, NAME_SINGULAR, sing, sizeof(sing)); rc_name(u->_race, NAME_SINGULAR, sing, sizeof(sing));
rc_name(u->_race, NAME_PLURAL, plur, sizeof(plur)); rc_name(u->_race, NAME_PLURAL, plur, sizeof(plur));
if (strcmp(u->name, sing) == 0 || strcmp(u->name, plur) == 0 || if (strcmp(u->name, sing) == 0 || strcmp(u->name, plur) == 0 ||
strcmp(u->name, locale_string(lang, sing)) == 0 || strcmp(u->name, LOC(lang, sing)) == 0 ||
strcmp(u->name, locale_string(lang, plur)) == 0) { strcmp(u->name, LOC(lang, plur)) == 0) {
return true; return true;
} }
} }

View File

@ -968,7 +968,7 @@ static bool CheckOverload(void)
if (value < 0) { if (value < 0) {
value = get_param_int(global.parameters, "rules.check_overload", 0); value = get_param_int(global.parameters, "rules.check_overload", 0);
} }
return value; return value!=0;
} }
int enter_ship(unit * u, struct order *ord, int id, bool report) int enter_ship(unit * u, struct order *ord, int id, bool report)
@ -1411,11 +1411,11 @@ static void init_prefixnames(void)
for (key = 0; race_prefixes[key]; ++key) { for (key = 0; race_prefixes[key]; ++key) {
variant var; variant var;
const char *pname = const char *pname =
locale_string(lang, mkname("prefix", race_prefixes[key])); LOC(lang, mkname("prefix", race_prefixes[key]));
if (findtoken(in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) { if (findtoken(in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) {
var.i = key; var.i = key;
addtoken(&in->names, pname, var); addtoken(&in->names, pname, var);
addtoken(&in->names, locale_string(lang, mkname("prefix", addtoken(&in->names, LOC(lang, mkname("prefix",
race_prefixes[key])), var); race_prefixes[key])), var);
} }
} }
@ -2209,7 +2209,7 @@ static bool display_item(faction * f, unit * u, const item_type * itype)
info = locale_getstring(f->locale, key); info = locale_getstring(f->locale, key);
if (info == NULL) { if (info == NULL) {
info = locale_string(f->locale, mkname("iteminfo", "no_info")); info = LOC(f->locale, mkname("iteminfo", "no_info"));
} }
ADDMSG(&f->msgs, msg_message("displayitem", "weight item description", ADDMSG(&f->msgs, msg_message("displayitem", "weight item description",
itype->weight, itype->rtype, info)); itype->weight, itype->rtype, info));
@ -2261,7 +2261,7 @@ static bool display_race(faction * f, unit * u, const race * rc)
key = mkname("raceinfo", rc->_name); key = mkname("raceinfo", rc->_name);
info = locale_getstring(f->locale, key); info = locale_getstring(f->locale, key);
if (info == NULL) { if (info == NULL) {
info = locale_string(f->locale, mkname("raceinfo", "no_info")); info = LOC(f->locale, mkname("raceinfo", "no_info"));
} }
bytes = (int)strlcpy(bufp, info, size); bytes = (int)strlcpy(bufp, info, size);

View File

@ -104,9 +104,9 @@ bool check_leuchtturm(region * r, faction * f)
{ {
attrib *a; attrib *a;
if (!fval(r->terrain, SEA_REGION)) if (!fval(r->terrain, SEA_REGION)) {
return false; return false;
}
for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse; for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
a = a->next) { a = a->next) {
building *b = (building *)a->data.v; building *b = (building *)a->data.v;
@ -141,7 +141,7 @@ bool check_leuchtturm(region * r, faction * f)
} }
else { else {
/* E3A rule: no perception req'd */ /* E3A rule: no perception req'd */
return maxd; return true;
} }
} }
} }

View File

@ -1025,7 +1025,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f)
if (r->land->ownership) { if (r->land->ownership) {
const char *str = const char *str =
locale_string(f->locale, mkname("morale", itoa10(r->land->morale))); LOC(f->locale, mkname("morale", itoa10(r->land->morale)));
bytes = _snprintf(bufp, size, " %s", str); bytes = _snprintf(bufp, size, " %s", str);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1701,7 +1701,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
if ((mode & HELP_ALL) == HELP_ALL) { if ((mode & HELP_ALL) == HELP_ALL) {
bytes = (int)strlcpy(bufp, locale_string(f->locale, parameters[P_ANY]), size); bytes = (int)strlcpy(bufp, LOC(f->locale, parameters[P_ANY]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
@ -1736,7 +1736,7 @@ show_allies(const faction * f, const ally * allies, char *buf, size_t size)
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
bytes = (int)strlcpy(bufp, locale_string(f->locale, parameters[p]), size); bytes = (int)strlcpy(bufp, LOC(f->locale, parameters[p]), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
hh = 1; hh = 1;

View File

@ -150,7 +150,7 @@ const char **name, const char **basename, int *number, bool singular)
if (owner && owner->faction == viewer) { if (owner && owner->faction == viewer) {
if (name) if (name)
*name = *name =
locale_string(viewer->locale, resourcename(i->type->rtype, LOC(viewer->locale, resourcename(i->type->rtype,
((i->number != 1 && !singular) ? GR_PLURAL : 0))); ((i->number != 1 && !singular) ? GR_PLURAL : 0)));
if (basename) if (basename)
*basename = resourcename(i->type->rtype, 0); *basename = resourcename(i->type->rtype, 0);
@ -163,19 +163,19 @@ const char **name, const char **basename, int *number, bool singular)
*number = 1; *number = 1;
if (pp > 50000 && dragonrace(u_race(owner))) { if (pp > 50000 && dragonrace(u_race(owner))) {
if (name) if (name)
*name = locale_string(viewer->locale, "dragonhoard"); *name = LOC(viewer->locale, "dragonhoard");
if (basename) if (basename)
*basename = "dragonhoard"; *basename = "dragonhoard";
} }
else if (pp > 5000) { else if (pp > 5000) {
if (name) if (name)
*name = locale_string(viewer->locale, "moneychest"); *name = LOC(viewer->locale, "moneychest");
if (basename) if (basename)
*basename = "moneychest"; *basename = "moneychest";
} }
else if (pp > 500) { else if (pp > 500) {
if (name) if (name)
*name = locale_string(viewer->locale, "moneybag"); *name = LOC(viewer->locale, "moneybag");
if (basename) if (basename)
*basename = "moneybag"; *basename = "moneybag";
} }
@ -191,7 +191,7 @@ const char **name, const char **basename, int *number, bool singular)
else { else {
if (name) if (name)
*name = *name =
locale_string(viewer->locale, resourcename(i->type->rtype, LOC(viewer->locale, resourcename(i->type->rtype,
NMF_APPEARANCE | ((i->number != 1 && !singular) ? GR_PLURAL : 0))); NMF_APPEARANCE | ((i->number != 1 && !singular) ? GR_PLURAL : 0)));
if (basename) if (basename)
*basename = resourcename(i->type->rtype, NMF_APPEARANCE); *basename = resourcename(i->type->rtype, NMF_APPEARANCE);
@ -584,7 +584,7 @@ size_t size)
if (u->number && (u->faction == f || telepath_see || isbattle)) { if (u->number && (u->faction == f || telepath_see || isbattle)) {
const char *c = hp_status(u); const char *c = hp_status(u);
c = c ? locale_string(f->locale, c) : 0; c = c ? LOC(f->locale, c) : 0;
bytes = (int)strlcpy(bufp, ", ", size); bytes = (int)strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -1956,7 +1956,7 @@ const char *trailinto(const region * r, const struct locale *lang)
if (r) { if (r) {
const char *tname = terrain_name(r); const char *tname = terrain_name(r);
strcat(strcpy(ref, tname), "_trail"); strcat(strcpy(ref, tname), "_trail");
s = locale_string(lang, ref); s = LOC(lang, ref);
if (s && *s) { if (s && *s) {
if (strstr(s, "%s")) if (strstr(s, "%s"))
return s; return s;
@ -2003,7 +2003,7 @@ static void eval_localize(struct opstack **stack, const void *userdata)
const struct faction *f = (const struct faction *)userdata; const struct faction *f = (const struct faction *)userdata;
const struct locale *lang = f ? f->locale : default_locale; const struct locale *lang = f ? f->locale : default_locale;
const char *c = (const char *)opop_v(stack); const char *c = (const char *)opop_v(stack);
c = locale_string(lang, c); c = LOC(lang, c);
opush_v(stack, strcpy(balloc(strlen(c) + 1), c)); opush_v(stack, strcpy(balloc(strlen(c) + 1), c));
} }

View File

@ -66,7 +66,7 @@ void init_skills(const struct locale *lang) {
const char *skillname(skill_t sk, const struct locale *lang) const char *skillname(skill_t sk, const struct locale *lang)
{ {
if (skill_disabled[sk]) return 0; if (skill_disabled[sk]) return 0;
return locale_string(lang, mkname("skill", skillnames[sk])); return LOC(lang, mkname("skill", skillnames[sk]));
} }

View File

@ -123,7 +123,7 @@ const char *locale_getstring(const locale * lang, const char *key)
return NULL; return NULL;
} }
const char *locale_string(const locale * lang, const char *key) const char *locale_string(const locale * lang, const char *key, bool warn)
{ {
assert(lang); assert(lang);
assert(key); assert(key);
@ -150,9 +150,11 @@ const char *locale_string(const locale * lang, const char *key)
if (find) { if (find) {
return find->str; return find->str;
} }
log_error("missing translation for \"%s\" in locale %s\n", key, lang->name); if (warn) {
log_warning("missing translation for \"%s\" in locale %s\n", key, lang->name);
}
if (lang->fallback) { if (lang->fallback) {
return locale_string(lang->fallback, key); return locale_string(lang->fallback, key, warn);
} }
} }
return 0; return 0;
@ -262,7 +264,7 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_
tokens = get_translations(lang, ut); tokens = get_translations(lang, ut);
for (i = 0; i != maxstrings; ++i) { for (i = 0; i != maxstrings; ++i) {
const char * s = string_cb(i); const char * s = string_cb(i);
const char * key = s ? locale_string(lang, s) : 0; const char * key = s ? locale_string(lang, s, false) : 0;
key = key ? key : s; key = key ? key : s;
if (key) { if (key) {
struct critbit_tree ** cb = (struct critbit_tree **)tokens; struct critbit_tree ** cb = (struct critbit_tree **)tokens;

View File

@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef MY_LOCALE_H #ifndef MY_LOCALE_H
#define MY_LOCALE_H #define MY_LOCALE_H
#include <platform.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -39,7 +42,7 @@ extern "C" {
const char *value); const char *value);
extern const char *locale_getstring(const struct locale *lang, extern const char *locale_getstring(const struct locale *lang,
const char *key); const char *key);
extern const char *locale_string(const struct locale *lang, const char *key); /* does fallback */ extern const char *locale_string(const struct locale *lang, const char *key, bool warn); /* does fallback */
extern unsigned int locale_index(const struct locale *lang); extern unsigned int locale_index(const struct locale *lang);
extern const char *locale_name(const struct locale *lang); extern const char *locale_name(const struct locale *lang);
@ -48,7 +51,7 @@ extern "C" {
extern void make_locales(const char *str); extern void make_locales(const char *str);
#define LOC(lang, s) (lang?locale_string(lang, s):s) #define LOC(lang, s) (lang?locale_string(lang, s, true):s)
extern struct locale *default_locale; extern struct locale *default_locale;
extern struct locale *locales; extern struct locale *locales;

View File

@ -28,7 +28,7 @@ static dir_lookup *dir_name_lookup;
void register_special_direction(struct locale *lang, const char *name) void register_special_direction(struct locale *lang, const char *name)
{ {
const char *token = LOC(lang, name); const char *token = locale_string(lang, name, false);
if (token) { if (token) {
void **tokens = get_translations(lang, UT_SPECDIR); void **tokens = get_translations(lang, UT_SPECDIR);
@ -47,7 +47,7 @@ void register_special_direction(struct locale *lang, const char *name)
} }
} }
else { else {
log_error("no translation for spec_direction '%s' in locale '%s'\n", name, locale_name(lang)); log_debug("no translation for spec_direction '%s' in locale '%s'\n", name, locale_name(lang));
} }
} }