forked from github/server
Implement a working LOCALE command. OBS: Throws away any command that isn't easy to translate.
This commit is contained in:
parent
6c2f6a98eb
commit
d55cfb8cbf
13 changed files with 142 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
"plant": "PLANT",
|
||||
"grow": [ "GROW", "BREED" ],
|
||||
"promote": ["PROMOTE", "PROMOTION" ],
|
||||
"locale": ["LANGUAGE", "LOCALE"],
|
||||
"combat": [ "COMBAT", "FIGHT" ]
|
||||
},
|
||||
"de": {
|
||||
|
@ -65,6 +66,7 @@
|
|||
"alliance": "ALLIANZ",
|
||||
"claim": ["BEANSPRUCHE", "BEANSPRUCHEN"],
|
||||
"promote": ["BEFÖRDERE", "BEFÖRDERUNG"],
|
||||
"locale": ["SPRACHE", "LOCALE"],
|
||||
"pay": ["BEZAHLE", "BEZAHLEN"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4806,6 +4806,10 @@ msgctxt "keyword"
|
|||
msgid "promote"
|
||||
msgstr "BEFÖRDERE"
|
||||
|
||||
msgctxt "keyword"
|
||||
msgid "locale"
|
||||
msgstr "SPRACHE"
|
||||
|
||||
msgid "skeleton_prefix_0"
|
||||
msgstr "Klapperige"
|
||||
|
||||
|
|
|
@ -4304,6 +4304,10 @@ msgctxt "keyword"
|
|||
msgid "promote"
|
||||
msgstr "PROMOTE"
|
||||
|
||||
msgctxt "keyword"
|
||||
msgid "locale"
|
||||
msgstr "LANGUAGE"
|
||||
|
||||
msgid "stone"
|
||||
msgstr "stone"
|
||||
|
||||
|
|
|
@ -835,3 +835,18 @@ faction *faction_create(int no)
|
|||
fhash(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
void change_locale(faction *f, const struct locale *lang) {
|
||||
unit *ux;
|
||||
for (ux = f->units; ux; ux = ux->nextF) {
|
||||
translate_orders(ux, lang, &ux->orders);
|
||||
if (ux->old_orders) {
|
||||
translate_orders(ux, lang, &ux->old_orders);
|
||||
}
|
||||
if (ux->thisorder) {
|
||||
translate_orders(ux, lang, &ux->thisorder);
|
||||
}
|
||||
}
|
||||
f->locale = lang;
|
||||
}
|
||||
|
||||
|
|
|
@ -155,6 +155,7 @@ extern "C" {
|
|||
int count_migrants(const struct faction * f);
|
||||
int count_maxmigrants(const struct faction * f);
|
||||
int max_magicians(const struct faction * f);
|
||||
void change_locale(struct faction *f, const struct locale *lang);
|
||||
|
||||
#define MONSTER_ID 666
|
||||
struct faction *getfaction(void);
|
||||
|
|
|
@ -135,11 +135,59 @@ static void test_addfaction(CuTest *tc) {
|
|||
static void test_check_passwd(CuTest *tc) {
|
||||
faction *f;
|
||||
|
||||
test_setup();
|
||||
f = test_create_faction(NULL);
|
||||
faction_setpassword(f, password_hash("password", PASSWORD_DEFAULT));
|
||||
CuAssertTrue(tc, checkpasswd(f, "password"));
|
||||
CuAssertTrue(tc, !checkpasswd(f, "assword"));
|
||||
CuAssertTrue(tc, !checkpasswd(f, "PASSWORD"));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_change_locale(CuTest *tc) {
|
||||
faction *f;
|
||||
unit *u;
|
||||
order *ord;
|
||||
struct locale *lang;
|
||||
|
||||
test_setup();
|
||||
f = test_create_faction(NULL);
|
||||
lang = get_or_create_locale("en");
|
||||
u = test_create_unit(f, test_create_plain(0, 0));
|
||||
u->thisorder = create_order(K_ENTERTAIN, f->locale, NULL);
|
||||
|
||||
u->old_orders = create_order(K_WORK, f->locale, NULL);
|
||||
u->old_orders->next = ord = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ALCHEMY]);
|
||||
CuAssertIntEquals(tc, SK_ALCHEMY - 100, ord->id);
|
||||
ord->next = create_order(K_GIVE, f->locale, "abcd 1 Schwert");
|
||||
|
||||
unit_addorder(u, create_order(K_NAME, f->locale, "EINHEIT Hodor"));
|
||||
unit_addorder(u, create_order(K_ENTERTAIN, f->locale, NULL));
|
||||
unit_addorder(u, create_order(K_KOMMENTAR, f->locale, "ich bin kein Tintenfisch"));
|
||||
unit_addorder(u, ord = create_order(K_STUDY, f->locale, skillnames[SK_ENTERTAINMENT]));
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id);
|
||||
|
||||
change_locale(f, lang);
|
||||
CuAssertPtrEquals(tc, lang, (void *)f->locale);
|
||||
CuAssertPtrNotNull(tc, u->thisorder);
|
||||
|
||||
CuAssertPtrNotNull(tc, ord = u->old_orders);
|
||||
CuAssertIntEquals(tc, K_WORK, ord->command);
|
||||
CuAssertPtrNotNull(tc, ord = ord->next);
|
||||
CuAssertIntEquals(tc, K_AUTOSTUDY, ord->command);
|
||||
CuAssertIntEquals(tc, SK_ALCHEMY - 100, ord->id);
|
||||
CuAssertPtrEquals(tc, NULL, ord->next);
|
||||
|
||||
CuAssertPtrNotNull(tc, ord = u->orders);
|
||||
CuAssertIntEquals(tc, K_ENTERTAIN, ord->command);
|
||||
CuAssertPtrNotNull(tc, ord = ord->next);
|
||||
CuAssertIntEquals(tc, K_KOMMENTAR, ord->command);
|
||||
CuAssertPtrNotNull(tc, ord = ord->next);
|
||||
CuAssertIntEquals(tc, K_STUDY, ord->command);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id);
|
||||
CuAssertPtrEquals(tc, NULL, ord->next);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_get_monsters(CuTest *tc) {
|
||||
|
@ -366,6 +414,7 @@ CuSuite *get_faction_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_set_origin);
|
||||
SUITE_ADD_TEST(suite, test_set_origin_bug);
|
||||
SUITE_ADD_TEST(suite, test_check_passwd);
|
||||
SUITE_ADD_TEST(suite, test_change_locale);
|
||||
SUITE_ADD_TEST(suite, test_valid_race);
|
||||
SUITE_ADD_TEST(suite, test_set_email);
|
||||
SUITE_ADD_TEST(suite, test_dbstrings);
|
||||
|
|
|
@ -213,7 +213,7 @@ int stream_order(struct stream *out, const struct order *ord, const struct local
|
|||
void free_order(order * ord)
|
||||
{
|
||||
if (ord != NULL) {
|
||||
assert(ord->next == 0);
|
||||
assert(ord->next == NULL);
|
||||
free(ord);
|
||||
}
|
||||
}
|
||||
|
@ -641,4 +641,3 @@ void close_orders(void) {
|
|||
(void)init_order(NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1849,3 +1849,46 @@ void unit_convert_race(unit *u, const race *rc, const char *rcname)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void translate_orders(unit *u, const struct locale *lang, order **list)
|
||||
{
|
||||
order **po = list;
|
||||
(void)lang;
|
||||
while (*po) {
|
||||
order *ord = *po;
|
||||
if (ord->id <= 0) {
|
||||
/* we can keep these, they have no problematic arguments */
|
||||
po = &ord->next;
|
||||
continue;
|
||||
}
|
||||
switch (getkeyword(ord)) {
|
||||
case K_ATTACK:
|
||||
case K_BANNER:
|
||||
case K_DRIVE:
|
||||
case K_FOLLOW:
|
||||
case K_GROUP:
|
||||
case K_KOMMENTAR:
|
||||
case K_MAIL:
|
||||
case K_NUMBER:
|
||||
case K_PASSWORD:
|
||||
case K_PREFIX:
|
||||
case K_RECRUIT:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_TEACH:
|
||||
case K_TRANSPORT:
|
||||
case K_URSPRUNG:
|
||||
/* we can keep these, they need no translation */
|
||||
po = &ord->next;
|
||||
break;
|
||||
default:
|
||||
/* we don't know what to do with these, drop them */
|
||||
if (u->thisorder == ord) {
|
||||
u->thisorder = NULL;
|
||||
}
|
||||
*po = ord->next;
|
||||
ord->next = NULL;
|
||||
free_order(ord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,6 +223,8 @@ extern "C" {
|
|||
bool unit_name_equals_race(const struct unit *u);
|
||||
|
||||
void unit_convert_race(struct unit *u, const struct race *rc, const char *rcname);
|
||||
void translate_orders(struct unit *u, const struct locale *lang, struct order **list);
|
||||
|
||||
/* getunit results: */
|
||||
#define GET_UNIT 0
|
||||
#define GET_NOTFOUND 1
|
||||
|
|
18
src/laws.c
18
src/laws.c
|
@ -3998,6 +3998,7 @@ void init_processor(void)
|
|||
p += 10;
|
||||
add_proc_global(p, renumber_factions, "Neue Nummern");
|
||||
}
|
||||
add_proc_order(p, K_LOCALE, locale_cmd, 0, "Sprache wechseln");
|
||||
}
|
||||
|
||||
static void reset_game(void)
|
||||
|
@ -4217,3 +4218,20 @@ seefaction(const faction * f, const region * r, const unit * u, int modifier)
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int locale_cmd(unit * u, order * ord)
|
||||
{
|
||||
char token[128];
|
||||
const char * name;
|
||||
faction *f = u->faction;
|
||||
|
||||
init_order(ord, f->locale);
|
||||
name = gettoken(token, sizeof(token));
|
||||
if (name) {
|
||||
const struct locale *lang = get_locale(name);
|
||||
if (lang && lang != f->locale) {
|
||||
change_locale(f, lang);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ extern "C" {
|
|||
bool long_order_allowed(const struct unit *u);
|
||||
bool password_wellformed(const char *password);
|
||||
|
||||
int locale_cmd(struct unit *u, struct order *ord);
|
||||
int password_cmd(struct unit *u, struct order *ord);
|
||||
int banner_cmd(struct unit *u, struct order *ord);
|
||||
int email_cmd(struct unit *u, struct order *ord);
|
||||
|
|
|
@ -155,5 +155,6 @@ const char *keywords[MAXKEYWORDS] = {
|
|||
"pay",
|
||||
"loot",
|
||||
"autostudy",
|
||||
"locale",
|
||||
};
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ extern "C"
|
|||
K_PAY,
|
||||
K_LOOT,
|
||||
K_AUTOSTUDY,
|
||||
K_LOCALE,
|
||||
MAXKEYWORDS,
|
||||
NOKEYWORD
|
||||
} keyword_t;
|
||||
|
|
Loading…
Reference in a new issue