[pyqgis-console] fixes translation strings

This commit is contained in:
Salvatore Larosa 2013-05-04 22:21:59 +02:00
parent fb91f76c19
commit d3f9dd5dc4
2 changed files with 56 additions and 25 deletions

View File

@ -464,19 +464,18 @@ class PythonConsoleWidget(QWidget):
self.layoutFind = QGridLayout(self.widgetFind) self.layoutFind = QGridLayout(self.widgetFind)
self.layoutFind.setContentsMargins(0, 0, 0, 0) self.layoutFind.setContentsMargins(0, 0, 0, 0)
self.lineEditFind = QgsFilterLineEdit() self.lineEditFind = QgsFilterLineEdit()
self.lineEditFind.setPlaceholderText('Enter text to find...') placeHolderTxt = QCoreApplication.translate("PythonConsole", "Enter text to find...")
self.lineEditFind.setPlaceholderText(placeHolderTxt)
self.findNextButton = QToolButton() self.findNextButton = QToolButton()
self.findNextButton.setEnabled(False) self.findNextButton.setEnabled(False)
toolTipfindNext = QCoreApplication.translate("PythonConsole", toolTipfindNext = QCoreApplication.translate("PythonConsole", "Find Next")
"Find Next")
self.findNextButton.setToolTip(toolTipfindNext) self.findNextButton.setToolTip(toolTipfindNext)
self.findNextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchNextEditorConsole.png")) self.findNextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchNextEditorConsole.png"))
self.findNextButton.setIconSize(QSize(24, 24)) self.findNextButton.setIconSize(QSize(24, 24))
self.findNextButton.setAutoRaise(True) self.findNextButton.setAutoRaise(True)
self.findPrevButton = QToolButton() self.findPrevButton = QToolButton()
self.findPrevButton.setEnabled(False) self.findPrevButton.setEnabled(False)
toolTipfindPrev = QCoreApplication.translate("PythonConsole", toolTipfindPrev = QCoreApplication.translate("PythonConsole", "Find Previous")
"Find Previous")
self.findPrevButton.setToolTip(toolTipfindPrev) self.findPrevButton.setToolTip(toolTipfindPrev)
self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png")) self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png"))
self.findPrevButton.setIconSize(QSize(24, 24)) self.findPrevButton.setIconSize(QSize(24, 24))
@ -628,8 +627,9 @@ class PythonConsoleWidget(QWidget):
def openScriptFile(self): def openScriptFile(self):
settings = QSettings() settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirPath").toString() lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
filename = QFileDialog.getOpenFileName( filename = QFileDialog.getOpenFileName(
self, "Open File", lastDirPath, "Script file (*.py)") self, openFileTr, lastDirPath, "Script file (*.py)")
if not filename.isEmpty(): if not filename.isEmpty():
for i in range(self.tabEditorWidget.count()): for i in range(self.tabEditorWidget.count()):
tabWidget = self.tabEditorWidget.widget(i) tabWidget = self.tabEditorWidget.widget(i)
@ -650,15 +650,18 @@ class PythonConsoleWidget(QWidget):
try: try:
tabWidget.save() tabWidget.save()
except (IOError, OSError), e: except (IOError, OSError), e:
QMessageBox.warning(self, "Save Error", errTr = QCoreApplication.translate("PythonConsole", "Save Error")
"Failed to save %s: %s" % (tabWidget.path, e)) msgErrTr = QCoreApplication.translate("PythonConsole",
"Failed to save %1: %2").arg(tabWidget.path, e)
QMessageBox.warning(self, errTr, msgErrTr)
def saveAsScriptFile(self): def saveAsScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget() tabWidget = self.tabEditorWidget.currentWidget()
if tabWidget is None: if tabWidget is None:
return return
saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As")
filename = QFileDialog.getSaveFileName(self, filename = QFileDialog.getSaveFileName(self,
"Save File As", saveAsFileTr,
tabWidget.path, "Script file (*.py)") tabWidget.path, "Script file (*.py)")
if not filename.isEmpty(): if not filename.isEmpty():
#print tabWidget.path #print tabWidget.path

