Merge pull request #98 from badgerman/master

init_locales changes and minor things
This commit is contained in:
Enno Rehling 2015-01-08 21:44:07 +01:00
commit 90f4ed9753
22 changed files with 94 additions and 96 deletions

View File

@ -54,10 +54,6 @@ function disable_test_bug_1738_build_castle_e3()
-- 33/4 makes 8 points, resulting size is 258.
process_orders()
--[[
init_reports()
write_report(f)
]]--
-- resulting size should be 250 because unit 2
-- does not have the needed minimum skill.
assert_equal(c.size, 250)
@ -302,13 +298,11 @@ function test_ship_capacity()
process_orders()
if r2~=u1.region then
print(get_turn(), u1, u1.faction)
write_reports()
end
assert_equal(r2, u1.region)
assert_not_equal(r2.id, u2.region.id)
if r2~=u3.region then
print(get_turn(), u3, u3.faction)
write_reports()
end
assert_equal(r2, u3.region)
assert_not_equal(r2.id, u4.region.id)
@ -375,8 +369,6 @@ function test_region_owner_cannot_leave_castle()
u:clear_orders()
u:add_order("BETRETE BURG " .. itoa36(b2.id))
process_orders()
init_reports()
write_report(u.faction)
assert_equal(b1, u.building, "region owner has left the building") -- region owners may not leave
end

View File

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

View File

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

View File

@ -92,7 +92,7 @@ static const char *crtag(const char *key)
static const struct locale *lang = NULL;
if (!lang)
lang = get_locale(TAG_LOCALE);
return locale_string(lang, key);
return LOC(lang, key);
}
#else
#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);
}
fprintf(F, "\"%d %s\"\n", data->value, translate(key,
locale_string(default_locale, key)));
LOC(default_locale, key)));
}
}
a = a->next;
@ -331,7 +331,7 @@ static int cr_resource(variant var, char *buffer, const void *userdata)
if (r) {
const char *key = resourcename(r, 0);
sprintf(buffer, "\"%s\"",
translate(key, locale_string(report->locale, key)));
translate(key, LOC(report->locale, key)));
return 0;
}
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 char *key = rc_name_s(rc, NAME_SINGULAR);
sprintf(buffer, "\"%s\"",
translate(key, locale_string(report->locale, key)));
translate(key, LOC(report->locale, key)));
return 0;
}
@ -649,7 +649,7 @@ const faction * f, const region * r)
if (sh->display && sh->display[0])
fprintf(F, "\"%s\";Beschr\n", sh->display);
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);
if (sh->damage) {
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)) {
const char *zRace = rc_name_s(u_race(u), NAME_PLURAL);
fprintf(F, "\"%s\";wahrerTyp\n",
translate(zRace, locale_string(f->locale, zRace)));
translate(zRace, LOC(f->locale, zRace)));
}
}
else {
const race *irace = u_irace(u);
const char *zRace = rc_name_s(irace, NAME_PLURAL);
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)) {
assert(skill_enabled(SK_STEALTH)
|| !"we're resetting this on load, so.. ircase should never be used");
zRace = rc_name_s(u_race(u), NAME_PLURAL);
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);
if (c && *c && (u->faction == f || omniscient(f))) {
fprintf(F, "\"%s\";hp\n", translate(c,
locale_string(u->faction->locale, c)));
LOC(u->faction->locale, c)));
}
if (fval(u, UFL_HERO)) {
fputs("1;hero\n", F);
@ -998,8 +998,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
pr = 1;
fputs("GEGENSTAENDE\n", F);
}
fprintf(F, "%d;%s\n", in, translate(ic, locale_string(f->locale,
ic)));
fprintf(F, "%d;%s\n", in, translate(ic, LOC(f->locale, ic)));
}
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);
fprintf(F, "\"%s\";Terrain\n", translate(tname, locale_string(f->locale,
tname)));
fprintf(F, "\"%s\";Terrain\n", translate(tname, LOC(f->locale, tname)));
if (sr->mode != see_unit)
fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]);
if (sr->mode == see_neighbour) {
@ -1359,12 +1357,12 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
if (lux) {
const char *ch = resourcename(lux->rtype, 0);
fprintf(F, "%d;%s\n", 1, translate(ch,
locale_string(f->locale, ch)));
LOC(f->locale, ch)));
}
if (herb) {
const char *ch = resourcename(herb->rtype, 0);
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
? dmd->value * dmd->type->price
: -dmd->type->price),
translate(ch, locale_string(f->locale, ch)));
translate(ch, LOC(f->locale, ch)));
dmd = dmd->next;
}
}
@ -1491,7 +1489,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
faction *f = ctx->f;
const char *prefix;
region *r;
const char *mailto = locale_string(f->locale, "mailto");
const char *mailto = LOC(f->locale, "mailto");
const attrib *a;
seen_region *sr = NULL;
#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);
if (mailto != NULL) {
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);
@ -1651,8 +1649,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
continue;
ch = resourcename(ptype->itype->rtype, 0);
fprintf(F, "TRANK %d\n", hashstring(ch));
fprintf(F, "\"%s\";Name\n", translate(ch, locale_string(f->locale,
ch)));
fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch)));
fprintf(F, "%d;Stufe\n", ptype->level);
if (description == NULL) {
@ -1669,8 +1666,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
while (m->number) {
ch = resourcename(m->rtype, 0);
fprintf(F, "\"%s\"\n", translate(ch, locale_string(f->locale,
ch)));
fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch)));
m++;
}
}

