#!/usr/local/bin/python3

# Copyright 2020 gi-lom
# Copyright 2020 Rafael Mardojai CM
# SPDX-License-Identifier: GPL-3.0-or-later

import gettext
import locale
import os
import signal
import sys

pkgdatadir = '/usr/local/share/dialect'
localedir = '/usr/local/share/locale'
builddir = os.environ.get('MESON_BUILD_ROOT')
if builddir:
    sys.dont_write_bytecode = True
    sys.path.insert(1, os.environ['MESON_SOURCE_ROOT'])
    data_dir = os.path.join(builddir, '/usr/local', 'share')
    os.putenv('XDG_DATA_DIRS', '%s:%s' % (data_dir, os.getenv('XDG_DATA_DIRS', '/usr/local/share/:/usr/share/')))

sys.path.insert(1, pkgdatadir)
signal.signal(signal.SIGINT, signal.SIG_DFL)

langs_trans = gettext.translation('dialect-cldr-langs', localedir, fallback=True)
ui_trans = gettext.translation('dialect', localedir, fallback=True)
ui_trans.add_fallback(langs_trans)
ui_trans.install(names=['gettext'])

locale.bindtextdomain('dialect', localedir)
locale.textdomain('dialect')

if __name__ == '__main__':
    from gi.repository import Gio
    resource = Gio.Resource.load(os.path.join(pkgdatadir, 'dialect.gresource'))
    resource._register()

    from dialect import main
    sys.exit(main.main())
