def on_Lang_changed(self, lang): """ Change the UI language setting. .. note:: This method is the slot responses to the signal argument :attr:`lang` from SelectLang widget while the value is changed. :param lang: The language name which is selected by user. .. note:: This string is typically in the format of IETF language tag. For example: en_US, en_GB, etc. .. seealso:: :attr:`language` in :class:`~gui.language.LangUtil` class. :type lang: str """ new_lang = LangUtil.get_locale_by_language(unicode(lang)) trans = QtCore.QTranslator() from hostsutil import LANG_DIR trans.load(LANG_DIR + new_lang) self.app.removeTranslator(self._trans) self.app.installTranslator(trans) self._trans = trans self.ui.retranslateUi(self) self.init_main() self.check_connection()
def set_languages(self): """ Set optional language selection items in the SelectLang widget. """ self.ui.SelectLang.clear() langs = LangUtil.language langs_not_found = [] for locale in langs: if not os.path.isfile(LANG_DIR + locale + ".qm"): langs_not_found.append(locale) for locale in langs_not_found: langs.pop(locale) LangUtil.language = langs if len(langs) <= 1: self.ui.SelectLang.setEnabled(False) # Block the signal while set the language selecions. self.ui.SelectLang.blockSignals(True) sys_locale = LangUtil.get_locale() if sys_locale not in langs.keys(): sys_locale = "en_US" for i, locale in enumerate(sorted(langs.keys())): if sys_locale == locale: select = i lang = langs[locale] self.ui.SelectLang.addItem(_fromUtf8("")) self.ui.SelectLang.setItemText(i, lang) self.ui.SelectLang.blockSignals(False) self.ui.SelectLang.setCurrentIndex(select)