Skip to content

Commit

Permalink
Merge pull request #11332 from AreaScout/master
Browse files Browse the repository at this point in the history
Add: Get user-preferred locale from OS (linux only)
  • Loading branch information
hrydgard committed Sep 2, 2018
2 parents caaec8c + c6c66e7 commit d23d58c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion SDL/SDLMain.cpp
Expand Up @@ -19,6 +19,7 @@ SDLJoystick *joystick = NULL;
#include <cassert>
#include <cmath>
#include <thread>
#include <locale>

#include "base/display.h"
#include "base/logging.h"
Expand Down Expand Up @@ -187,8 +188,23 @@ std::string System_GetProperty(SystemProperty prop) {
#else
return "SDL:";
#endif
case SYSPROP_LANGREGION:
case SYSPROP_LANGREGION: {
// Get user-preferred locale from OS
setlocale(LC_ALL, "");
std::string locale(setlocale(LC_ALL, NULL));
// Set c and c++ strings back to POSIX
std::locale::global(std::locale("POSIX"));
if (!locale.empty()) {
if (locale.find("_", 0) != std::string::npos) {
if (locale.find(".", 0) != std::string::npos) {
return locale.substr(0, locale.find(".",0));
} else {
return locale;
}
}
}
return "en_US";
}
default:
return "";
}
Expand Down

0 comments on commit d23d58c

Please sign in to comment.