forked from github/server
LOCALE command: do not delete orders with incomplete translations
Instead, we let the player fix them from echeck warnings.
This commit is contained in:
parent
7759f7840a
commit
aa28ad323a
|
@ -836,15 +836,15 @@ faction *faction_create(int no)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void change_locale(faction *f, const struct locale *lang) {
|
void change_locale(faction *f, const struct locale *lang, bool del ) {
|
||||||
unit *ux;
|
unit *ux;
|
||||||
for (ux = f->units; ux; ux = ux->nextF) {
|
for (ux = f->units; ux; ux = ux->nextF) {
|
||||||
translate_orders(ux, lang, &ux->orders);
|
translate_orders(ux, lang, &ux->orders, del);
|
||||||
if (ux->old_orders) {
|
if (ux->old_orders) {
|
||||||
translate_orders(ux, lang, &ux->old_orders);
|
translate_orders(ux, lang, &ux->old_orders, del);
|
||||||
}
|
}
|
||||||
if (ux->thisorder) {
|
if (ux->thisorder) {
|
||||||
translate_orders(ux, lang, &ux->thisorder);
|
translate_orders(ux, lang, &ux->thisorder, del);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f->locale = lang;
|
f->locale = lang;
|
||||||
|
|
|
@ -155,7 +155,7 @@ extern "C" {
|
||||||
int count_migrants(const struct faction * f);
|
int count_migrants(const struct faction * f);
|
||||||
int count_maxmigrants(const struct faction * f);
|
int count_maxmigrants(const struct faction * f);
|
||||||
int max_magicians(const struct faction * f);
|
int max_magicians(const struct faction * f);
|
||||||
void change_locale(struct faction *f, const struct locale *lang);
|
void change_locale(struct faction *f, const struct locale *lang, bool del);
|
||||||
|
|
||||||
#define MONSTER_ID 666
|
#define MONSTER_ID 666
|
||||||
struct faction *getfaction(void);
|
struct faction *getfaction(void);
|
||||||
|
|
|
@ -167,7 +167,7 @@ static void test_change_locale(CuTest *tc) {
|
||||||
unit_addorder(u, ord = create_order(K_STUDY, f->locale, skillnames[SK_ENTERTAINMENT]));
|
unit_addorder(u, ord = create_order(K_STUDY, f->locale, skillnames[SK_ENTERTAINMENT]));
|
||||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id);
|
CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id);
|
||||||
|
|
||||||
change_locale(f, lang);
|
change_locale(f, lang, true);
|
||||||
CuAssertPtrEquals(tc, lang, (void *)f->locale);
|
CuAssertPtrEquals(tc, lang, (void *)f->locale);
|
||||||
CuAssertPtrNotNull(tc, u->thisorder);
|
CuAssertPtrNotNull(tc, u->thisorder);
|
||||||
|
|
||||||
|
|
|
@ -1849,46 +1849,58 @@ void unit_convert_race(unit *u, const race *rc, const char *rcname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool translate_order(order *ord, const struct locale *from_lang, const struct locale *to_lang)
|
||||||
|
{
|
||||||
|
(void)to_lang;
|
||||||
|
(void)from_lang;
|
||||||
|
|
||||||
void translate_orders(unit *u, const struct locale *lang, order **list)
|
if (ord->id <= 0) {
|
||||||
|
/* no arguments, no translation needed */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (getkeyword(ord)) {
|
||||||
|
case NOKEYWORD:
|
||||||
|
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 do not use translated strings */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void translate_orders(unit *u, const struct locale *lang, order **list, bool del)
|
||||||
{
|
{
|
||||||
order **po = list;
|
order **po = list;
|
||||||
(void)lang;
|
(void)lang;
|
||||||
while (*po) {
|
while (*po) {
|
||||||
order *ord = *po;
|
order *ord = *po;
|
||||||
if (ord->id <= 0) {
|
if (!translate_order(ord, u->faction->locale, lang)) {
|
||||||
/* we can keep these, they have no problematic arguments */
|
/* we don't know what to do with these, drop or keep them? */
|
||||||
po = &ord->next;
|
if (del) {
|
||||||
continue;
|
if (u->thisorder == ord) {
|
||||||
}
|
u->thisorder = NULL;
|
||||||
switch (getkeyword(ord)) {
|
}
|
||||||
case K_ATTACK:
|
*po = ord->next;
|
||||||
case K_BANNER:
|
ord->next = NULL;
|
||||||
case K_DRIVE:
|
free_order(ord);
|
||||||
case K_FOLLOW:
|
continue;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
po = &ord->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ extern "C" {
|
||||||
bool unit_name_equals_race(const struct unit *u);
|
bool unit_name_equals_race(const struct unit *u);
|
||||||
|
|
||||||
void unit_convert_race(struct unit *u, const struct race *rc, const char *rcname);
|
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);
|
void translate_orders(struct unit *u, const struct locale *lang, struct order **list, bool del);
|
||||||
|
|
||||||
/* getunit results: */
|
/* getunit results: */
|
||||||
#define GET_UNIT 0
|
#define GET_UNIT 0
|
||||||
|
|
|
@ -4225,13 +4225,14 @@ int locale_cmd(unit * u, order * ord)
|
||||||
char token[128];
|
char token[128];
|
||||||
const char * name;
|
const char * name;
|
||||||
faction *f = u->faction;
|
faction *f = u->faction;
|
||||||
|
bool del = config_get_int("translate.delete_orders", 0) != 0;
|
||||||
|
|
||||||
init_order(ord, f->locale);
|
init_order(ord, f->locale);
|
||||||
name = gettoken(token, sizeof(token));
|
name = gettoken(token, sizeof(token));
|
||||||
if (name) {
|
if (name) {
|
||||||
const struct locale *lang = get_locale(name);
|
const struct locale *lang = get_locale(name);
|
||||||
if (lang && lang != f->locale) {
|
if (lang && lang != f->locale) {
|
||||||
change_locale(f, lang);
|
change_locale(f, lang, del);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue