// SPDX-License-Identifier: MIT #include "main_window.hpp" #include "openpu/storage.hpp" #include #include #include #include #include #include #include namespace { /// Translations directory: OPENPU_LOCALEDIR (build tree), else /share/locale next to the /// executable when it exists (relocatable installs such as the AppImage), else the configured one. std::string localeDir() { if (const char* dir = std::getenv("OPENPU_LOCALEDIR")) // NOLINT(concurrency-mt-unsafe): no thread yet return dir; std::error_code ec; const auto exe = std::filesystem::read_symlink("/proc/self/exe", ec); if (!ec) { const auto dir = exe.parent_path().parent_path() / "share" / "locale"; if (std::filesystem::is_directory(dir, ec)) return dir.string(); } return OPENPU_LOCALEDIR; } } // namespace int main(int argc, char* argv[]) { // A language chosen in the settings overrides the session language (gettext reads LANGUAGE). try { const auto settings = openpu::Settings::load(openpu::paths::configDir() / "config.json"); if (!settings.language.empty()) (void)setenv("LANGUAGE", settings.language.c_str(), 1); // NOLINT(concurrency-mt-unsafe): no thread yet } catch (const openpu::StorageError&) { // dismissed: the window reports unreadable settings itself } (void)std::setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe): no thread yet bindtextdomain(GETTEXT_PACKAGE, localeDir().c_str()); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); auto app = Gtk::Application::create("io.github.openpu.OpenPU"); return app->make_window_and_run(argc, argv); }