Browse Source

Get default langauge

pull/2478/head
Anders Jenbo 5 years ago
parent
commit
5c2a559487
  1. 13
      Source/options.cpp
  2. 13
      Source/utils/language.cpp
  3. 1
      Source/utils/language.h

13
Source/options.cpp

@ -6,6 +6,7 @@
#include <cstdint>
#include <fstream>
#include <locale>
#define SI_SUPPORT_IOSTREAMS
#include <SimpleIni.h>
@ -13,6 +14,7 @@
#include "diablo.h"
#include "options.h"
#include "utils/file_util.h"
#include "utils/language.h"
#include "utils/paths.h"
namespace devilution {
@ -259,7 +261,16 @@ void LoadOptions()
sgOptions.Controller.bRearTouch = GetIniBool("Controller", "Enable Rear Touchpad", true);
#endif
GetIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), "en");
std::string locale = std::locale("").name().substr(0, 5);
SDL_Log("prefered locale %s", locale.c_str());
if (!HasTranslation(locale)) {
locale = locale.substr(0, 2);
if (!HasTranslation(locale)) {
locale = "en";
}
}
GetIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), locale.c_str());
keymapper.Load();

13
Source/utils/language.cpp

@ -235,6 +235,19 @@ const char *LanguageMetadata(const char *key)
return it->second;
}
bool HasTranslation(const std::string &locale)
{
std::string gmoPath = paths::LangPath() + "./" + locale + ".gmo";
if (FileExists(gmoPath.c_str()))
return true;
std::string moPath = paths::LangPath() + "./" + locale + ".mo";
if (FileExists(moPath.c_str()))
return true;
return false;
}
void LanguageInitialize()
{
FILE *fp;

1
Source/utils/language.h

@ -6,6 +6,7 @@
#define ngettext(x, y, z) LanguagePluralTranslate(x, y, z).c_str()
#define N_(x) (x)
bool HasTranslation(const std::string &locale);
void LanguageInitialize();
const std::string &LanguagePluralTranslate(const char *singular, const char *plural, int count);
const std::string &LanguageTranslate(const char *key);

Loading…
Cancel
Save