From 3b229a8275fe73beb7b30ddd2d9eaa95421ef476 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 24 Oct 2021 15:54:01 +0200 Subject: [PATCH] Check for translation in the same place as they are loaded from --- Source/diablo.cpp | 2 -- Source/utils/language.cpp | 13 ++++++++----- Source/utils/paths.cpp | 18 ------------------ Source/utils/paths.h | 2 -- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index e82b4046a..c6f3c3640 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -832,8 +832,6 @@ void DiabloParseFlags(int argc, char **argv) recordNumber = SDL_atoi(argv[++i]); } else if (strcasecmp("--config-dir", argv[i]) == 0) { paths::SetConfigPath(argv[++i]); - } else if (strcasecmp("--lang-dir", argv[i]) == 0) { - paths::SetLangPath(argv[++i]); } else if (strcasecmp("-n", argv[i]) == 0) { gbShowIntro = false; } else if (strcasecmp("-f", argv[i]) == 0) { diff --git a/Source/utils/language.cpp b/Source/utils/language.cpp index 476132d0b..421c0022e 100644 --- a/Source/utils/language.cpp +++ b/Source/utils/language.cpp @@ -256,12 +256,15 @@ const std::string &LanguageTranslate(const char *key) bool HasTranslation(const std::string &locale) { - std::string moPath = paths::LangPath() + locale + ".mo"; - if (FileExists(moPath.c_str())) - return true; + for (const char *ext : { ".mo", ".gmo" }) { + SDL_RWops *rw = SFileOpenRw((locale + ext).c_str()); + if (rw != nullptr) { + SDL_RWclose(rw); + return true; + } + } - std::string gmoPath = paths::LangPath() + locale + ".gmo"; - return FileExists(gmoPath.c_str()); + return false; } void LanguageInitialize() diff --git a/Source/utils/paths.cpp b/Source/utils/paths.cpp index 382ec1e8a..9874ee5bf 100644 --- a/Source/utils/paths.cpp +++ b/Source/utils/paths.cpp @@ -11,10 +11,6 @@ #include "utils/sdl2_to_1_2_backports.h" #endif -#ifndef MO_LANG_DIR -#define MO_LANG_DIR "" -#endif - namespace devilution { namespace paths { @@ -25,7 +21,6 @@ std::optional appPath; std::optional basePath; std::optional prefPath; std::optional configPath; -std::optional langPath; void AddTrailingSlash(std::string &path) { @@ -89,13 +84,6 @@ const std::string &ConfigPath() return *configPath; } -const std::string &LangPath() -{ - if (!langPath) - langPath.emplace(MO_LANG_DIR); - return *langPath; -} - void SetBasePath(const std::string &path) { basePath = path; @@ -114,12 +102,6 @@ void SetConfigPath(const std::string &path) AddTrailingSlash(*configPath); } -void SetLangPath(const std::string &path) -{ - langPath = path; - AddTrailingSlash(*langPath); -} - } // namespace paths } // namespace devilution diff --git a/Source/utils/paths.h b/Source/utils/paths.h index c1444ffb6..071096fc8 100644 --- a/Source/utils/paths.h +++ b/Source/utils/paths.h @@ -10,12 +10,10 @@ const std::string &AppPath(); const std::string &BasePath(); const std::string &PrefPath(); const std::string &ConfigPath(); -const std::string &LangPath(); void SetBasePath(const std::string &path); void SetPrefPath(const std::string &path); void SetConfigPath(const std::string &path); -void SetLangPath(const std::string &path); } // namespace paths