Simplify TranslateName a bit using a helper function

develop
Quietust 2012-01-27 21:46:52 -06:00
parent 116e5d60be
commit 34f9d98d45
1 changed files with 22 additions and 38 deletions

@ -81,13 +81,24 @@ bool Translation::copyName(df::language_name * source, df::language_name * targe
return true; return true;
} }
void addNameWord (string &out, const string &word)
{
if (word.empty())
return;
string upper = word;
upper[0] = toupper(upper[0]);
if (out.length() > 0)
out.append(" ");
out.append(upper);
}
string Translation::TranslateName(const df::language_name * name, bool inEnglish) string Translation::TranslateName(const df::language_name * name, bool inEnglish)
{ {
string out; string out;
string word;
string word = name->first_name; if (!name->first_name.empty())
word[0] = toupper(word[0]); addNameWord(out, name->first_name);
out.append(word);
if (!name->nickname.empty()) if (!name->nickname.empty())
{ {
@ -103,9 +114,7 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
case d_init_nickname::CENTRALIZE: case d_init_nickname::CENTRALIZE:
break; break;
} }
if (out.length() > 0) addNameWord(out, word);
out.append(" ");
out.append(word);
} }
if (!inEnglish) if (!inEnglish)
@ -113,40 +122,25 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
if (name->words[0] >= 0 || name->words[1] >= 0) if (name->words[0] >= 0 || name->words[1] >= 0)
{ {
word.clear(); word.clear();
if (name->words[0] >= 0) if (name->words[0] >= 0)
word.append(*world->raws.language.translations[name->language]->words[name->words[0]]); word.append(*world->raws.language.translations[name->language]->words[name->words[0]]);
if (name->words[1] >= 0) if (name->words[1] >= 0)
word.append(*world->raws.language.translations[name->language]->words[name->words[1]]); word.append(*world->raws.language.translations[name->language]->words[name->words[1]]);
addNameWord(out, word);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
} }
if (name->words[5] >= 0) if (name->words[5] >= 0)
{ {
word.clear(); word.clear();
for (int i = 2; i <= 5; i++) for (int i = 2; i <= 5; i++)
if (name->words[i] >= 0) if (name->words[i] >= 0)
word.append(*world->raws.language.translations[name->language]->words[name->words[i]]); word.append(*world->raws.language.translations[name->language]->words[name->words[i]]);
addNameWord(out, word);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
} }
if (name->words[6] >= 0) if (name->words[6] >= 0)
{ {
word.clear(); word.clear();
word.append(*world->raws.language.translations[name->language]->words[name->words[6]]); word.append(*world->raws.language.translations[name->language]->words[name->words[6]]);
addNameWord(out, word);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
} }
} }
else else
@ -154,16 +148,11 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
if (name->words[0] >= 0 || name->words[1] >= 0) if (name->words[0] >= 0 || name->words[1] >= 0)
{ {
word.clear(); word.clear();
if (name->words[0] >= 0) if (name->words[0] >= 0)
word.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]); word.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]);
if (name->words[1] >= 0) if (name->words[1] >= 0)
word.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]); word.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]);
addNameWord(out, word);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
} }
if (name->words[5] >= 0) if (name->words[5] >= 0)
{ {
@ -171,14 +160,11 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
out.append(" the"); out.append(" the");
else else
out.append("The"); out.append("The");
for (int i = 2; i <= 5; i++) for (int i = 2; i <= 5; i++)
{ {
if (name->words[i] >= 0) if (name->words[i] >= 0)
{ addNameWord(out, world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value]);
word = world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value];
word[0] = toupper(word[0]);
out.append(" " + word);
}
} }
} }
if (name->words[6] >= 0) if (name->words[6] >= 0)
@ -188,9 +174,7 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
else else
out.append("Of"); out.append("Of");
word = world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value]; addNameWord(out, world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value]);
word[0] = toupper(word[0]);
out.append(" " + word);
} }
} }