[linux] updatesvc: add app lang detection

This commit is contained in:
SimplestStudio
2024-02-12 19:53:57 +02:00
parent db2b5a98ce
commit 0aacaea99f
3 changed files with 22 additions and 2 deletions

View File

@ -57,7 +57,7 @@ int main(int argc, char *argv[])
if (argc > 1) {
if (strcmp(argv[1], "--run-as-app") == 0) {
std::locale::global(std::locale(""));
Translator lang(NS_Utils::GetSysLanguage(), "/langs/langs.iss");
Translator lang(NS_Utils::GetAppLanguage(), "/langs/langs.iss");
CSocket socket(0, INSTANCE_SVC_PORT);
if (!socket.isPrimaryInstance())
return 0;

View File

@ -33,12 +33,15 @@
#include "platform_linux/utils.h"
#include "version.h"
#include <fstream>
#include <regex>
#include <algorithm>
#include <sys/stat.h>
#include <gtk/gtk.h>
//#include <openssl/md5.h>
#include <fcntl.h>
#include "../../src/defines.h"
#include "../../src/prop/defines_p.h"
#define APP_CONFIG_PATH "/.config/" REG_GROUP_KEY "/" REG_APP_NAME ".conf"
//#define BUFSIZE 1024
@ -151,6 +154,22 @@ namespace NS_Utils
}
return (pos == std::string::npos) ? lang : lang.substr(0, pos);
}
string GetAppLanguage()
{
string lang = "en_US", value = "locale=", path = string("/home/") + getlogin() + APP_CONFIG_PATH;
list<string> lst;
NS_File::readFile(path, lst);
for (const auto &str : lst) {
size_t pos = str.find(value);
if (pos != string::npos) {
lang = str.substr(pos + value.length());
std::replace(lang.begin(), lang.end(), '-', '_');
return lang;
}
}
return lang;
}
}
namespace NS_File

View File

@ -53,6 +53,7 @@ namespace NS_Utils
string GetLastErrorAsString();
int ShowMessage(string str, bool showError = false);
string GetSysLanguage();
string GetAppLanguage();
}
namespace NS_File