37 const std::string lang_conf = Glib::get_home_dir() +
"/.config/BastionGuard/lang.conf";
38 std::ifstream f(lang_conf);
45 while (std::getline(f, line)) {
46 if (line.empty() || line[0] ==
'#')
49 auto pos = line.find(
'=');
50 if (pos == std::string::npos)
53 std::string key = line.substr(0, pos);
54 std::string val = line.substr(pos + 1);
56 auto ltrim = [](std::string& s){
57 s.erase(0, s.find_first_not_of(
" \t\r\n"));
59 auto rtrim = [](std::string& s){
60 s.erase(s.find_last_not_of(
" \t\r\n") + 1);
62 ltrim(key); rtrim(key);
63 ltrim(val); rtrim(val);
65 if (!key.empty() && !val.empty()) {
66 setenv(key.c_str(), val.c_str(), 1);
74int main(
int argc,
char* argv[])
77 const std::string lang_conf = Glib::get_home_dir() +
"/.config/BastionGuard/lang.conf";
80 if (!fs::exists(lang_conf, ec) || ec) {
81 std::string cfgdir = Glib::get_home_dir() +
"/.config/BastionGuard";
82 fs::create_directories(cfgdir, ec);
83 std::ofstream out(lang_conf, std::ios::out | std::ios::trunc);
85 out <<
"LANG=en_US.UTF-8\n";
86 out <<
"LC_ALL=en_US.UTF-8\n";
87 out <<
"LANGUAGE=en_US\n";
89 std::cout <<
"[Lang] ✅ Creato lang.conf di default: " << lang_conf << std::endl;
94 std::ifstream f(lang_conf);
97 while (std::getline(f, line)) {
98 auto pos = line.find(
'=');
99 if (pos != std::string::npos) {
100 std::string key = line.substr(0, pos);
101 std::string val = line.substr(pos + 1);
102 if (!key.empty() && !val.empty())
103 setenv(key.c_str(), val.c_str(), 1);
107 std::cout <<
"[Lang] Config caricata da " << lang_conf << std::endl;
109 std::cerr <<
"[Lang] ⚠️ Impossibile aprire lang.conf, forzo inglese di default" << std::endl;
113 const char* lang_env = std::getenv(
"LANG");
114 if (!lang_env || std::string(lang_env).empty())
115 setenv(
"LANG",
"en_US.UTF-8", 1);
117 const char* lc_all_env = std::getenv(
"LC_ALL");
118 if (!lc_all_env || std::string(lc_all_env).empty())
119 setenv(
"LC_ALL",
"en_US.UTF-8", 1);
121 const char* language_env = std::getenv(
"LANGUAGE");
122 if (!language_env || std::string(language_env).empty())
123 setenv(
"LANGUAGE",
"en_US", 1);
126 const char* applied = setlocale(LC_ALL,
"");
127 if (!applied) applied = setlocale(LC_ALL,
"en_US.UTF-8");
128 if (!applied) applied = setlocale(LC_ALL,
"en_US");
129 if (!applied) applied = setlocale(LC_ALL,
"C.UTF-8");
130 if (!applied) applied = setlocale(LC_ALL,
"C");
132 bindtextdomain(
"BastionGuard",
LOCALEDIR);
133 bind_textdomain_codeset(
"BastionGuard",
"UTF-8");
134 textdomain(
"BastionGuard");
136 auto app = Gtk::Application::create(
"org.bastionguard.first-run-test");