Skip to content

Commit

Permalink
UI: Workaround for mixed locales
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed May 6, 2024
1 parent b0531de commit 1718d9a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Source/Game/GameContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,12 @@ void loadAddonET(ModMetadata& mod) {
}
} else {
//This is a reworked ET

paths["Resource/Models"] = {};
}

//Load texts, first try current lang, then english, then russian
std::string locale = getLocale();
std::string locpath = getLocDataPath();
const std::string& locale = getLocale();
const std::string& locpath = getLocDataPath();
std::vector<std::string> lang_paths;
lang_paths.emplace_back(locpath);
lang_paths.emplace_back("Resource/LocData/English/");
Expand Down
2 changes: 1 addition & 1 deletion Source/Render/src/VisGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ cFont* cVisGeneric::CreateGameFont(const char* TextureFileName, int height, bool
if(TextureFileName==nullptr||TextureFileName[0]==0) return nullptr;

if (locale.empty()) {
locale = getLocale();
locale = getDefaultFontLocale();
}

std::vector<cFontInternal*>::iterator it;
Expand Down
23 changes: 23 additions & 0 deletions Source/Util/Localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

bool isLocaleInit = false;
std::string localeCurrent;
std::string localeDefaultFont;
std::string localePath;
std::vector<std::string> localesAvailable;

Expand Down Expand Up @@ -117,6 +118,17 @@ void initLocale() {
fprintf(stdout, "Current locale path: %s\n", localePath.c_str());
}

//TODO workaround to fix multiplayer games with mixed russian locale and non russian locale players
localeDefaultFont.clear();
if (localeCurrent == "english") {
for (auto& locale : localesAvailable) {
if (stricmp(locale.c_str(), "russian") == 0) {
localeDefaultFont = "russian";
break;
}
}
}

isLocaleInit = true;
}

Expand All @@ -127,6 +139,17 @@ const std::string& getLocale() {
return localeCurrent;
}

const std::string& getDefaultFontLocale() {
if (!isLocaleInit) {
initLocale();
}
if (localeDefaultFont.empty()) {
return localeCurrent;
} else {
return localeDefaultFont;
}
}

const std::vector<std::string>& getLocales() {
if (!isLocaleInit) {
initLocale();
Expand Down
1 change: 1 addition & 0 deletions Source/Util/Localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct LocalizedText {

void initLocale();
const std::string& getLocale();
const std::string& getDefaultFontLocale();
const std::vector<std::string>& getLocales();
const char* getLocRootPath();
const std::string& getLocDataPath();
Expand Down

0 comments on commit 1718d9a

Please sign in to comment.