forked from github/server
REKRUTIERE RASSE funktioniert nicht (Bug 2012)
http://bugs.eressea.de/view.php?id=2012 init_locales must not be called before races have been configured. make jsonconf initialize translations handle missing strings in translations, log errors.
This commit is contained in:
parent
722be026b2
commit
1500bcac70
|
@ -1736,12 +1736,51 @@ static const char * parameter_key(int i)
|
|||
return parameters[i];
|
||||
}
|
||||
|
||||
|
||||
void init_terrains_translation(const struct locale *lang) {
|
||||
void **tokens;
|
||||
const terrain_type *terrain;
|
||||
|
||||
tokens = get_translations(lang, UT_TERRAINS);
|
||||
for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
|
||||
variant var;
|
||||
const char *name;
|
||||
var.v = (void *)terrain;
|
||||
name = LOC(lang, terrain->_name);
|
||||
if (name) {
|
||||
addtoken(tokens, name, var);
|
||||
}
|
||||
else {
|
||||
log_error_n("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_options_translation(const struct locale * lang) {
|
||||
void **tokens;
|
||||
int i;
|
||||
|
||||
tokens = get_translations(lang, UT_OPTIONS);
|
||||
for (i = 0; i != MAXOPTIONS; ++i) {
|
||||
variant var;
|
||||
var.i = i;
|
||||
if (options[i]) {
|
||||
const char *name = LOC(lang, options[i]);
|
||||
if (name) {
|
||||
addtoken(tokens, name, var);
|
||||
}
|
||||
else {
|
||||
log_error_n("no translation for OPTION %s in locale %s", options[i], locale_name(lang));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init_locale(const struct locale *lang)
|
||||
{
|
||||
variant var;
|
||||
int i;
|
||||
const struct race *rc;
|
||||
const terrain_type *terrain;
|
||||
void **tokens;
|
||||
|
||||
tokens = get_translations(lang, UT_MAGIC);
|
||||
|
@ -1755,12 +1794,19 @@ static void init_locale(const struct locale *lang)
|
|||
sstr = _strdup(str);
|
||||
tok = strtok(sstr, " ");
|
||||
while (tok) {
|
||||
const char *name;
|
||||
for (i = 0; i != MAXMAGIETYP; ++i) {
|
||||
if (strcmp(tok, magic_school[i]) == 0) break;
|
||||
}
|
||||
assert(i != MAXMAGIETYP);
|
||||
var.i = i;
|
||||
addtoken(tokens, LOC(lang, mkname("school", tok)), var);
|
||||
name = LOC(lang, mkname("school", tok));
|
||||
if (name) {
|
||||
addtoken(tokens, name, var);
|
||||
}
|
||||
else {
|
||||
log_error_n("no translation for magic school %s in locale %s", tok, locale_name(lang));
|
||||
}
|
||||
tok = strtok(NULL, " ");
|
||||
}
|
||||
free(sstr);
|
||||
|
@ -1772,24 +1818,18 @@ static void init_locale(const struct locale *lang)
|
|||
|
||||
tokens = get_translations(lang, UT_RACES);
|
||||
for (rc = races; rc; rc = rc->next) {
|
||||
const char *name;
|
||||
var.v = (void *)rc;
|
||||
addtoken(tokens, LOC(lang, rc_name(rc, 1)), var);
|
||||
addtoken(tokens, LOC(lang, rc_name(rc, 0)), var);
|
||||
name = LOC(lang, rc_name(rc, 1));
|
||||
if (name) addtoken(tokens, name, var);
|
||||
name = LOC(lang, rc_name(rc, 0));
|
||||
if (name) addtoken(tokens, name, var);
|
||||
}
|
||||
|
||||
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
|
||||
|
||||
tokens = get_translations(lang, UT_OPTIONS);
|
||||
for (i = 0; i != MAXOPTIONS; ++i) {
|
||||
var.i = i;
|
||||
if (options[i]) addtoken(tokens, LOC(lang, options[i]), var);
|
||||
}
|
||||
|
||||
tokens = get_translations(lang, UT_TERRAINS);
|
||||
for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
|
||||
var.v = (void *)terrain;
|
||||
addtoken(tokens, LOC(lang, terrain->_name), var);
|
||||
}
|
||||
init_options_translation(lang);
|
||||
init_terrains_translation(lang);
|
||||
}
|
||||
|
||||
typedef struct param {
|
||||
|
@ -1918,10 +1958,7 @@ void init_locales(void)
|
|||
{
|
||||
int l;
|
||||
for (l = 0; localenames[l]; ++l) {
|
||||
const struct locale *lang = get_locale(localenames[l]);
|
||||
if (!lang) {
|
||||
lang = get_or_create_locale(localenames[l]);
|
||||
}
|
||||
const struct locale *lang = get_or_create_locale(localenames[l]);
|
||||
init_locale(lang);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ extern "C" {
|
|||
/* ------------------------------------------------------------- */
|
||||
void add_translation(struct critbit_tree **cb, const char *str, int i);
|
||||
void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings);
|
||||
void init_locales(void);
|
||||
int shipspeed(const struct ship *sh, const struct unit *u);
|
||||
|
||||
#define i2b(i) ((bool)((i)?(true):(false)))
|
||||
|
|
|
@ -670,5 +670,6 @@ void json_config(cJSON *json) {
|
|||
log_error_n("config contains unknown attribute %s", child->string);
|
||||
}
|
||||
}
|
||||
init_locales();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "types.h"
|
||||
#include "jsonconf.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "building.h"
|
||||
#include "direction.h"
|
||||
#include "item.h"
|
||||
|
@ -97,6 +98,23 @@ static void test_races(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_findrace(CuTest *tc) {
|
||||
const char * data = "{\"races\": { \"dwarf\": {} }, \"strings\": { \"de\" : { \"race::dwarf\" : \"Zwerg\" } } }";
|
||||
cJSON *json = cJSON_Parse(data);
|
||||
const struct locale *lang;
|
||||
const race *rc;
|
||||
|
||||
CuAssertPtrNotNull(tc, json);
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("de");
|
||||
CuAssertPtrEquals(tc, 0, (void *)findrace("Zwerg", lang));
|
||||
|
||||
json_config(json);
|
||||
rc = findrace("Zwerg", lang);
|
||||
CuAssertPtrNotNull(tc, rc);
|
||||
CuAssertStrEquals(tc, "dwarf", rc->_name[0]);
|
||||
}
|
||||
|
||||
static void test_items(CuTest * tc)
|
||||
{
|
||||
const char * data = "{\"items\": { "
|
||||
|
@ -389,6 +407,7 @@ CuSuite *get_jsonconf_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_castles);
|
||||
SUITE_ADD_TEST(suite, test_terrains);
|
||||
SUITE_ADD_TEST(suite, test_races);
|
||||
SUITE_ADD_TEST(suite, test_findrace);
|
||||
SUITE_ADD_TEST(suite, test_strings);
|
||||
SUITE_ADD_TEST(suite, test_spells);
|
||||
SUITE_ADD_TEST(suite, test_flags);
|
||||
|
|
|
@ -2175,7 +2175,6 @@ static int parse_strings(xmlDocPtr doc)
|
|||
xmlXPathFreeObject(strings);
|
||||
|
||||
xmlXPathFreeContext(xpath);
|
||||
init_locales();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ int read_xml(const char *filename, const char *catalog)
|
|||
result = 0;
|
||||
}
|
||||
xmlFreeDoc(doc);
|
||||
init_locales();
|
||||
return result;
|
||||
#else
|
||||
log_error("LIBXML2 disabled, cannot read %s.\n", filename);
|
||||
|
|
Loading…
Reference in New Issue