View File

@ -472,23 +472,30 @@ class Editor(QsciScintilla):
pass pass
else: else:
raise e raise e
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in ')
if tmp: if tmp:
name = name + ' [Temporary file saved in ' + dir + ']' name = name + tmpFileTr + dir + ']'
if _traceback: if _traceback:
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: %1').arg(name)
print "## %s" % datetime.datetime.now() print "## %s" % datetime.datetime.now()
print "## Script error: %s" % name print msgTraceTr
sys.stderr.write(_traceback) sys.stderr.write(_traceback)
p.stderr.close() p.stderr.close()
else: else:
msgSuccessTr = QCoreApplication.translate('PythonConsole',
'## Script executed successfully: %1').arg(name)
print "## %s" % datetime.datetime.now() print "## %s" % datetime.datetime.now()
print "## Script executed successfully: %s" % name print msgSuccessTr
sys.stdout.write(out) sys.stdout.write(out)
p.stdout.close() p.stdout.close()
del p del p
if tmp: if tmp:
os.remove(filename) os.remove(filename)
except IOError, error: except IOError, error:
print 'Cannot execute file %s. Error: %s' % (filename, error.strerror) IOErrorTr = QCoreApplication.translate('PythonConsole',
'Cannot execute file %1. Error: %2') \
.arg(filename, error.strerror)
print IOErrorTr
except: except:
s = traceback.format_exc() s = traceback.format_exc()
print '## Error: ' print '## Error: '
@ -535,7 +542,8 @@ class Editor(QsciScintilla):
def goToLine(self, objName, linenr): def goToLine(self, objName, linenr):
self.SendScintilla(QsciScintilla.SCI_GOTOLINE, linenr-1) self.SendScintilla(QsciScintilla.SCI_GOTOLINE, linenr-1)
self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART, self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)) self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART,
self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS))
self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, len(self.text())) self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, len(self.text()))
pos = self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET, len(objName), objName) pos = self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET, len(objName), objName)
index = pos - self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) index = pos - self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
@ -557,7 +565,10 @@ class Editor(QsciScintilla):
try: try:
file = open(pathfile, "r").readlines() file = open(pathfile, "r").readlines()
except IOError, error: except IOError, error:
print 'The file %s could not be opened. Error: %s' % (pathfile, error.strerror) IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file %1 could not be opened. Error: %2') \
.arg(pathfile, error.strerro)
print IOErrorTr
for line in reversed(file): for line in reversed(file):
self.insert(line) self.insert(line)
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
@ -566,7 +577,9 @@ class Editor(QsciScintilla):
self.parent.tw.listObject(self.parent.tw.currentWidget()) self.parent.tw.listObject(self.parent.tw.currentWidget())
self.mtime = os.stat(pathfile).st_mtime self.mtime = os.stat(pathfile).st_mtime
msgText = QCoreApplication.translate('PythonConsole', 'The file <b>"%1"</b> has been changed and reloaded').arg(pathfile) msgText = QCoreApplication.translate('PythonConsole',
'The file <b>"%1"</b> has been changed and reloaded') \
.arg(pathfile)
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False) self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)
QsciScintilla.focusInEvent(self, e) QsciScintilla.focusInEvent(self, e)
@ -609,7 +622,10 @@ class EditorTab(QWidget):
try: try:
fn = open(unicode(filename), "rb") fn = open(unicode(filename), "rb")
except IOError, error: except IOError, error:
print 'The file <b>%s</b> could not be opened. Error: %s' % (filename, error.strerror) IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file <b>%1</b> could not be opened. Error: %2') \
.arg(filename, error.strerror)
print IOErrorTr
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
txt = fn.read() txt = fn.read()
fn.close() fn.close()
@ -621,8 +637,10 @@ class EditorTab(QWidget):
def save(self): def save(self):
if self.path is None: if self.path is None:
saveTr = QCoreApplication.translate('PythonConsole',
'Python Console: Save file')
self.path = str(QFileDialog().getSaveFileName(self, self.path = str(QFileDialog().getSaveFileName(self,
"Python Console: Save file", saveTr,
"*.py", "*.py",
"Script file (*.py)")) "Script file (*.py)"))
# If the user didn't select a file, abort the save operation # If the user didn't select a file, abort the save operation
@ -743,7 +761,9 @@ class EditorTabWidget(QTabWidget):
self.connect(self.fileTabMenu, SIGNAL("triggered(QAction*)"), self.connect(self.fileTabMenu, SIGNAL("triggered(QAction*)"),
self.showFileTabMenuTriggered) self.showFileTabMenuTriggered)
self.fileTabButton = QToolButton() self.fileTabButton = QToolButton()
self.fileTabButton.setToolTip('List all tabs') txtToolTipMenuFile = QCoreApplication.translate("PythonConsole",
"List all tabs")
self.fileTabButton.setToolTip(txtToolTipMenuFile)
self.fileTabButton.setIcon(QgsApplication.getThemeIcon("console/iconFileTabsMenuConsole.png")) self.fileTabButton.setIcon(QgsApplication.getThemeIcon("console/iconFileTabsMenuConsole.png"))
self.fileTabButton.setIconSize(QSize(24, 24)) self.fileTabButton.setIconSize(QSize(24, 24))
self.fileTabButton.setAutoRaise(True) self.fileTabButton.setAutoRaise(True)
@ -756,7 +776,9 @@ class EditorTabWidget(QTabWidget):
# Open button # Open button
self.newTabButton = QToolButton() self.newTabButton = QToolButton()
self.newTabButton.setToolTip('New Tab') txtToolTipNewTab = QCoreApplication.translate("PythonConsole",
"New Tab")
self.newTabButton.setToolTip(txtToolTipNewTab)
self.newTabButton.setAutoRaise(True) self.newTabButton.setAutoRaise(True)
self.newTabButton.setIcon(QgsApplication.getThemeIcon("console/iconNewTabEditorConsole.png")) self.newTabButton.setIcon(QgsApplication.getThemeIcon("console/iconNewTabEditorConsole.png"))
self.newTabButton.setIconSize(QSize(24, 24)) self.newTabButton.setIconSize(QSize(24, 24))
@ -813,9 +835,12 @@ class EditorTabWidget(QTabWidget):
if tab2index: if tab2index:
tab = self.indexOf(tab) tab = self.indexOf(tab)
if self.widget(tab).newEditor.isModified(): if self.widget(tab).newEditor.isModified():
res = QMessageBox.question( self, 'Python Console: Save File', txtSaveOnRemove = QCoreApplication.translate("PythonConsole",
'The file <b>"%s"</b> has been modified, save changes ?' "Python Console: Save File")
% self.tabText(tab), txtMsgSaveOnRemove = QCoreApplication.translate("PythonConsole",
"The file <b>'%1'</b> has been modified, save changes ?").arg(self.tabText(tab))
res = QMessageBox.question( self, txtSaveOnRemove,
txtMsgSaveOnRemove,
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel ) QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
if res == QMessageBox.Save: if res == QMessageBox.Save:
self.widget(tab).save() self.widget(tab).save()
@ -856,8 +881,11 @@ class EditorTabWidget(QTabWidget):
tabName = pathFile.split('/')[-1] tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile) self.newTabEditor(tabName, pathFile)
else: else:
errOnRestore = QCoreApplication.translate("PythonConsole",
"Unable to restore the file: \n%1\n") \
.arg(pathFile)
print '## Error: ' print '## Error: '
s = 'Unable to restore the file: \n%s\n' % pathFile s = errOnRestore
sys.stderr.write(s) sys.stderr.write(s)
self.parent.updateTabListScript(pathFile) self.parent.updateTabListScript(pathFile)
if self.count() < 1: if self.count() < 1: