Skip to content

Commit

Permalink
Initial work on Japanese localisations (#1551)
Browse files Browse the repository at this point in the history
* Add code support for japanese localisations, which are taken from the English ones.

* Monarch names

* Dynasties

* Japanese monarch descriptions

* Fix focus localisations for non-english languages (copy from english)

* Copy most events from English to unhandled languages

* Copy english for all unhandled election events

* Political parties from english
  • Loading branch information
Idhrendur authored Oct 8, 2022
1 parent bf97ab9 commit 920cf3e
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/HOI4World/HoI4Country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ void HoI4::Country::convertMonarchIdea(const Mappers::GraphicsMapper& graphicsMa
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", "Król " + *firstName + " " + *surname, "polish");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", "Король " + *firstName + " " + *surname, "russian");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", "Rey " + *firstName + " " + *surname, "spanish");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", *firstName + " " + *surname + "", "japanese");
}
else
{
Expand All @@ -613,6 +614,7 @@ void HoI4::Country::convertMonarchIdea(const Mappers::GraphicsMapper& graphicsMa
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", "Królowa " + *firstName + " " + *surname, "polish");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", "Королева " + *firstName + " " + *surname, "russian");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", "Reina " + *firstName + " " + *surname, "spanish");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch", *firstName + " " + *surname + "女王", "japanese");
}

if (!female)
Expand Down Expand Up @@ -645,6 +647,10 @@ void HoI4::Country::convertMonarchIdea(const Mappers::GraphicsMapper& graphicsMa
"Reunida en torno al Rey de [" + tag + ".GetName] y las tierras [" + tag + ".GetAdjective]s, la nación [" +
tag + ".GetAdjective] está unida y orgullosa de su legado imperial.",
"spanish");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch_desc",
"[" + tag + ".GetName]の国王と[" + tag + ".GetAdjective]の領土の周りに結集し、[" + tag +
".GetAdjective]人は団結し、帝国の遺産を誇りに思っています",
"japanese");
}
else
{
Expand Down Expand Up @@ -676,6 +682,10 @@ void HoI4::Country::convertMonarchIdea(const Mappers::GraphicsMapper& graphicsMa
"Reunida en torno a la Reina de [" + tag + ".GetName] y las tierras [" + tag +
".GetAdjective]s, la nación [" + tag + ".GetAdjective] está unida y orgullosa de su legado imperial.",
"spanish");
hoi4Localisations.addIdeaLocalisation(tag + "_monarch_desc",
"[" + tag + ".GetName]の女王と[" + tag + ".GetAdjective]の領土の周りに結集し、[" + tag +
".GetAdjective]人は団結し、帝国の遺産を誇りに思っています",
"japanese");
}

if (!female)
Expand Down
160 changes: 159 additions & 1 deletion src/HOI4World/HoI4Localisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,29 @@
#include <ranges>


// watch for getTextInEachLanguage



