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