View File

@ -43,7 +43,7 @@ void init_directions(struct locale *lang) {
register_special_direction(lang, "vortex");
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) {
variant token;
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)) {
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;
addtoken(&bn->names, n, type);
}

View File

@ -144,7 +144,7 @@ bool ExpensiveMigrants(void)
gamecookie = global.cookie;
value = get_param_int(global.parameters, "study.expensivemigrants", 0);
}
return value;
return value!=0;
}
/** Specifies automatic alliance modes.
@ -932,12 +932,12 @@ void init_terrains_translation(const struct locale *lang) {
variant var;
const char *name;
var.v = (void *)terrain;
name = LOC(lang, terrain->_name);
name = locale_string(lang, terrain->_name, false);
if (name) {
addtoken(tokens, name, var);
}
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;
var.i = i;
if (options[i]) {
const char *name = LOC(lang, options[i]);
const char *name = locale_string(lang, options[i], false);
if (name) {
addtoken(tokens, name, var);
}
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) {
const char *name;
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);
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);
}
@ -1122,8 +1122,15 @@ void set_param(struct param **p, const char *key, const char *data)
while (*p != NULL) {
int cmp = strcmp((*p)->name, key);
if (cmp == 0) {
free((*p)->data);
(*p)->data = _strdup(data);
par = *p;
free(par->data);
if (data) {
par->data = _strdup(data);
}
else {
*p = par->next;
free(par);
}
return;
}
else if (cmp > 0) {
@ -1686,7 +1693,7 @@ order *default_order(const struct locale *lang)
assert(i < MAXLOCALES);
result = defaults[i];
if (!result && usedefault) {
const char * str = locale_string(lang, "defaultorder");
const char * str = LOC(lang, "defaultorder");
if (str) {
result = defaults[i] = parse_order(str, lang);
}

View File

@ -71,6 +71,8 @@ static void test_get_set_param(CuTest * tc)
set_param(&par, "bar", "foo");
CuAssertStrEquals(tc, "bar", get_param(par, "foo"));
CuAssertStrEquals(tc, "foo", get_param(par, "bar"));
set_param(&par, "bar", NULL);
CuAssertPtrEquals(tc, NULL, (void *)get_param(par, "bar"));
}
static void test_param_int(CuTest * tc)

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));
for (i = 0; i != 2; ++i) {
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)) {
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;
for (i = 0; i != 2; ++i) {
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)) {
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_ALCHEMY, get_skill("alchemie", lang));
CuAssertStrEquals(tc, "ALCHEMIE", locale_string(lang, "skill::alchemy"));
CuAssertStrEquals(tc, "ARMBRUST", locale_string(lang, "skill::crossbow"));
CuAssertStrEquals(tc, "ALCHEMIE", LOC(lang, "skill::alchemy"));
CuAssertStrEquals(tc, "ARMBRUST", LOC(lang, "skill::crossbow"));
test_cleanup();
}
@ -396,8 +396,8 @@ static void test_keywords(CuTest * tc)
CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "keyword::study"));
CuAssertStrEquals(tc, "NACH", locale_string(lang, "keyword::move"));
CuAssertStrEquals(tc, "LERNEN", LOC(lang, "keyword::study"));
CuAssertStrEquals(tc, "NACH", LOC(lang, "keyword::move"));
test_cleanup();
}
@ -413,10 +413,10 @@ static void test_strings(CuTest * tc)
test_cleanup();
lang = get_or_create_locale("de");
CuAssertPtrNotNull(tc, lang);
CuAssertPtrEquals(tc, NULL, (void *)locale_string(lang, "move"));
CuAssertPtrEquals(tc, NULL, (void *)LOC(lang, "move"));
json_config(json);
CuAssertStrEquals(tc, "NACH", locale_string(lang, "move"));
CuAssertStrEquals(tc, "LERNEN", locale_string(lang, "study"));
CuAssertStrEquals(tc, "NACH", LOC(lang, "move"));
CuAssertStrEquals(tc, "LERNEN", LOC(lang, "study"));
}
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)
{
keyword_t kwd = ORD_KEYWORD(ord);
int result = 0;
switch (kwd) {
case K_CAST:
case K_BUY:
@ -411,13 +409,12 @@ bool is_repeated(const order * ord)
case K_MAKE:
case K_LOOT:
case K_DESTROY:
result = 1;
break;
return true;
default:
result = 0;
break;
}
return result;
return false;
}
/**
@ -431,7 +428,6 @@ bool is_repeated(const order * ord)
bool is_exclusive(const order * ord)
{
keyword_t kwd = ORD_KEYWORD(ord);
int result = 0;
switch (kwd) {
case K_MOVE:
@ -452,13 +448,12 @@ bool is_exclusive(const order * ord)
case K_MAKE:
case K_LOOT:
case K_DESTROY:
result = 1;
break;
return true;
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);
if (sh->type == NULL) {
/* 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!");

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)) {
ship_type *stype = (ship_type *)ql_get(ql, qi);
variant var2;
const char *n = locale_string(lang, stype->_name);
const char *n = LOC(lang, stype->_name);
var2.v = (void *)stype;
addtoken(&sn->names, n, var2);
}

View File

@ -1883,7 +1883,7 @@ char *write_unitname(const unit * u, char *buffer, size_t size)
} else {
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);
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;
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_PLURAL, plur, sizeof(plur));
if (strcmp(u->name, sing) == 0 || strcmp(u->name, plur) == 0 ||
strcmp(u->name, locale_string(lang, sing)) == 0 ||
strcmp(u->name, locale_string(lang, plur)) == 0) {
strcmp(u->name, LOC(lang, sing)) == 0 ||
strcmp(u->name, LOC(lang, plur)) == 0) {
return true;
}
}

View File

@ -968,7 +968,7 @@ static bool CheckOverload(void)
if (value < 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)
@ -1411,11 +1411,11 @@ static void init_prefixnames(void)
for (key = 0; race_prefixes[key]; ++key) {
variant var;
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) {
var.i = key;
addtoken(&in->names, pname, var);
addtoken(&in->names, locale_string(lang, mkname("prefix",
addtoken(&in->names, LOC(lang, mkname("prefix",
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);
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",
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);
info = locale_getstring(f->locale, key);
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);

View File

@ -104,9 +104,9 @@ bool check_leuchtturm(region * r, faction * f)
{
attrib *a;
if (!fval(r->terrain, SEA_REGION))
if (!fval(r->terrain, SEA_REGION)) {
return false;
}
for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
a = a->next) {
building *b = (building *)a->data.v;
@ -141,7 +141,7 @@ bool check_leuchtturm(region * r, faction * f)
}
else {
/* 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) {
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);
if (wrptr(&bufp, &size, bytes) != 0)
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)
WARN_STATIC_BUFFER();
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)
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)
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)
WARN_STATIC_BUFFER();
hh = 1;

View File

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

View File

@ -66,7 +66,7 @@ void init_skills(const struct locale *lang) {
const char *skillname(skill_t sk, const struct locale *lang)
{
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;
}
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(key);
@ -150,9 +150,11 @@ const char *locale_string(const locale * lang, const char *key)
if (find) {
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) {
return locale_string(lang->fallback, key);
return locale_string(lang->fallback, key, warn);
}
}
return 0;
@ -262,7 +264,7 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_
tokens = get_translations(lang, ut);
for (i = 0; i != maxstrings; ++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;
if (key) {
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
#define MY_LOCALE_H
#include <platform.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -39,7 +42,7 @@ extern "C" {
const char *value);
extern const char *locale_getstring(const struct locale *lang,
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 const char *locale_name(const struct locale *lang);
@ -48,7 +51,7 @@ extern "C" {
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 *locales;

View File

@ -28,7 +28,7 @@ static dir_lookup *dir_name_lookup;
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) {
void **tokens = get_translations(lang, UT_SPECDIR);
@ -47,7 +47,7 @@ void register_special_direction(struct locale *lang, const char *name)
}
}
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));
}
}