Browse Source

Check for translation in the same place as they are loaded from

pull/3237/head
Anders Jenbo 4 years ago
parent
commit
3b229a8275
  1. 2
      Source/diablo.cpp
  2. 13
      Source/utils/language.cpp
  3. 18
      Source/utils/paths.cpp
  4. 2
      Source/utils/paths.h

2
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) {

13
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()

18
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<std::string> appPath;
std::optional<std::string> basePath;
std::optional<std::string> prefPath;
std::optional<std::string> configPath;
std::optional<std::string> 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

2
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

Loading…
Cancel
Save