]> sigrok.org Git - pulseview.git/blobdiff - pv/globalsettings.cpp
Implement translations
[pulseview.git] / pv / globalsettings.cpp
index b648d5da4e6d1fe388eb69052272dd3044edd0ae..1c23e04c39a85929ed17de14d4e23878caeaca58 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "globalsettings.hpp"
+#include "application.hpp"
 
 #include <QApplication>
 #include <QColor>
@@ -42,6 +43,7 @@ const vector< pair<QString, QString> > Themes {
        {"DarkStyle", ":/themes/darkstyle/darkstyle.qss"}
 };
 
+const QString GlobalSettings::Key_General_Language = "General_Language";
 const QString GlobalSettings::Key_General_Theme = "General_Theme";
 const QString GlobalSettings::Key_General_Style = "General_Style";
 const QString GlobalSettings::Key_General_SaveWithSetup = "General_SaveWithSetup";
@@ -68,13 +70,13 @@ const QString GlobalSettings::Key_Log_NotifyOfStacktrace = "Log_NotifyOfStacktra
 
 vector<GlobalSettingsInterface*> GlobalSettings::callbacks_;
 bool GlobalSettings::tracking_ = false;
+bool GlobalSettings::is_dark_theme_ = false;
 map<QString, QVariant> GlobalSettings::tracked_changes_;
 QString GlobalSettings::default_style_;
 QPalette GlobalSettings::default_palette_;
 
 GlobalSettings::GlobalSettings() :
-       QSettings(),
-       is_dark_theme_(false)
+       QSettings()
 {
        beginGroup("Settings");
 }
@@ -90,6 +92,14 @@ void GlobalSettings::save_internal_defaults()
 
 void GlobalSettings::set_defaults_where_needed()
 {
+       if (!contains(Key_General_Language)) {
+               // Determine and set default UI language
+               QString language = QLocale().uiLanguages().first();  // May return e.g. en-Latn-US
+               language = language.split("-").first();
+
+               setValue(Key_General_Language, language);
+       }
+
        // Use no theme by default
        if (!contains(Key_General_Theme))
                setValue(Key_General_Theme, 0);
@@ -130,8 +140,10 @@ void GlobalSettings::set_defaults_where_needed()
        if (!contains(Key_View_SnapDistance))
                setValue(Key_View_SnapDistance, 15);
 
-       if (!contains(Key_Dec_ExportFormat))
-               setValue(Key_Dec_ExportFormat, "%s %d: %c: %1");
+       // %c was used for the row name in the past so we need to transition such users
+       if (!contains(Key_Dec_ExportFormat) ||
+               value(Key_Dec_ExportFormat).toString() == "%s %d: %c: %1")
+               setValue(Key_Dec_ExportFormat, "%s %d: %r: %1");
 
        // Default to 500 lines of backlog
        if (!contains(Key_Log_BufferSize))
@@ -229,6 +241,12 @@ void GlobalSettings::apply_theme()
        QPixmapCache::clear();
 }
 
+void GlobalSettings::apply_language()
+{
+       Application* a = qobject_cast<Application*>(QApplication::instance());
+       a->switch_language(value(Key_General_Language).toString());
+}
+
 void GlobalSettings::add_change_handler(GlobalSettingsInterface *cb)
 {
        callbacks_.push_back(cb);