From cff4575bb34b4a19918a7e30110de9f30007e572 Mon Sep 17 00:00:00 2001 From: rdbende Date: Mon, 4 Dec 2023 19:47:26 +0100 Subject: [PATCH] Fix translations once and for all --- cozy/application.py | 27 ++++----------------------- main.py | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/cozy/application.py b/cozy/application.py index 33521fda..59996a49 100644 --- a/cozy/application.py +++ b/cozy/application.py @@ -1,5 +1,3 @@ -import gettext -import locale import logging import os import platform @@ -9,24 +7,18 @@ from traceback import format_exception import distro - -import gi - -from cozy.db.storage import Storage -from cozy.ui.widgets.filter_list_box import FilterListBox -from cozy.ui.widgets.seek_bar import SeekBar - -from gi.repository import Gtk, GLib, Adw +from gi.repository import Adw, GLib from cozy.app_controller import AppController from cozy.control.db import init_db from cozy.control.mpris import MPRIS from cozy.db.settings import Settings +from cozy.db.storage import Storage from cozy.report import reporter from cozy.ui.main_view import CozyUI +from cozy.ui.widgets.filter_list_box import FilterListBox from cozy.version import __version__ - log = logging.getLogger("application") @@ -60,8 +52,7 @@ class Application(Adw.Application): ui: CozyUI app_controller: AppController - def __init__(self, localedir: str, pkgdatadir: str): - self.localedir = localedir + def __init__(self, pkgdatadir: str): self.pkgdatadir = pkgdatadir super().__init__(application_id='com.github.geigi.cozy') @@ -74,16 +65,6 @@ def __init__(self, localedir: str, pkgdatadir: str): sys.excepthook = self.handle_exception setup_thread_excepthook() - # We need to call `locale.*textdomain` to get the strings in UI files translated - locale.bindtextdomain('com.github.geigi.cozy', localedir) - locale.textdomain('com.github.geigi.cozy') - - # But also `gettext.*textdomain`, to make `_("foo")` in Python work as well - gettext.bindtextdomain('com.github.geigi.cozy', localedir) - gettext.textdomain('com.github.geigi.cozy') - - gettext.install('com.github.geigi.cozy', localedir) - def do_startup(self): log.info(distro.linux_distribution(full_distribution_name=False)) log.info(f"Starting up cozy {__version__}") diff --git a/main.py b/main.py index 766540a6..00afe960 100755 --- a/main.py +++ b/main.py @@ -19,11 +19,14 @@ import argparse import code +import gettext +import locale import logging import os import signal import sys import traceback + import gi gi.require_version('Gtk', '4.0') @@ -32,17 +35,26 @@ gi.require_version('Gst', '1.0') gi.require_version('GstPbutils', '1.0') +from gi.repository import Gio, GLib + pkgdatadir = '@DATA_DIR@' localedir = '@LOCALE_DIR@' -from gi.repository import Gio +# We need to call `locale.*textdomain` to get the strings in UI files translated +locale.bindtextdomain('com.github.geigi.cozy', localedir) +locale.textdomain('com.github.geigi.cozy') + +# But also `gettext.*textdomain`, to make `_("foo")` in Python work as well +gettext.bindtextdomain('com.github.geigi.cozy', localedir) +gettext.textdomain('com.github.geigi.cozy') -# gresource must be registered before importing any Gtk.Template annotated classes +gettext.install('com.github.geigi.cozy', localedir) + + +# gresource must be registered before importing any Gtk.Template annotated classes resource = Gio.Resource.load(os.path.join(pkgdatadir, 'com.github.geigi.cozy.ui.gresource')) resource._register() -from gi.repository import GLib - old_except_hook = None log = logging.getLogger("main") @@ -93,7 +105,7 @@ def main(): listen() - application = Application(localedir, pkgdatadir) + application = Application(pkgdatadir) try: # Handle the debug option seperatly without the Glib stuff