我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用PyQt5.QtCore.QTranslator()。
def checkBoxToggled(self): checkBox = self.sender() window = self.mainWindowForCheckBoxMap.get(checkBox) if not window: translator = QTranslator() translator.load(self.qmFileForCheckBoxMap[checkBox]) QApplication.installTranslator(translator) # Because we will be installing an event filter for the main window # it is important that this instance isn't garbage collected before # the main window when the program terminates. We ensure this by # making the main window a child of this one. window = MainWindow(self) window.setPalette(QPalette(self.colorForLanguage(checkBox.text()))) window.installEventFilter(self) self.mainWindowForCheckBoxMap[checkBox] = window window.setVisible(checkBox.isChecked())
def main(): """Run StarCraft Casting Tool.""" global language from scctool.view.main import MainWindow currentExitCode = MainWindow.EXIT_CODE_REBOOT cntlr = None while currentExitCode == MainWindow.EXIT_CODE_REBOOT: try: app = QApplication(sys.argv) app.setStyle(QStyleFactory.create('Fusion')) translator = QTranslator(app) translator.load(QLocale(language), "qtbase", "_", getAbsPath('locales'), ".qm") app.installTranslator(translator) initial_download() cntlr = main_window(app, translator, cntlr) currentExitCode = app.exec_() app = None except Exception as e: logger.exception("message") sys.exit(currentExitCode)
def run(): app = QtWidgets.QApplication(sys.argv) # Translates standard-buttons (Ok, Cancel) and mac menu bar to german try: base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") path = os.path.join(base_path, 'bin', 'qtbase_de.qm') translator = QtCore.QTranslator() translator.load(path) app.installTranslator(translator) window = MainWindow() window.show() app.exec_()
def main(): app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(False) app.setApplicationVersion("1.0 Beta") locale = QLocale.system().name() translator = QTranslator(app) translator.load("/usr/share/lilii/languages/{}.qm".format(locale)) app.installTranslator(translator) single = SingleApplication() if single.hasPrevious("lilii", app.arguments()): return False single.listen("lilii") window = MainWindow() window.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) qtTranslator = QTranslator() qtTranslator.load('torrentbro_' + QLocale.system().name(), QLibraryInfo.location(QLibraryInfo.TranslationsPath)) app.installTranslator(qtTranslator) ex = Home() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) app.setApplicationName("Kaptan") app.setOrganizationName("Kaptan") app.setApplicationVersion("5.0 Beta3") #app.setStyleSheet(open(join(dirPath, "data/libkaptan.qss").read()) locale = QLocale.system().name() translator = QTranslator(app) translator.load("/usr/share/kaptan/languages/kaptan_{}.qm".format(locale)) app.installTranslator(translator) kaptan = Kaptan() kaptan.show() app.exec_()
def run(): app = QtWidgets.QApplication(sys.argv) trans = QtCore.QTranslator() # trans.load("./gui/en") # app.installTranslator(trans) window = Main(app, trans) window.show() sys.exit(app.exec_())
def langSelect(self, lang): for k, v in self.lang_list.items(): if lang == v: self.parent.lilii_settings["lang"] = k translator = QTranslator(qApp) translator.load("/usr/share/lilii/languages/{}.qm".format(k.split(".")[0])) qApp.installTranslator(translator)
def languageName(self, qmFile): translator = QTranslator() translator.load(qmFile) return translator.translate("MainWindow", "English")
def __init__(self): QMainWindow.__init__(self, flags=Qt.Window) self.menu = MenuBarWidget() self.status_bar = StatusBar() self.editor = TextEditor() self.translator = QTranslator() # I18N ?? self.filename = str() self.change_locale("translate\\" + QLocale.system().name() + ".qm") # ??? ??? ?? self.document_prt = QPrinter() self.init_window() self.init_setting()
def run(): # First set some application settings for QSettings QtCore.QCoreApplication.setOrganizationName("QTodoTxt") QtCore.QCoreApplication.setApplicationName("QTodoTxt2") # Now set up our application and start app = QtWidgets.QApplication(sys.argv) # it is said, that this is lighter: # (without qwidgets, as we probably don't need them anymore, when transition to qml is done) # app = QtGui.QGuiApplication(sys.argv) name = QtCore.QLocale.system().name() translator = QtCore.QTranslator() if translator.load(str(name) + ".qm", "..//i18n"): app.installTranslator(translator) args = _parseArgs() setupSingleton(args) _setupLogging(args.loglevel) engine = QQmlApplicationEngine(parent=app) controller = MainController(args) engine.rootContext().setContextProperty("mainController", controller) path = os.path.join(os.path.dirname(__file__), 'qml') engine.addImportPath(path) mainqml = os.path.join(path, 'QTodoTxt.qml') engine.load(mainqml) setupAnotherInstanceEvent(controller) controller.start() app.setWindowIcon(QtGui.QIcon(":/qtodotxt")) app.exec_() sys.exit()
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 main(): app = QApplication(sys.argv) app.setApplicationName("Kaptan") app.setOrganizationName("Kaptan") app.setApplicationVersion("5.0 Beta3") #app.setStyleSheet(open(join(dirPath, "data/libkaptan.qss").read()) locale = QLocale.system().name() translator = QTranslator(app) translator.load("/usr/share/kaptan/languages/{}.qm".format(locale)) app.installTranslator(translator) kaptan = Kaptan() kaptan.show() app.exec_()
def launchInstance(cls, transpyler, show=True, **kwargs): """ Launches a new instance of application. """ app = QtWidgets.QApplication(sys.argv) path = os.path.join(os.path.dirname(__file__), 'data') locale = QLocale() translator = QTranslator() translator.load(locale, 'qturtle', '_', path, '.qm') app.installTranslator(translator) window = cls(transpyler, **kwargs) if show: window.show() sys.exit(app.exec_())