namespace
{


const std::set<std::string> supported_languages = {"braz_por",
"czech",
"dutch",
"english",
"finnish",
"french",
"german",
"hungarian",
"italian",
"japanese",
"polish",
"russian",
"spanish",
"swedish"};

void importLocalisationFile(const std::string& filename, HoI4::languageToLocalisationsMap& localisations)
{
HoI4::keyToLocalisationMap newLocalisations;
Expand Down Expand Up @@ -60,7 +79,10 @@ void importLocalisationFile(const std::string& filename, HoI4::languageToLocalis
auto [iterator, success] = localisations.emplace(language, newLocalisations);
if (!success)
{
iterator->second = newLocalisations;
for (const auto& [key, new_localization]: newLocalisations)
{
iterator->second[key] = new_localization;
}
}

file.close();
Expand Down Expand Up @@ -750,11 +772,13 @@ void HoI4::Localisation::addNonenglishCountryLocalisations()
countryLocalisations.insert(make_pair("braz_por", englishLocalisations->second));
countryLocalisations.insert(make_pair("polish", englishLocalisations->second));
countryLocalisations.insert(make_pair("russian", englishLocalisations->second));
countryLocalisations.insert(make_pair("japanese", englishLocalisations->second));
}


void HoI4::Localisation::copyFocusLocalisations(const std::string& oldKey, const std::string& newKey)
{
std::set<std::string> handled_languages;
for (const auto& [language, localisations]: originalFocuses)
{
auto newLanguage = newFocuses.find(language);
Expand All @@ -768,6 +792,7 @@ void HoI4::Localisation::copyFocusLocalisations(const std::string& oldKey, const
if (auto oldLocalisation = localisations.find(oldKey); oldLocalisation != localisations.end())
{
newLanguage->second[newKey] = oldLocalisation->second;
handled_languages.insert(language);
}
else
{
Expand All @@ -780,11 +805,48 @@ void HoI4::Localisation::copyFocusLocalisations(const std::string& oldKey, const
newLanguage->second[newKey + "_desc"] = oldLocalisationDescription->second;
}
}

for (const auto& language: supported_languages)
{
if (handled_languages.contains(language))
{
continue;
}

const auto english_localisations = newFocuses.find("english");
if (english_localisations == newFocuses.end())
{
break;
}

const auto english_localisation = english_localisations->second.find(newKey);
if (english_localisation == english_localisations->second.end())
{
continue;
}

auto unhandled_language = newFocuses.find(language);
if (unhandled_language == newFocuses.end())
{
keyToLocalisationMap new_localisations;
newFocuses.insert(make_pair(language, new_localisations));
unhandled_language = newFocuses.find(language);
}
unhandled_language->second[newKey] = english_localisation->second;

const auto english_description = english_localisations->second.find(newKey + "_desc");
if (english_description == english_localisations->second.end())
{
continue;
}
unhandled_language->second[newKey + "_desc"] = english_description->second;
}
}


void HoI4::Localisation::copyEventLocalisations(const std::string& oldKey, const std::string& newKey)
{
std::set<std::string> handled_languages;
for (const auto& [language, localisations]: originalEventLocalisations)
{
auto newLanguage = newEventLocalisations.find(language);
Expand All @@ -798,12 +860,42 @@ void HoI4::Localisation::copyEventLocalisations(const std::string& oldKey, const
if (const auto& oldLocalisation = localisations.find(oldKey); oldLocalisation != localisations.end())
{
newLanguage->second[newKey] = oldLocalisation->second;
handled_languages.insert(language);
}
else
{
Log(LogLevel::Warning) << "Could not find original localisation for " << oldKey << " in " << language;
}
}

for (const auto& language: supported_languages)
{
if (handled_languages.contains(language))
{
continue;
}

const auto english_localisations = newEventLocalisations.find("english");
if (english_localisations == newEventLocalisations.end())
{
break;
}

const auto english_localisation = english_localisations->second.find(newKey);
if (english_localisation == english_localisations->second.end())
{
continue;
}

auto unhandled_language = newEventLocalisations.find(language);
if (unhandled_language == newEventLocalisations.end())
{
keyToLocalisationMap new_localisations;
newEventLocalisations.insert(make_pair(language, new_localisations));
unhandled_language = newEventLocalisations.find(language);
}
unhandled_language->second[newKey] = english_localisation->second;
}
}


Expand Down Expand Up @@ -1170,6 +1262,7 @@ void HoI4::Localisation::addNonenglishStateLocalisations()
stateLocalisations.insert(make_pair("braz_por", englishLocalisations));
stateLocalisations.insert(make_pair("polish", englishLocalisations));
stateLocalisations.insert(make_pair("russian", englishLocalisations));
stateLocalisations.insert(make_pair("japanese", englishLocalisations));
}


Expand All @@ -1179,6 +1272,7 @@ void HoI4::Localisation::addNonenglishVPLocalisations()
VPLocalisations.insert(make_pair("braz_por", englishLocalisations));
VPLocalisations.insert(make_pair("polish", englishLocalisations));
VPLocalisations.insert(make_pair("russian", englishLocalisations));
VPLocalisations.insert(make_pair("japanese", englishLocalisations));
}


Expand All @@ -1195,6 +1289,7 @@ void HoI4::Localisation::addEventLocalisationFromVic2(const std::string& Vic2Key
const std::string& HoI4Key,
const Vic2::Localisations& vic2Localisations)
{
std::set<std::string> handled_languages;
for (const auto& [language, text]: vic2Localisations.getTextInEachLanguage(Vic2Key))
{
auto existingLanguage = newEventLocalisations.find(language);
Expand All @@ -1206,6 +1301,36 @@ void HoI4::Localisation::addEventLocalisationFromVic2(const std::string& Vic2Key
}

existingLanguage->second[HoI4Key] = text;
handled_languages.insert(language);
}

for (const auto& language: supported_languages)
{
if (handled_languages.contains(language))
{
continue;
}

const auto english_localisations = newEventLocalisations.find("english");
if (english_localisations == newEventLocalisations.end())
{
break;
}

const auto english_localisation = english_localisations->second.find(HoI4Key);
if (english_localisation == english_localisations->second.end())
{
continue;
}

auto unhandled_language = newEventLocalisations.find(language);
if (unhandled_language == newEventLocalisations.end())
{
keyToLocalisationMap new_localisations;
newEventLocalisations.insert(make_pair(language, new_localisations));
unhandled_language = newEventLocalisations.find(language);
}
unhandled_language->second[HoI4Key] = english_localisation->second;
}
}

Expand Down Expand Up @@ -1262,6 +1387,7 @@ void HoI4::Localisation::addPoliticalPartyLocalisation(const std::string& Vic2Ke
const std::string& HoI4Key,
const Vic2::Localisations& vic2Localisations)
{
std::set<std::string> handled_languages;
for (const auto& [language, text]: vic2Localisations.getTextInEachLanguage(Vic2Key))
{
auto existingLanguage = politicalPartyLocalisations.find(language);
Expand All @@ -1273,6 +1399,36 @@ void HoI4::Localisation::addPoliticalPartyLocalisation(const std::string& Vic2Ke
}

existingLanguage->second[HoI4Key] = text;
handled_languages.insert(language);
}

for (const auto& language: supported_languages)
{
if (handled_languages.contains(language))
{
continue;
}

const auto english_localisations = politicalPartyLocalisations.find("english");
if (english_localisations == politicalPartyLocalisations.end())
{
break;
}

const auto english_localisation = english_localisations->second.find(HoI4Key);
if (english_localisation == english_localisations->second.end())
{
continue;
}

auto unhandled_language = politicalPartyLocalisations.find(language);
if (unhandled_language == politicalPartyLocalisations.end())
{
keyToLocalisationMap new_localisations;
politicalPartyLocalisations.insert(make_pair(language, new_localisations));
unhandled_language = politicalPartyLocalisations.find(language);
}
unhandled_language->second[HoI4Key] = english_localisation->second;
}
}

Expand All @@ -1287,6 +1443,7 @@ void HoI4::Localisation::addRulingHouseLocalisations(const std::string& rulingPa
politicalPartyLocalisations["polish"][rulingParty] = "Dynastia " + utf8Dynasty + "ów";
politicalPartyLocalisations["russian"][rulingParty] = "Династия " + utf8Dynasty;
politicalPartyLocalisations["spanish"][rulingParty] = "Casa de " + utf8Dynasty;
politicalPartyLocalisations["japanese"][rulingParty] = utf8Dynasty + "";
}


Expand Down Expand Up @@ -1448,4 +1605,5 @@ void HoI4::Localisation::addCharacterLocalisation(const std::string& id, const s
characterLocalisations_["russian"].emplace(id, name);
characterLocalisations_["spanish"].emplace(id, name);
characterLocalisations_["swedish"].emplace(id, name);
characterLocalisations_["japanese"].emplace(id, name);
}

0 comments on commit 920cf3e

Please sign in to comment.