Skip to content

Commit

Permalink
Fix translations once and for all
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende authored and geigi committed Dec 6, 2023
1 parent 1ba3745 commit cff4575
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
27 changes: 4 additions & 23 deletions cozy/application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import gettext
import locale
import logging
import os
import platform
Expand All @@ -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")


Expand Down Expand Up @@ -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')
Expand All @@ -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__}")
Expand Down
22 changes: 17 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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")
Expand Down Expand Up @@ -93,7 +105,7 @@ def main():

listen()

application = Application(localedir, pkgdatadir)
application = Application(pkgdatadir)

try:
# Handle the debug option seperatly without the Glib stuff
Expand Down

0 comments on commit cff4575

Please sign in to comment.