def _load_lang(): locale = QtCore.QLocale() full_locale = locale.bcp47Name() if "LUMBERJACK_LOCALE" in os.environ: full_locale = os.environ["LUMBERJACK_LOCALE"] logging.info("LOCAL OVERRIDE %s" % full_locale) if "-" in full_locale: lang, _ = full_locale.split("-") else: lang = full_locale if lang == "en": # we write in english by default, maybe one day we will deal with British/US english logging.info("English language") return region_lang = ":i18n/%s.qm" % full_locale lang_lang = ":i18n/%s.qm" % lang lang_file = QtCore.QFile(region_lang) if not lang_file.exists(): logging.debug("language %s does not exist" % region_lang) lang_file.close() lang_file = QtCore.QFile(lang_lang) if not lang_file.exists(): logging.info("language %s does not exist" % lang_lang) lang_file.close() logging.debug("falling back to english") return logging.debug("found lang file %s " % lang_file.fileName()) app = QtWidgets.QApplication.instance() trans = QtCore.QTranslator(app) trans.load(lang_file.fileName()) app = QtWidgets.QApplication.instance() app.installTranslator(trans)
def _read_theme_file(theme, gui=None): logging.debug("theme: %s", theme) css_f = QtCore.QFile(theme) css_f.open(QtCore.QIODevice.ReadOnly) theme_data = "" in_ = QtCore.QTextStream(css_f) theme_dev = False if ":" not in theme: # theme dev mode, fix the file theme_dev = True logging.info("in theme dev mode") while not in_.atEnd(): line = in_.readLine() # A QByteArray if theme_dev: rsc_dir = join(dirname(dirname(dirname(__file__))), "resources") line = line.replace("url(:", "url(%s/" % rsc_dir) theme_data += line css_f.close() app = QtWidgets.QApplication.instance() logging.info('setting theme: %s' % gui) if gui: gui.setStyleSheet(theme_data) else: app.setStyleSheet(theme_data)