forked from github/server
issue #633: parse FACTION/PARTEI in any language.
added a test since the first fix did not work.
This commit is contained in:
parent
23d1355fa1
commit
e19f0ad381
|
@ -214,6 +214,27 @@ param_t findparam(const char *s, const struct locale * lang)
|
|||
return result;
|
||||
}
|
||||
|
||||
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale)
|
||||
{
|
||||
param_t p;
|
||||
if (!s || s[0] == '@') {
|
||||
return NOPARAM;
|
||||
}
|
||||
p = findparam(s, lang);
|
||||
if (any_locale && p==NOPARAM) {
|
||||
const struct locale *loc;
|
||||
for (loc=locales;loc;loc=nextlocale(loc)) {
|
||||
if (loc!=lang) {
|
||||
p = findparam(s, loc);
|
||||
if (p==P_FACTION || p==P_GAMENAME) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
param_t findparam_ex(const char *s, const struct locale * lang)
|
||||
{
|
||||
param_t result = findparam(s, lang);
|
||||
|
|
|
@ -45,6 +45,7 @@ extern "C" {
|
|||
int findoption(const char *s, const struct locale *lang);
|
||||
|
||||
param_t findparam(const char *s, const struct locale *lang);
|
||||
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale);
|
||||
param_t findparam_ex(const char *s, const struct locale * lang);
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param);
|
||||
param_t getparam(const struct locale *lang);
|
||||
|
|
|
@ -251,9 +251,33 @@ static void test_config_inifile(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_findparam(CuTest *tc) {
|
||||
struct locale *en, *de;
|
||||
test_setup();
|
||||
en = get_or_create_locale("en");
|
||||
locale_setstring(en, parameters[P_FACTION], "FACTION");
|
||||
CuAssertIntEquals(tc, NOPARAM, findparam("FACTION", en));
|
||||
init_parameters(en);
|
||||
CuAssertIntEquals(tc, P_FACTION, findparam("FACTION", en));
|
||||
de = get_or_create_locale("de");
|
||||
locale_setstring(de, parameters[P_FACTION], "PARTEI");
|
||||
CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", de));
|
||||
init_parameters(de);
|
||||
CuAssertIntEquals(tc, P_FACTION, findparam("PARTEI", de));
|
||||
CuAssertIntEquals(tc, NOPARAM, findparam("HODOR", de));
|
||||
|
||||
CuAssertIntEquals(tc, NOPARAM, findparam("PARTEI", en));
|
||||
CuAssertIntEquals(tc, NOPARAM, findparam_block("HODOR", de, false));
|
||||
CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", de, true));
|
||||
CuAssertIntEquals(tc, NOPARAM, findparam_block("PARTEI", en, false));
|
||||
CuAssertIntEquals(tc, P_FACTION, findparam_block("PARTEI", en, true));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_config_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_findparam);
|
||||
SUITE_ADD_TEST(suite, test_config_inifile);
|
||||
SUITE_ADD_TEST(suite, test_config_cache);
|
||||
SUITE_ADD_TEST(suite, test_get_set_param);
|
||||
|
|
|
@ -252,26 +252,6 @@ static faction *factionorders(void)
|
|||
return f;
|
||||
}
|
||||
|
||||
static param_t next_param(const char *s, const struct locale *lang) {
|
||||
param_t p;
|
||||
if (!s || s[0] == '@') {
|
||||
return NOPARAM;
|
||||
}
|
||||
p = findparam(s, lang);
|
||||
if (p==NOPARAM) {
|
||||
const struct locale *loc;
|
||||
for (loc=locales;loc;loc=nextlocale(loc)) {
|
||||
if (loc!=lang) {
|
||||
p = findparam(s, lang);
|
||||
if (p==P_FACTION || p==P_GAMENAME) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
int readorders(const char *filename)
|
||||
{
|
||||
FILE *F = NULL;
|
||||
|
@ -299,7 +279,7 @@ int readorders(const char *filename)
|
|||
const char *s;
|
||||
init_tokens_str(b);
|
||||
s = gettoken(token, sizeof(token));
|
||||
p = next_param(s, lang);
|
||||
p = findparam_block(s, lang, true);
|
||||
switch (p) {
|
||||
case P_GAMENAME:
|
||||
case P_FACTION:
|
||||
|
|
|
@ -295,12 +295,13 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_
|
|||
// TODO: swap the name of s and key
|
||||
const char * s = string_cb(i);
|
||||
if (s) {
|
||||
struct critbit_tree ** cb = (struct critbit_tree **)tokens;
|
||||
const char * key = locale_string(lang, s, false);
|
||||
if (!key) key = s;
|
||||
if (key) {
|
||||
struct critbit_tree ** cb = (struct critbit_tree **)tokens;
|
||||
add_translation(cb, key, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *get_translation(const struct locale *lang, const char *str, int index) {
|
||||
|
|
Loading…
Reference in New Issue