本文整理匯總了Python中PyQt4.QtCore.QTranslator方法的典型用法代碼示例。如果您正苦於以下問題:Python QtCore.QTranslator方法的具體用法?Python QtCore.QTranslator怎麽用?Python QtCore.QTranslator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.QtCore
的用法示例。
在下文中一共展示了QtCore.QTranslator方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from PyQt4 import QtCore [as 別名]
# 或者: from PyQt4.QtCore import QTranslator [as 別名]
def __init__(self):
super(SimpleApp, self).__init__([])
self.translator = QtCore.QTranslator()
self.default_font = QtGui.QFont()
if sys.version_info < (3,) :
settings_path = ".easygui-qt2"
else:
settings_path = ".easygui-qt3"
self.config_path = os.path.join(os.path.expanduser("~"),
settings_path)
try:
self.load_config()
self.setFont(self.default_font)
except:
pass
self.save_config()
示例2: set_locale
# 需要導入模塊: from PyQt4 import QtCore [as 別名]
# 或者: from PyQt4.QtCore import QTranslator [as 別名]
def set_locale(self, locale, save=True):
"""Sets the language of the basic controls for PyQt
from a locale - provided that the corresponding qm files
are present in the PyQt distribution.
"""
global QM_FILES
if QM_FILES is None:
QM_FILES = utils.find_qm_files()
if locale in QM_FILES:
if self.translator.load("qt_" + locale, QM_FILES[locale]):
self.installTranslator(self.translator)
self.config['locale'] = locale
else:
print("language not available")
elif locale == "default" and self.config['locale'] != 'default':
self.removeTranslator(self.translator)
self.translator = QtCore.QTranslator()
self.config['locale'] = 'default'
elif self.config['locale'] in QM_FILES:
if self.translator.load("qt_" + self.config['locale'],
QM_FILES[self.config['locale']]):
self.installTranslator(self.translator)
if save:
self.save_config()
示例3: __init__
# 需要導入模塊: from PyQt4 import QtCore [as 別名]
# 或者: from PyQt4.QtCore import QTranslator [as 別名]
def __init__(self, iface):
QObject.__init__(self)
QgsMessageLog.logMessage('GDAL Version: ' + str(gdal.VersionInfo('VERSION_NUM')), 'CartoDB Plugin', QgsMessageLog.INFO)
# Save reference to the QGIS interface
self.iface = iface
# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
localePath = os.path.join(CartoDBPlugin.PLUGIN_DIR, "i18n", "{}.qm".format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# SQLite available?
driverName = "SQLite"
self.sqLiteDrv = ogr.GetDriverByName(driverName)
if self.sqLiteDrv is None:
QgsMessageLog.logMessage('SQLite driver not found', 'CartoDB Plugin', QgsMessageLog.CRITICAL)
else:
QgsMessageLog.logMessage('SQLite driver is found', 'CartoDB Plugin', QgsMessageLog.INFO)
self.databasePath = CartoDBPlugin.PLUGIN_DIR + '/db/database.sqlite'
shutil.copyfile(CartoDBPlugin.PLUGIN_DIR + '/db/init_database.sqlite', self.databasePath)
self.layers = []
self.countLoadingLayers = 0
self.countLoadedLayers = 0
self._cdbMenu = None
self._mainAction = None
self._loadDataAction = None
self._createVizAction = None
self._addSQLAction = None
self.toolbar = CartoDBToolbar()
self._toolbarAction = None
self._menu = None
示例4: __init__
# 需要導入模塊: from PyQt4 import QtCore [as 別名]
# 或者: from PyQt4.QtCore import QTranslator [as 別名]
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'TestPlugin_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Create the dialog (after translation) and keep reference
self.dlg = TestPluginDialog()
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&Test Plugin')
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'TestPlugin')
self.toolbar.setObjectName(u'TestPlugin')
# noinspection PyMethodMayBeStatic
示例5: test_qgis_translations
# 需要導入模塊: from PyQt4 import QtCore [as 別名]
# 或者: from PyQt4.QtCore import QTranslator [as 別名]
def test_qgis_translations(self):
"""Test that translations work."""
parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir)
dir_path = os.path.abspath(parent_path)
file_path = os.path.join(
dir_path, 'i18n', 'af.qm')
translator = QTranslator()
translator.load(file_path)
QCoreApplication.installTranslator(translator)
expected_message = 'Goeie more'
real_message = QCoreApplication.translate("@default", 'Good morning')
self.assertEqual(real_message, expected_message)