75{
76
77 const std::string lang_conf = Glib::get_home_dir() + "/.config/BastionGuard/lang.conf";
78 {
79 std::error_code ec;
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);
84 if (out.is_open()) {
85 out << "LANG=en_US.UTF-8\n";
86 out << "LC_ALL=en_US.UTF-8\n";
87 out << "LANGUAGE=en_US\n";
88 out.close();
89 std::cout << "[Lang] ✅ Creato lang.conf di default: " << lang_conf << std::endl;
90 }
91 }
92 }
93
94 std::ifstream f(lang_conf);
95 if (f.is_open()) {
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);
104 }
105 }
106 f.close();
107 std::cout << "[Lang] Config caricata da " << lang_conf << std::endl;
108 } else {
109 std::cerr << "[Lang] ⚠️ Impossibile aprire lang.conf, forzo inglese di default" << std::endl;
110 }
111
112
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);
116
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);
120
121 const char* language_env = std::getenv("LANGUAGE");
122 if (!language_env || std::string(language_env).empty())
123 setenv("LANGUAGE", "en_US", 1);
124
125
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");
131
132 bindtextdomain(
"BastionGuard",
LOCALEDIR);
133 bind_textdomain_codeset("BastionGuard", "UTF-8");
134 textdomain("BastionGuard");
135
136 auto app = Gtk::Application::create("org.bastionguard.first-run-test");
139}