MacOS 获取系统语言
std::string GetLocaleLanguage()
{
std::string lpath = GetManagerDataPath() + "lang.txt";
std::string cmd = R"(defaults read .GlobalPreferences AppleLanguages | tr -d ["()\""][:space:] > )";
cmd += lpath;
system(cmd.c_str());
std::string _language = "English";
FILE * fp = fopen(lpath.c_str(), "r");
LOG_STREAM_MESSAGE << "open:" << lpath;
char buf[10] = { 0 };
if (fp)
{
if (fgets(buf, sizeof buf, fp))
{
LOG_STREAM_MESSAGE << "language file:" << buf;
int ret = strncmp(buf, "zh-Han", std::min<size_t>(strlen(buf), strlen("zh-Han")));
if (ret == 0)
{
_language = "Chinese";
}
}
fclose(fp);
}
else
{
LOG_STREAM_MESSAGE << "fp == null! " << lpath << " not Found";
}
remove(lpath.c_str());
return _language;
}