本文整理汇总了Python中PyQt5.QtCore.QTranslator.translate方法的典型用法代码示例。如果您正苦于以下问题:Python QTranslator.translate方法的具体用法?Python QTranslator.translate怎么用?Python QTranslator.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QTranslator
的用法示例。
在下文中一共展示了QTranslator.translate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __populateLanguageCombo
# 需要导入模块: from PyQt5.QtCore import QTranslator [as 别名]
# 或者: from PyQt5.QtCore.QTranslator import translate [as 别名]
def __populateLanguageCombo(self):
"""
Private method to initialize the language combobox of the Interface
configuration page.
"""
self.languageComboBox.clear()
fnlist = glob.glob("eric6_*.qm") + \
glob.glob(os.path.join(
getConfig('ericTranslationsDir'), "eric6_*.qm")) + \
glob.glob(os.path.join(Utilities.getConfigDir(), "eric6_*.qm"))
locales = {}
for fn in fnlist:
locale = os.path.basename(fn)[6:-3]
if locale not in locales:
translator = QTranslator()
translator.load(fn)
locales[locale] = translator.translate(
"InterfacePage", "English",
"Translate this with your language") + \
" ({0})".format(locale)
localeList = sorted(list(locales.keys()))
try:
uiLanguage = Preferences.getUILanguage()
if uiLanguage == "None" or uiLanguage is None:
currentIndex = 0
elif uiLanguage == "System":
currentIndex = 1
else:
currentIndex = localeList.index(uiLanguage) + 2
except ValueError:
currentIndex = 0
self.languageComboBox.clear()
self.languageComboBox.addItem("English (default)", "None")
self.languageComboBox.addItem(self.tr('System'), "System")
for locale in localeList:
self.languageComboBox.addItem(locales[locale], locale)
self.languageComboBox.setCurrentIndex(currentIndex)
示例2: beginFinalInit
# 需要导入模块: from PyQt5.QtCore import QTranslator [as 别名]
# 或者: from PyQt5.QtCore.QTranslator import translate [as 别名]
def beginFinalInit(self):
"""
@see: startup
Notice the __init__ method . we just setup the basic widget.
And after the language , style ,plugins etc had loaded .
we call this method .
Never call it unless you know what's it
"""
#when at linux platform . the icon is not visible at menu .
for key in self.__actions.keys():
self.__actions.get(key).setIconVisibleInMenu(True)
#--------------->>Seeking init <<-----------------#
# __init__ menu
self.getMenu("settings").addAction(self.getAction("perferences"))
#i18n , must restart program to make it in use
action_languages = QAction(QIcon(getPath('iconDir','languages.png')),QApplication.translate("default", "Languages"),self)
action_languages.setIconVisibleInMenu(True)
menu_languages = QMenu(self)
trans_dir = QDir(getPrccisePath("transDir","","coredir"))
fileNames = trans_dir.entryList(['i18n*.qm'], QDir.Files,QDir.Name)
qmFiles = [trans_dir.filePath(fn) for fn in fileNames]
for qmf in qmFiles:
translator = QTranslator()
translator.load(qmf)
action = menu_languages.addAction(translator.translate("default", "English"))
action.triggered.connect(lambda re,locale=translator.translate("default", "locale"):self.__evt_changeLanguage(locale))
action_languages.setMenu(menu_languages)
self.getMenu("settings").addAction(action_languages)
#style menu use signalmapper
action_style = QAction(QIcon(getPath('iconDir','style.png')),QApplication.translate("default", "Style"),self)
action_style.setIconVisibleInMenu(True)
menu_style = QMenu(self)
for style_item in QStyleFactory.keys():
action = menu_style.addAction(style_item)
action.triggered.connect(lambda re,style_item=style_item:changeStyle(style_item))
action_style.setMenu(menu_style)
self.getMenu("settings").addAction(action_style)
menu_plugin = self.getMenu("plugins")
menu_plugin.addAction(self.getAction("plguinInfos"))
menu_plugin.addSeparator()
menu_plugin.addAction(self.getAction("plguinRequest"))
#--------------->>Seeking init <<-----------------#
# __init__ toolbar
toolBar = self.addToolBar(QApplication.translate("default","common"))
toolBar.addAction(self.getAction("perferences"))
toolBar.addAction(self.getAction("close"))
toolBar.addAction(self.getAction("gotohome"))
toolBar.addAction(self.getAction("help"))
#--------------->>Seeking init <<-----------------#
# __init__ status bar
self.statusBar().showMessage("Seeking ...")
#--------------->>Seeking init <<-----------------#
#Effects of a loading progress .
#Results appear in the tab of the interior, the window has no effect on the global
self.overlay = Overlay(self.centralWidget())
self.overlay.hide()
#--------------->>Seeking init <<-----------------#
#other
self.emit(SIGNAL('updateWindows()'))
示例3: languageName
# 需要导入模块: from PyQt5.QtCore import QTranslator [as 别名]
# 或者: from PyQt5.QtCore.QTranslator import translate [as 别名]
def languageName(self, qmFile):
translator = QTranslator()
translator.load(qmFile)
return translator.translate("MainWindow", "English")
示例4: list
# 需要导入模块: from PyQt5.QtCore import QTranslator [as 别名]
# 或者: from PyQt5.QtCore.QTranslator import translate [as 别名]
try:
argvb = list(map(os.fsencode, sys.argv))
except AttributeError:
argvb = sys.argv
app = QCoreApplication(argvb)
for qm in glob(sys.argv[1] + "/output/i18n/qgis_*.qm"):
translator = QTranslator()
translator.load(qm)
lang = qm[len(sys.argv[1] + "/output/i18n/qgis_"):-3]
for s in strings:
translation = translator.translate("appinfo", s, "")
if translation in [s, '']:
continue
strings[s][lang] = translation
for elem in ['name', 'summary', 'description']:
for c in r.iter(elem):
if c.attrib:
continue
l = list(c)
s = c.text if not l else "".join([et.tostring(x).decode("utf-8") for x in l])
for lang in strings[s]:
e = et.Element(elem, attrib={"xml:lang": lang})
e.text = strings[s][lang]