aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-07-01 11:49:53 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-07-01 11:49:53 +0200
commitfdf0e9c28c05a8d497a19414099d74f9a0f5d970 (patch)
tree0723081f717378ba55ebd05dc9ca938833f03b4d
parentAdd browser.session (diff)
downloadsmolbote-fdf0e9c28c05a8d497a19414099d74f9a0f5d970.tar.xz
Add browser.locale and browser.translation
-rw-r--r--doc/Translating.md19
-rw-r--r--lib/configuration/configuration.cpp2
-rw-r--r--src/main.cpp20
3 files changed, 41 insertions, 0 deletions
diff --git a/doc/Translating.md b/doc/Translating.md
new file mode 100644
index 0000000..111ddbc
--- /dev/null
+++ b/doc/Translating.md
@@ -0,0 +1,19 @@
+## Generating translations
+
+~~~sh
+lupdate src/ lib/ -ts lang/<lang-id>.ts
+~~~
+
+## Baking translation
+This generates lang/<lang-id>.qm
+
+~~~sh
+lrelease lang/<land-id>.ts
+~~~
+
+## Using translations
+
+~~~sh
+--browser.locale # set Qt translation; ex. de
+--browser.translation # set translation file; ex. /home/user/.config/smolbote/lang/custom-translate.qm
+~~~
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index b4a3d07..766dfaf 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -60,6 +60,8 @@ Configuration::Configuration(QObject *parent)
configuration_desc.add_options()
("browser.stylesheet", po::value<std::string>())
("browser.session", po::value<std::string>())
+ ("browser.locale", po::value<std::string>())
+ ("browser.translation", po::value<std::string>())
// main window ui
("mainwindow.height", po::value<int>()->default_value(720))
diff --git a/src/main.cpp b/src/main.cpp
index a419775..85bf5f0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,6 +14,8 @@
#include <iostream>
#include "plugin.h"
#include "session.h"
+#include <QTranslator>
+#include <QLibraryInfo>
int main(int argc, char **argv)
{
@@ -83,6 +85,24 @@ int main(int argc, char **argv)
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
app.setConfiguration(config);
+ // 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;
+ }
+
+
app.setup(QString::fromStdString(config->value<std::string>("profile.default").value()));
for(const Plugin &plugin : plugins) {
app.registerPlugin(plugin);