Add menu to select language

This commit is contained in:
dec05eba
2026-01-27 19:39:19 +01:00
parent 29d2e66e28
commit 9b59b57352
11 changed files with 63 additions and 7 deletions

View File

@@ -85,6 +85,7 @@ namespace gsr {
std::string joystick_hotkeys_enable_option = "disable_hotkeys";
std::string tint_color;
std::string notification_speed = "normal";
std::string language;
ConfigHotkey show_hide_hotkey;
};

View File

@@ -117,7 +117,7 @@ namespace gsr {
void recreate_global_hotkeys(const char *hotkey_option);
void update_led_indicator_after_settings_change();
void create_frontpage_ui_components();
void recreate_frontpage_ui_components();
void xi_setup();
void handle_xi_events();
void process_key_bindings(mgl::Event &event);
@@ -286,6 +286,7 @@ namespace gsr {
mgl::Clock cursor_tracker_update_clock;
bool hide_ui = false;
bool reload_ui = false;
double notification_duration_multiplier = 1.0;
ClipboardFile clipboard_file;

View File

@@ -16,6 +16,7 @@ namespace gsr {
class RadioButton;
class Button;
class List;
class ComboBox;
class CustomRendererWidget;
enum ConfigureHotkeyType {
@@ -75,6 +76,7 @@ namespace gsr {
std::unique_ptr<Button> create_exit_program_button();
std::unique_ptr<Button> create_go_back_to_old_ui_button();
std::unique_ptr<List> create_notification_speed();
std::unique_ptr<List> create_language();
std::unique_ptr<Subsection> create_application_options_subsection(ScrollablePage *parent_page);
std::unique_ptr<Subsection> create_application_info_subsection(ScrollablePage *parent_page);
std::unique_ptr<Subsection> create_donate_subsection(ScrollablePage *parent_page);
@@ -112,6 +114,7 @@ namespace gsr {
Button *take_screenshot_window_button_ptr = nullptr;
Button *show_hide_button_ptr = nullptr;
RadioButton *notification_speed_button_ptr = nullptr;
ComboBox *language_combo_box_ptr = nullptr;
ConfigHotkey configure_config_hotkey;
ConfigureHotkeyType configure_hotkey_type = ConfigureHotkeyType::NONE;

View File

@@ -178,6 +178,7 @@ namespace gsr {
{"main.joystick_hotkeys_enable_option", &config.main_config.joystick_hotkeys_enable_option},
{"main.tint_color", &config.main_config.tint_color},
{"main.notification_speed", &config.main_config.notification_speed},
{"main.language", &config.main_config.language},
{"main.show_hide_hotkey", &config.main_config.show_hide_hotkey},
{"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option},

View File

@@ -21,7 +21,6 @@
#include "../include/CursorTracker/CursorTrackerWayland.hpp"
#include <iomanip>
#include <iostream>
#include <string.h>
#include <assert.h>
#include <sys/wait.h>
@@ -853,6 +852,12 @@ namespace gsr {
bool Overlay::draw() {
remove_widgets_to_be_removed();
if(reload_ui) {
reload_ui = false;
if(visible)
recreate_frontpage_ui_components();
}
update_notification_process_status();
process_gsr_output();
update_gsr_process_status();
@@ -1142,7 +1147,7 @@ namespace gsr {
update_compositor_texture(*focused_monitor);
visible = true;
create_frontpage_ui_components();
recreate_frontpage_ui_components();
// The focused application can be an xwayland application but the cursor can hover over a wayland application.
// This is even the case when hovering over the titlebar of the xwayland application.
@@ -1211,7 +1216,7 @@ namespace gsr {
}
}
void Overlay::create_frontpage_ui_components() {
void Overlay::recreate_frontpage_ui_components() {
bg_screenshot_overlay = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height));
top_bar_background = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height*0.06f).floor());
top_bar_text = mgl::Text("GPU Screen Recorder", get_theme().top_bar_font);
@@ -1351,6 +1356,7 @@ namespace gsr {
button->set_bg_hover_color(mgl::Color(0, 0, 0, 255));
button->set_icon(&get_theme().settings_small_texture);
button->on_click = [&]() {
std::string language_before = config.main_config.language;
auto settings_page = std::make_unique<GlobalSettingsPage>(this, &gsr_info, config, &page_stack);
settings_page->on_startup_changed = [&](bool enable, int exit_status) {
@@ -1385,7 +1391,7 @@ namespace gsr {
global_hotkeys_js.reset();
};
settings_page->on_page_closed = [this]() {
settings_page->on_page_closed = [this, language_before]() {
replay_dropdown_button_ptr->set_item_description("start", config.replay_config.start_stop_hotkey.to_string(false, false));
replay_dropdown_button_ptr->set_item_description("save", config.replay_config.save_hotkey.to_string(false, false));
replay_dropdown_button_ptr->set_item_description("save_1_min", config.replay_config.save_1_min_hotkey.to_string(false, false));
@@ -1395,6 +1401,9 @@ namespace gsr {
record_dropdown_button_ptr->set_item_description("pause", config.record_config.pause_unpause_hotkey.to_string(false, false));
stream_dropdown_button_ptr->set_item_description("start", config.streaming_config.start_stop_hotkey.to_string(false, false));
if(config.main_config.language != language_before)
reload_ui = true;
};
page_stack.push(std::move(settings_page));

View File

@@ -68,6 +68,9 @@ namespace gsr {
bool Translation::load_language(const char* lang) {
translations.clear();
if(lang[0] == '\0')
lang = "en";
if (!is_language_supported(lang)) {
fprintf(stderr, "Warning: language '%s' is not supported\n", lang);
return false;

View File

@@ -12,6 +12,7 @@
#include "../../include/gui/Label.hpp"
#include "../../include/gui/Image.hpp"
#include "../../include/gui/RadioButton.hpp"
#include "../../include/gui/ComboBox.hpp"
#include "../../include/gui/LineSeparator.hpp"
#include "../../include/gui/CustomRendererWidget.hpp"
@@ -519,12 +520,37 @@ namespace gsr {
return list;
}
std::unique_ptr<List> GlobalSettingsPage::create_language() {
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
list->add_widget(std::make_unique<Label>(&get_theme().body_font, TR("Language"), get_color_theme().text_color));
auto combo_box = std::make_unique<ComboBox>(&get_theme().body_font);
language_combo_box_ptr = combo_box.get();
combo_box->add_item(TR("System language"), "");
combo_box->add_item("English", "en");
combo_box->add_item("Русский", "ru");
combo_box->add_item("українська", "uk");
combo_box->on_selection_changed = [](const std::string&, const std::string &id) {
Translation::instance().load_language(id.c_str());
return true;
};
list->add_widget(std::move(combo_box));
return list;
}
std::unique_ptr<Subsection> GlobalSettingsPage::create_application_options_subsection(ScrollablePage *parent_page) {
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
List *list_ptr = list.get();
auto subsection = std::make_unique<Subsection>(TR("Application options"), std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
list_ptr->add_widget(create_notification_speed());
{
auto horizontal_list = std::make_unique<List>(List::Orientation::HORIZONTAL);
horizontal_list->set_spacing(0.02f);
horizontal_list->add_widget(create_notification_speed());
horizontal_list->add_widget(create_language());
list_ptr->add_widget(std::move(horizontal_list));
}
list_ptr->add_widget(std::make_unique<LineSeparator>(LineSeparator::Orientation::HORIZONTAL, subsection->get_inner_size().x));
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
@@ -614,6 +640,7 @@ namespace gsr {
enable_joystick_hotkeys_radio_button_ptr->set_selected_item(config.main_config.joystick_hotkeys_enable_option, false, false);
notification_speed_button_ptr->set_selected_item(config.main_config.notification_speed);
language_combo_box_ptr->set_selected_item(config.main_config.language);
load_hotkeys();
}
@@ -644,6 +671,7 @@ namespace gsr {
config.main_config.hotkeys_enable_option = enable_keyboard_hotkeys_radio_button_ptr->get_selected_id();
config.main_config.joystick_hotkeys_enable_option = enable_joystick_hotkeys_radio_button_ptr->get_selected_id();
config.main_config.notification_speed = notification_speed_button_ptr->get_selected_id();
config.main_config.language = language_combo_box_ptr->get_selected_id();
save_config(config);
}

View File

@@ -208,7 +208,8 @@ int main(int argc, char **argv) {
#endif
}
gsr::Translation::instance().init((resources_path + "translations/").c_str(), nullptr);
std::optional<gsr::Config> config = read_config(gsr::SupportedCaptureOptions{});
gsr::Translation::instance().init((resources_path + "translations/").c_str(), config.has_value() ? config.value().main_config.language.c_str() : nullptr);
if(geteuid() == 0) {
fprintf(stderr, "Error: don't run gsr-ui as the root user\n");

View File

@@ -168,6 +168,9 @@ Notification speed=Скорость уведомлений
Normal=Обычная
Fast=Быстрая
Language=Язык
System language=Системный язык
Exit program=Выйти из программы
Go back to the old UI=Вернуться к старому интерфейсу

View File

@@ -179,6 +179,9 @@ Notification speed=
Normal=
Fast=
Language=
System language=
Exit program=
Go back to the old UI=

View File

@@ -168,6 +168,9 @@ Notification speed=Швидкість сповіщень
Normal=Звичайна
Fast=Швидка
Language=Мова
System language=Системна мова
Exit program=Вийти з програми
Go back to the old UI=Повернутися до старого інтерфейсу