aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/builtins.cpp29
-rw-r--r--src/builtins.h3
-rw-r--r--src/main.cpp31
-rw-r--r--src/mainwindow/menubar.h2
4 files changed, 34 insertions, 31 deletions
diff --git a/src/builtins.cpp b/src/builtins.cpp
index 242a09f..8cfdb46 100644
--- a/src/builtins.cpp
+++ b/src/builtins.cpp
@@ -10,17 +10,22 @@
#include <QObject>
#include <QVersionNumber>
#include <iostream>
-#include <version.h>
+#include "version.h"
+#include <QTranslator>
-inline std::string tr(const char *text)
+inline const char* tr(const QTranslator *translator, const char *text)
{
- return QObject::tr(text).toStdString();
+ const auto t = translator->translate("builtins", text);
+ if(t.isEmpty())
+ return text;
+ else
+ return qUtf8Printable(t);
}
int builtins::version()
{
const auto version = QVersionNumber::fromString(QLatin1String(poi_Version)).toString().toStdString();
- std::cout << tr("smolbote ") << version << std::endl;
+ std::cout << "smolbote " << version << std::endl;
return 0;
}
@@ -33,24 +38,24 @@ int builtins::build()
int builtins::help(const char *cmd,
boost::program_options::options_description cmd_opts,
boost::program_options::options_description config_opts,
- CommandHash_t pluginCommands)
+ CommandHash_t pluginCommands, const QTranslator *translator)
{
const auto version = QVersionNumber::fromString(QLatin1String(poi_Version)).toString().toStdString();
- std::cout << tr("smolbote ") << version << tr(": yet another no-frills browser\n");
- std::cout << tr("Usage: ") << cmd << tr(" [options] [command/URL(s)]\n\n");
+ std::cout << tr(translator, "smolbote ") << version << tr(translator, ": yet another no-frills browser\n");
+ std::cout << tr(translator, "Usage: ") << cmd << tr(translator, " [options] [command/URL(s)]\n\n");
- std::cout << tr("Command-line Options:\n") << cmd_opts << '\n';
+ std::cout << tr(translator, "Command-line Options:\n") << cmd_opts << '\n';
- std::cout << tr("Commands: \n");
+ std::cout << tr(translator, "Commands: \n");
for(auto it = pluginCommands.constBegin(); it != pluginCommands.constEnd(); ++it)
std::cout << " " << it.key().toStdString() << '\n';
std::cout << '\n';
- std::cout << tr("Configuration Options:\n") << config_opts << '\n';
+ std::cout << tr(translator, "Configuration Options:\n") << config_opts << '\n';
#ifdef Q_OS_UNIX
- std::cout << tr("For more information on usage, refer to the manual page smolbote.7\n");
- std::cout << tr("For more information on configuration, refer to the manual page smolbote.5\n");
+ std::cout << tr(translator, "For more information on usage, refer to the manual page smolbote.7\n");
+ std::cout << tr(translator, "For more information on configuration, refer to the manual page smolbote.5\n");
#endif
std::cout << std::endl;
diff --git a/src/builtins.h b/src/builtins.h
index 6c7153c..7ad8ba5 100644
--- a/src/builtins.h
+++ b/src/builtins.h
@@ -19,7 +19,8 @@ int build();
int help(const char *cmd,
boost::program_options::options_description cmd_opts,
boost::program_options::options_description config_opts,
- CommandHash_t pluginCommands);
+ CommandHash_t pluginCommands,
+ const QTranslator *translator);
}
#endif
diff --git a/src/main.cpp b/src/main.cpp
index d9e1c6a..04ce57a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -65,6 +65,10 @@ int main(int argc, char **argv)
// create and load configuration
std::unique_ptr<Configuration> config = std::make_unique<Configuration>(argc, argv, cmd->value<std::string>("config").value());
+ QTranslator translator;
+ if(config->exists("browser.translation")) {
+ translator.load(config->value<QString>("browser.translation").value());
+ }
QVector<QPluginLoader *> plugins;
CommandHash_t pluginCommands;
@@ -88,13 +92,21 @@ int main(int argc, char **argv)
}
if(cmd->exists("help")) {
- return builtins::help(argv[0], cmd->description(), config->description(), pluginCommands);
+ return builtins::help(argv[0], cmd->description(), config->description(), pluginCommands, &translator);
}
// argc, argv, allowSecondary
Browser app(argc, argv);
// set this, otherwise the webview becomes black when using a stylesheet
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
+ app.installTranslator(&translator);
+ if(config->exists("browser.locale")) {
+ auto *locale = new QTranslator(&app);
+ if(locale->load("qt_" + config->value<QString>("browser.locale").value(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+ app.installTranslator(locale);
+ else
+ delete locale;
+ }
#ifdef CONFIG_USEBREAKPAD
const std::string crashpath = config->value<std::string>("browser.crash.path").value_or("/tmp");
@@ -119,23 +131,6 @@ int main(int argc, char **argv)
#endif
#endif // CONFIG_USEBREAKPAD
- // translator
- if(config->exists("browser.locale")) {
- auto *translator = new QTranslator(&app);
- if(translator->load("qt_" + config->value<QString>("browser.locale").value(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
- app.installTranslator(translator);
- else
- delete translator;
- }
-
- if(config->exists("browser.translation")) {
- auto *translator = new QTranslator(&app);
- if(translator->load(config->value<QString>("browser.translation").value()))
- app.installTranslator(translator);
- else
- delete translator;
- }
-
const bool isStandalone = cmd->exists("no-remote");
const auto profile = config->value<QString>("profile.default");
diff --git a/src/mainwindow/menubar.h b/src/mainwindow/menubar.h
index 38b1286..7b592dd 100644
--- a/src/mainwindow/menubar.h
+++ b/src/mainwindow/menubar.h
@@ -15,6 +15,8 @@ class Configuration;
class MainWindow;
class MenuBar : public QMenuBar
{
+ Q_OBJECT
+
public:
MenuBar(const Configuration *config, MainWindow *parent = nullptr);