From 831ab47dc337a46256e279c26b09e334ffeea649 Mon Sep 17 00:00:00 2001 From: Nokse22 <44558032+Nokse22@users.noreply.github.com> Date: Sun, 29 Sep 2024 16:15:38 +0200 Subject: [PATCH] fixed translation in preferences --- src/main.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main.py b/src/main.py index 1f4f003..752dec7 100644 --- a/src/main.py +++ b/src/main.py @@ -22,14 +22,21 @@ from gi.repository import Gtk, Gio, Adw, GLib from .window import TeleprompterWindow -from gettext import gettext as _ +import gettext + +from os import path + +LOCALE_DIR = path.join( + path.dirname(__file__).split('teleprompter')[0], 'locale') +gettext.bindtextdomain('teleprompter', LOCALE_DIR) +gettext.textdomain('teleprompter') class TeleprompterApplication(Adw.Application): """The main application singleton class.""" - def __init__(self): - super().__init__(application_id='io.github.nokse22.teleprompter', + def __init_gettext(self): + super().__init_gettext(application_id='io.github.nokse22.teleprompter', flags=Gio.ApplicationFlags.DEFAULT_FLAGS) self.create_action( 'quit', lambda *_: self.quit(), ['q']) @@ -95,7 +102,7 @@ def on_about_action(self, *args): website='https://github.com/Nokse22/teleprompter', copyright='© 2023 Noske') # Replace "translator-credits" with your name/username, and optionally an email or URL. - about.set_translator_credits(_("translator-credits")) + about.set_translator_credits(gettext("translator-credits")) about.present(self.props.active_window) def on_preferences_action(self, *args): @@ -104,35 +111,35 @@ def on_preferences_action(self, *args): pref = Adw.PreferencesDialog() settingsPage = Adw.PreferencesPage( - title=_("Generals")) + title=gettext("Generals")) settingsPage.set_icon_name("applications-system-symbolic") pref.add(settingsPage) scrollSettingsGroup = Adw.PreferencesGroup( - title=_("Scroll Settings")) + title=gettext("Scroll Settings")) settingsPage.add(scrollSettingsGroup) scrollSpeedRow = Adw.SpinRow( - title=_("Scroll Speed"), - subtitle=_("In words per minute (approximately)")) + title=gettext("Scroll Speed"), + subtitle=gettext("In words per minute (approximately)")) scrollSettingsGroup.add(scrollSpeedRow) speed_adj = Gtk.Adjustment(upper=200, step_increment=1, lower=10) speed_adj.set_value(self.win.settings.speed) scrollSpeedRow.set_adjustment(speed_adj) - textGroup = Adw.PreferencesGroup(title=_("Text")) + textGroup = Adw.PreferencesGroup(title=gettext("Text")) settingsPage.add(textGroup) highlightColorPickerRow = Adw.ActionRow( - title=_("Highlight color")) + title=gettext("Highlight color")) textGroup.add(highlightColorPickerRow) highlightColorPicker = Gtk.ColorButton(valign=Gtk.Align.CENTER) highlightColorPicker.set_rgba(self.win.settings.highlightColor) highlightColorPickerRow.add_suffix(highlightColorPicker) - boldHighlight = Adw.ActionRow(title=_("Bold Highlight")) + boldHighlight = Adw.ActionRow(title=gettext("Bold Highlight")) textGroup.add(boldHighlight) boldHighlightSwitch = Gtk.Switch(valign=Gtk.Align.CENTER) @@ -140,10 +147,10 @@ def on_preferences_action(self, *args): boldHighlight.add_suffix(boldHighlightSwitch) - fontColorPickerRow = Adw.ActionRow(title=_("Font color")) + fontColorPickerRow = Adw.ActionRow(title=gettext("Font color")) textGroup.add(fontColorPickerRow) - fontPickerRow = Adw.ActionRow(title=_("Font")) + fontPickerRow = Adw.ActionRow(title=gettext("Font")) textGroup.add(fontPickerRow) fontPicker = Gtk.FontButton(valign=Gtk.Align.CENTER)