我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用PyQt4.QtCore.QTranslator()。
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', 'GeometryWrapper_{}.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) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Geometry Wrapper') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'GeometryWrapper') self.toolbar.setObjectName(u'GeometryWrapper') # listen for browse button self.dlg = GeometryWrapperDialog() self.dlg.inButton.clicked.connect(self.setInDataset) # noinspection PyMethodMayBeStatic
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)
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 __init__(self): """ Initialize a new instance of this class. Set the UI object and current translator of the main dialog. """ self.app = QtGui.QApplication(sys.argv) super(QDialogUI, self).__init__() self.ui = Ui_Util() self.ui.setupUi(self) self.set_style() self.set_stylesheet() # Set default UI language trans = QtCore.QTranslator() trans.load(LANG_DIR + "en_US") self._trans = trans self.app.installTranslator(trans) self.set_languages()
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', 'GoogleEarthEnginePlugin_{}.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) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Google Earth Engine') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'GoogleEarthEngine') self.toolbar.setObjectName(u'GoogleEarthEngine') self.pluginIsActive = False self.dock_widget = None # noinspection PyMethodMayBeStatic
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 """ super(SortNumber, self).__init__() # necessary for pyqtSignal # 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', 'SortNumber_{}.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 = SortNumberDialog() # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Sort and Number') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'SortNumber') self.toolbar.setObjectName(u'SortNumber') # noinspection PyMethodMayBeStatic
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', 'isochrones_{}.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 = isochronesDialog(self.iface.mainWindow(), self.iface) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Isochrones') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'isochrones') self.toolbar.setObjectName(u'isochrones') # noinspection PyMethodMayBeStatic
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', 'HotspotAnalysis_{}.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 = HotspotAnalysisDialog() # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Hotspot Analysis') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'HotspotAnalysis') self.toolbar.setObjectName(u'HotspotAnalysis') # Load output directory path self.dlg.lineEdit.clear() self.dlg.pushButton.clicked.connect(self.select_output_file) self.clear_ui() # noinspection PyMethodMayBeStatic
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', 'mapillary_{}.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 = mapillaryDialog() # Declare instance attributes self.actions = [] self.menu = self.tr(u'&mapillary') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'mapillary') self.toolbar.setObjectName(u'mapillary') # noinspection PyMethodMayBeStatic
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', 'DataLoader_{}.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) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Data Loader') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'DataLoader') self.toolbar.setObjectName(u'DataLoader') # noinspection PyMethodMayBeStatic
def start_gui(): from .frontends import MainWindow app = QApplication(sys.argv) trans = QTranslator() trans.load(config['lang'], Constant.locale_dir) app.installTranslator(trans) window = MainWindow() window.show() sys.exit(app.exec_())
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', 'QgsResourceSharing_{}.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 = ResourceSharingDialog(iface=self.iface) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Resource Sharing') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'QgsResourceSharing') self.toolbar.setObjectName(u'QgsResourceSharing') # noinspection PyMethodMayBeStatic
def __init__(self, iface): self.iface = iface self.canvas = self.iface.mapCanvas() self.qgsVersion = unicode(QGis.QGIS_VERSION_INT) pluginPath = os.path.abspath(os.path.dirname(__file__)) overrideLocale = QSettings().value('locale/overrideFlag', False, bool) if not overrideLocale: locale = QLocale.system().name()[:2] else: locale = QSettings().value('locale/userLocale', '') translationPath = '{}/i18n/landmark_{}.qm'.format(pluginPath, locale) if QFileInfo(translationPath).exists(): self.translator = QTranslator() self.translator.load(translationPath) QCoreApplication.installTranslator(self.translator)
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 """ QSettings().setValue("ckan_browser/isopen", False) # 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', 'CKANBrowser_{}.qm'.format(locale)) # load english file for testing # locale_path = os.path.join( # self.plugin_dir, # 'i18n', # 'CKANBrowser_en.qm') if not os.path.exists(locale_path): locale_path = os.path.join( self.plugin_dir, 'i18n', 'CKANBrowser_en.qm') if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.settings = Settings() self.settings.load() self.util = Util(self.settings, self.iface.mainWindow()) # TODO ping API # Create the dialog (after translation) and keep reference # self.dlg = CKANBrowserDialog(self.settings, self.iface, self.iface.mainWindow()) # Declare instance attributes self.actions = [] self.menu = self.util.tr(u'&Open Data (CKAN) Browser') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'Open Data (CKAN) Browser') self.toolbar.setObjectName(u'Open Data (CKAN) Browser')
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__) self.elevation_dir = os.path.join(self.plugin_dir, 'elevation') print self.elevation_dir # initialize locale locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join( self.plugin_dir, 'i18n', '{}.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 = ElevationPluginDialog() self.dlg.choose_dir_button.clicked.connect(self.open_browse) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&QGIS Elevation Plugin') # Making GDAL visible local_path = '/usr/local/bin:' if local_path not in os.environ['PATH']: os.environ['PATH'] = local_path + os.environ['PATH'] # Checking the presence of elevation library try: import elevation print elevation.util.selfcheck(elevation.datasource.TOOLS) except: self.clear_and_push_message("Installing elevation library!", QgsMessageBar.WARNING, 10) pip.main(['install', '--target=%s' % self.elevation_dir, 'elevation']) if self.elevation_dir not in sys.path: sys.path.append(self.elevation_dir) self.clear_and_push_message("Elevation Library correctly installed!", QgsMessageBar.INFO, 5)
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.dlg = MapzenIsochronesDialog() 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', 'MapzenIsochrones_{}.qm'.format(locale)) #Populate comboBox_2 with all point file layers for layer in qgis.utils.iface.legendInterface().layers(): layerType = layer.type() if layerType == QgsMapLayer.VectorLayer and layer.wkbType() == QGis.WKBPoint: self.dlg.comboBox_2.addItem(layer.name()) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Mapzen Isochrones') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'MapzenIsochrones') self.toolbar.setObjectName(u'MapzenIsochrones') # noinspection PyMethodMayBeStatic
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 self.canvas = self.iface.mapCanvas() # 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', 'GkukanMusiumdb_{}.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) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&gkukanmusiumdb') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'GkukanMusiumdb') self.toolbar.setObjectName(u'GkukanMusiumdb') #print "** INITIALIZING GkukanMusiumdb" self.pluginIsActive = False self.dockwidget = None self.GKukanSetting() self.land=LandmarkPlugin(self.iface) self.projectloaded=False QgsProject.instance().readProject.connect(self.project_loaded) # noinspection PyMethodMayBeStatic