Skip to content

Commit 67ff7fb

Browse files
committed
feat: Change language setting
1 parent d707a11 commit 67ff7fb

16 files changed

Lines changed: 221 additions & 60 deletions

File tree

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
with:
4848
pkgs: libnick
4949
triplet: ${{ matrix.variant.triplet }}
50-
revision: 3c81ed09705008f13bf76f39853507bef51f71a1
50+
revision: e50305684899fdaa0e594679bc533effea0829cc
5151
token: ${{ github.token }}
5252
cache-key: ${{ matrix.variant.triplet }}
5353
- name: "Build (Installer)"

flatpak/org.nickvision.application.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
{
115115
"type": "git",
116116
"url": "https://github.com/nickvisionapps/libnick",
117-
"tag": "2025.7.1"
117+
"tag": "2025.7.3"
118118
}
119119
]
120120
},

libapplication/include/controllers/preferencesviewcontroller.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ namespace Nickvision::Application::Shared::Controllers
2727
* @param theme The new preferred theme
2828
*/
2929
void setTheme(Models::Theme theme);
30+
/**
31+
* @brief Gets the available translation languages for the application.
32+
* @return The list of available translation languages
33+
*/
34+
const std::vector<std::string>& getAvailableTranslationLanguages() const;
35+
/**
36+
* @brief Gets the preferred translation language for the application.
37+
* @return The preferred translation language
38+
*/
39+
std::string getTranslationLanguage() const;
40+
/**
41+
* @brief Sets the preferred translation language for the application.
42+
* @param language The new preferred translation language
43+
*/
44+
void setTranslationLanguage(const std::string& language);
45+
/**
46+
* @brief Sets the preferred translation language for the application.
47+
* @param index The index of the preferred translation language in the available languages list
48+
*/
49+
void setTranslationLanguage(size_t index);
3050
/**
3151
* @brief Gets whether or not to automatically check for application updates.
3252
* @return True to automatically check for updates, else false
@@ -44,6 +64,7 @@ namespace Nickvision::Application::Shared::Controllers
4464

4565
private:
4666
Models::Configuration& m_configuration;
67+
std::vector<std::string> m_availableTranslationLanguages;
4768
};
4869
}
4970

libapplication/include/models/configuration.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ namespace Nickvision::Application::Shared::Models
3131
* @param theme The new preferred theme
3232
*/
3333
void setTheme(Theme theme);
34+
/**
35+
* @brief Gets the preferred translation language for the application.
36+
* @return The preferred translation language
37+
* @return An empty string to use the system language
38+
* @return "C" to not use translations
39+
*/
40+
std::string getTranslationLanguage() const;
41+
/**
42+
* @brief Sets the preferred translation language for the application.
43+
* @param language The new preferred translation language
44+
*/
45+
void setTranslationLanguage(const std::string& language);
3446
/**
3547
* @brief Gets the window geometry for the application.
3648
* @return The window geometry

libapplication/src/controllers/mainwindowcontroller.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
#include <libnick/system/environment.h>
1010
#include "models/configuration.h"
1111

12+
#define CONFIG_FILE_KEY "config"
13+
1214
using namespace Nickvision::App;
1315
using namespace Nickvision::Application::Shared::Models;
1416
using namespace Nickvision::Events;
1517
using namespace Nickvision::Filesystem;
18+
using namespace Nickvision::Localization;
1619
using namespace Nickvision::Notifications;
1720
using namespace Nickvision::System;
1821
using namespace Nickvision::Update;
@@ -44,15 +47,20 @@ namespace Nickvision::Application::Shared::Controllers
4447
m_appInfo.getDesigners()["DaPigGuy"] = "https://github.com/DaPigGuy";
4548
m_appInfo.getArtists()[_("David Lapshin")] = "https://github.com/daudix";
4649
m_appInfo.setTranslatorCredits(_("translator-credits"));
47-
Localization::Gettext::init(m_appInfo.getEnglishShortName());
50+
Gettext::init(m_appInfo.getEnglishShortName());
51+
std::string translationLanguage{ m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY).getTranslationLanguage() };
52+
if(!translationLanguage.empty())
53+
{
54+
Gettext::changeLanguage(translationLanguage);
55+
}
4856
#ifdef _WIN32
4957
m_updater = std::make_shared<Updater>(m_appInfo.getSourceRepo());
5058
#endif
5159
}
5260

5361
Event<EventArgs>& MainWindowController::configurationSaved()
5462
{
55-
return m_dataFileManager.get<Configuration>("config").saved();
63+
return m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY).saved();
5664
}
5765

5866
Event<NotificationSentEventArgs>& MainWindowController::notificationSent()
@@ -67,7 +75,7 @@ namespace Nickvision::Application::Shared::Controllers
6775

6876
Theme MainWindowController::getTheme()
6977
{
70-
return m_dataFileManager.get<Configuration>("config").getTheme();
78+
return m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY).getTheme();
7179
}
7280

7381
std::string MainWindowController::getDebugInformation(const std::string& extraInformation) const
@@ -91,7 +99,7 @@ namespace Nickvision::Application::Shared::Controllers
9199

92100
std::shared_ptr<PreferencesViewController> MainWindowController::createPreferencesViewController()
93101
{
94-
return std::make_shared<PreferencesViewController>(m_dataFileManager.get<Configuration>("config"));
102+
return std::make_shared<PreferencesViewController>(m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY));
95103
}
96104

97105
#ifdef _WIN32
@@ -108,11 +116,11 @@ namespace Nickvision::Application::Shared::Controllers
108116
return info;
109117
}
110118
//Load configuration
111-
info.setWindowGeometry(m_dataFileManager.get<Configuration>("config").getWindowGeometry());
119+
info.setWindowGeometry(m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY).getWindowGeometry());
112120
//Load taskbar item
113121
#ifdef _WIN32
114122
m_taskbar.connect(hwnd);
115-
if (m_dataFileManager.get<Configuration>("config").getAutomaticallyCheckForUpdates())
123+
if (m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY).getAutomaticallyCheckForUpdates())
116124
{
117125
checkForUpdates(false);
118126
}
@@ -125,7 +133,7 @@ namespace Nickvision::Application::Shared::Controllers
125133

126134
void MainWindowController::shutdown(const WindowGeometry& geometry)
127135
{
128-
Configuration& config{ m_dataFileManager.get<Configuration>("config") };
136+
Configuration& config{ m_dataFileManager.get<Configuration>(CONFIG_FILE_KEY) };
129137
config.setWindowGeometry(geometry);
130138
config.save();
131139
}

libapplication/src/controllers/preferencesviewcontroller.cpp

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#include "controllers/preferencesviewcontroller.h"
2+
#include <libnick/localization/gettext.h>
23

34
using namespace Nickvision::Application::Shared::Models;
5+
using namespace Nickvision::Localization;
46

57
namespace Nickvision::Application::Shared::Controllers
68
{
79
PreferencesViewController::PreferencesViewController(Configuration& configuration)
8-
: m_configuration{ configuration }
10+
: m_configuration{ configuration },
11+
m_availableTranslationLanguages{ Gettext::getAvailableLanguages() }
912
{
10-
13+
m_availableTranslationLanguages.insert(m_availableTranslationLanguages.begin(), _("System"));
14+
m_availableTranslationLanguages.insert(m_availableTranslationLanguages.begin(), _("None"));
1115
}
12-
16+
1317
Theme PreferencesViewController::getTheme() const
1418
{
1519
return m_configuration.getTheme();
@@ -20,6 +24,57 @@ namespace Nickvision::Application::Shared::Controllers
2024
m_configuration.setTheme(theme);
2125
}
2226

27+
const std::vector<std::string>& PreferencesViewController::getAvailableTranslationLanguages() const
28+
{
29+
return m_availableTranslationLanguages;
30+
}
31+
32+
std::string PreferencesViewController::getTranslationLanguage() const
33+
{
34+
std::string language{ m_configuration.getTranslationLanguage() };
35+
if(language.empty())
36+
{
37+
return _("System");
38+
}
39+
else if(language == "C")
40+
{
41+
return _("None");
42+
}
43+
return language;
44+
}
45+
46+
void PreferencesViewController::setTranslationLanguage(const std::string& language)
47+
{
48+
if(language == _("System"))
49+
{
50+
m_configuration.setTranslationLanguage("");
51+
}
52+
else if(language == _("None"))
53+
{
54+
m_configuration.setTranslationLanguage("C");
55+
}
56+
else
57+
{
58+
m_configuration.setTranslationLanguage(language);
59+
}
60+
}
61+
62+
void PreferencesViewController::setTranslationLanguage(size_t index)
63+
{
64+
if(index == 1 || index >= m_availableTranslationLanguages.size())
65+
{
66+
m_configuration.setTranslationLanguage("");
67+
}
68+
else if(index == 0)
69+
{
70+
m_configuration.setTranslationLanguage("C");
71+
}
72+
else
73+
{
74+
m_configuration.setTranslationLanguage(m_availableTranslationLanguages[index]);
75+
}
76+
}
77+
2378
bool PreferencesViewController::getAutomaticallyCheckForUpdates() const
2479
{
2580
return m_configuration.getAutomaticallyCheckForUpdates();

libapplication/src/models/configuration.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ namespace Nickvision::Application::Shared::Models
2222
m_json["Theme"] = static_cast<int>(theme);
2323
}
2424

25+
std::string Configuration::getTranslationLanguage() const
26+
{
27+
return m_json["TranslationLanguage"].is_string() ? m_json["TranslationLanguage"].as_string().c_str() : "";
28+
}
29+
30+
void Configuration::setTranslationLanguage(const std::string& language)
31+
{
32+
m_json["TranslationLanguage"] = language;
33+
}
34+
2535
WindowGeometry Configuration::getWindowGeometry() const
2636
{
2737
if(!m_json["WindowGeometry"].is_object())

org.nickvision.application.gnome/blueprints/preferences_dialog.blp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ Adw.PreferencesDialog root {
2222
icon-name: "dark-mode-symbolic";
2323
}
2424
}
25+
26+
Adw.ComboRow languageRow {
27+
title: _("Translation Language");
28+
subtitle: _("An application restart is required for change to take effect");
29+
30+
[prefix]
31+
Gtk.Image {
32+
icon-name: "translate-symbolic";
33+
}
34+
}
2535
}
2636
}
2737
}

org.nickvision.application.gnome/resources/org.nickvision.application.gresource.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
</gresource>
1010
<gresource prefix="/org/nickvision/application/icons/scalable/status/">
1111
<file preprocess="xml-stripblanks">dark-mode-symbolic.svg</file>
12+
<file preprocess="xml-stripblanks">translate-symbolic.svg</file>
1213
</gresource>
1314
</gresources>
Lines changed: 2 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)