diff --git a/labelme/app.py b/labelme/app.py index 9479dceb786fe815f6d3e93ca5709cc5aac3aaf3..2ce02304662ba6e505cade7a77aa6f422c530230 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -88,7 +88,7 @@ class MainWindow(QtWidgets.QMainWindow): self.lastOpenDir = None self.flag_dock = self.flag_widget = None - self.flag_dock = QtWidgets.QDockWidget('Flags', self) + self.flag_dock = QtWidgets.QDockWidget(self.tr('Flags'), self) self.flag_dock.setObjectName('Flags') self.flag_widget = QtWidgets.QListWidget() if config['flags']: @@ -104,23 +104,23 @@ class MainWindow(QtWidgets.QMainWindow): self.labelList.setDragDropMode( QtWidgets.QAbstractItemView.InternalMove) self.labelList.setParent(self) - self.shape_dock = QtWidgets.QDockWidget('Polygon Labels', self) + self.shape_dock = QtWidgets.QDockWidget(self.tr('Polygon Labels'), self) self.shape_dock.setObjectName('Labels') self.shape_dock.setWidget(self.labelList) self.uniqLabelList = EscapableQListWidget() - self.uniqLabelList.setToolTip( + self.uniqLabelList.setToolTip(self.tr( "Select label to start annotating for it. " - "Press 'Esc' to deselect.") + "Press 'Esc' to deselect.")) if self._config['labels']: self.uniqLabelList.addItems(self._config['labels']) self.uniqLabelList.sortItems() - self.label_dock = QtWidgets.QDockWidget(u'Label List', self) + self.label_dock = QtWidgets.QDockWidget(self.tr(u'Label List'), self) self.label_dock.setObjectName(u'Label List') self.label_dock.setWidget(self.uniqLabelList) self.fileSearch = QtWidgets.QLineEdit() - self.fileSearch.setPlaceholderText('Search Filename') + self.fileSearch.setPlaceholderText(self.tr('Search Filename')) self.fileSearch.textChanged.connect(self.fileSearchChanged) self.fileListWidget = QtWidgets.QListWidget() self.fileListWidget.itemSelectionChanged.connect( @@ -131,7 +131,7 @@ class MainWindow(QtWidgets.QMainWindow): fileListLayout.setSpacing(0) fileListLayout.addWidget(self.fileSearch) fileListLayout.addWidget(self.fileListWidget) - self.file_dock = QtWidgets.QDockWidget(u'File List', self) + self.file_dock = QtWidgets.QDockWidget(self.tr(u'File List'), self) self.file_dock.setObjectName(u'Files') fileListWidget = QtWidgets.QWidget() fileListWidget.setLayout(fileListLayout) @@ -181,194 +181,194 @@ class MainWindow(QtWidgets.QMainWindow): # Actions action = functools.partial(utils.newAction, self) shortcuts = self._config['shortcuts'] - quit = action('&Quit', self.close, shortcuts['quit'], 'quit', - 'Quit application') - open_ = action('&Open', self.openFile, shortcuts['open'], 'open', - 'Open image or label file') - opendir = action('&Open Dir', self.openDirDialog, - shortcuts['open_dir'], 'open', u'Open Dir') + quit = action(self.tr('&Quit'), self.close, shortcuts['quit'], 'quit', + self.tr('Quit application')) + open_ = action(self.tr('&Open'), self.openFile, shortcuts['open'], 'open', + self.tr('Open image or label file')) + opendir = action(self.tr('&Open Dir'), self.openDirDialog, + shortcuts['open_dir'], 'open', self.tr(u'Open Dir')) openNextImg = action( - '&Next Image', + self.tr('&Next Image'), self.openNextImg, shortcuts['open_next'], 'next', - u'Open next (hold Ctl+Shift to copy labels)', + self.tr(u'Open next (hold Ctl+Shift to copy labels)'), enabled=False, ) openPrevImg = action( - '&Prev Image', + self.tr('&Prev Image'), self.openPrevImg, shortcuts['open_prev'], 'prev', - u'Open prev (hold Ctl+Shift to copy labels)', + self.tr(u'Open prev (hold Ctl+Shift to copy labels)'), enabled=False, ) - save = action('&Save', self.saveFile, shortcuts['save'], 'save', - 'Save labels to file', enabled=False) - saveAs = action('&Save As', self.saveFileAs, shortcuts['save_as'], - 'save-as', 'Save labels to a different file', + save = action(self.tr('&Save'), self.saveFile, shortcuts['save'], 'save', + self.tr('Save labels to file'), enabled=False) + saveAs = action(self.tr('&Save As'), self.saveFileAs, shortcuts['save_as'], + 'save-as', self.tr('Save labels to a different file'), enabled=False) deleteFile = action( - '&Delete File', + self.tr('&Delete File'), self.deleteFile, shortcuts['delete_file'], 'delete', - 'Delete current label file', + self.tr('Delete current label file'), enabled=False) changeOutputDir = action( - '&Change Output Dir', + self.tr('&Change Output Dir'), slot=self.changeOutputDirDialog, shortcut=shortcuts['save_to'], icon='open', - tip=u'Change where annotations are loaded/saved' + tip=self.tr(u'Change where annotations are loaded/saved') ) saveAuto = action( - text='Save &Automatically', + text=self.tr('Save &Automatically'), slot=lambda x: self.actions.saveAuto.setChecked(x), icon='save', - tip='Save automatically', + tip=self.tr('Save automatically'), checkable=True, enabled=True, ) saveAuto.setChecked(self._config['auto_save']) - close = action('&Close', self.closeFile, shortcuts['close'], 'close', - 'Close current file') - color1 = action('Polygon &Line Color', self.chooseColor1, + close = action(self.tr('&Close'), self.closeFile, shortcuts['close'], 'close', + self.tr('Close current file')) + color1 = action(self.tr('Polygon &Line Color'), self.chooseColor1, shortcuts['edit_line_color'], 'color_line', - 'Choose polygon line color') - color2 = action('Polygon &Fill Color', self.chooseColor2, + self.tr('Choose polygon line color')) + color2 = action(self.tr('Polygon &Fill Color'), self.chooseColor2, shortcuts['edit_fill_color'], 'color', - 'Choose polygon fill color') + self.tr('Choose polygon fill color')) toggle_keep_prev_mode = action( - 'Keep Previous Annotation', + self.tr('Keep Previous Annotation'), self.toggleKeepPrevMode, shortcuts['toggle_keep_prev_mode'], None, - 'Toggle "keep pevious annotation" mode', + self.tr('Toggle "keep pevious annotation" mode'), checkable=True) toggle_keep_prev_mode.setChecked(self._config['keep_prev']) createMode = action( - 'Create Polygons', + self.tr('Create Polygons'), lambda: self.toggleDrawMode(False, createMode='polygon'), shortcuts['create_polygon'], 'objects', - 'Start drawing polygons', + self.tr('Start drawing polygons'), enabled=False, ) createRectangleMode = action( - 'Create Rectangle', + self.tr('Create Rectangle'), lambda: self.toggleDrawMode(False, createMode='rectangle'), shortcuts['create_rectangle'], 'objects', - 'Start drawing rectangles', + self.tr('Start drawing rectangles'), enabled=False, ) createCircleMode = action( - 'Create Circle', + self.tr('Create Circle'), lambda: self.toggleDrawMode(False, createMode='circle'), shortcuts['create_circle'], 'objects', - 'Start drawing circles', + self.tr('Start drawing circles'), enabled=False, ) createLineMode = action( - 'Create Line', + self.tr('Create Line'), lambda: self.toggleDrawMode(False, createMode='line'), shortcuts['create_line'], 'objects', - 'Start drawing lines', + self.tr('Start drawing lines'), enabled=False, ) createPointMode = action( - 'Create Point', + self.tr('Create Point'), lambda: self.toggleDrawMode(False, createMode='point'), shortcuts['create_point'], 'objects', - 'Start drawing points', + self.tr('Start drawing points'), enabled=False, ) createLineStripMode = action( - 'Create LineStrip', + self.tr('Create LineStrip'), lambda: self.toggleDrawMode(False, createMode='linestrip'), shortcuts['create_linestrip'], 'objects', - 'Start drawing linestrip. Ctrl+LeftClick ends creation.', + self.tr('Start drawing linestrip. Ctrl+LeftClick ends creation.'), enabled=False, ) - editMode = action('Edit Polygons', self.setEditMode, + editMode = action(self.tr('Edit Polygons'), self.setEditMode, shortcuts['edit_polygon'], 'edit', - 'Move and edit the selected polygons', enabled=False) + self.tr('Move and edit the selected polygons'), enabled=False) - delete = action('Delete Polygons', self.deleteSelectedShape, + delete = action(self.tr('Delete Polygons'), self.deleteSelectedShape, shortcuts['delete_polygon'], 'cancel', - 'Delete the selected polygons', enabled=False) - copy = action('Duplicate Polygons', self.copySelectedShape, + self.tr('Delete the selected polygons'), enabled=False) + copy = action(self.tr('Duplicate Polygons'), self.copySelectedShape, shortcuts['duplicate_polygon'], 'copy', - 'Create a duplicate of the selected polygons', + self.tr('Create a duplicate of the selected polygons'), enabled=False) - undoLastPoint = action('Undo last point', self.canvas.undoLastPoint, + undoLastPoint = action(self.tr('Undo last point'), self.canvas.undoLastPoint, shortcuts['undo_last_point'], 'undo', - 'Undo last drawn point', enabled=False) + self.tr('Undo last drawn point'), enabled=False) addPointToEdge = action( - 'Add Point to Edge', + self.tr('Add Point to Edge'), self.canvas.addPointToEdge, shortcuts['add_point_to_edge'], 'edit', - 'Add point to the nearest edge', + self.tr('Add point to the nearest edge'), enabled=False, ) - undo = action('Undo', self.undoShapeEdit, shortcuts['undo'], 'undo', - 'Undo last add and edit of shape', enabled=False) + undo = action(self.tr('Undo'), self.undoShapeEdit, shortcuts['undo'], 'undo', + self.tr('Undo last add and edit of shape'), enabled=False) - hideAll = action('&Hide\nPolygons', + hideAll = action(self.tr('&Hide\nPolygons'), functools.partial(self.togglePolygons, False), - icon='eye', tip='Hide all polygons', enabled=False) - showAll = action('&Show\nPolygons', + icon='eye', tip=self.tr('Hide all polygons'), enabled=False) + showAll = action(self.tr('&Show\nPolygons'), functools.partial(self.togglePolygons, True), - icon='eye', tip='Show all polygons', enabled=False) + icon='eye', tip=self.tr('Show all polygons'), enabled=False) - help = action('&Tutorial', self.tutorial, icon='help', - tip='Show tutorial page') + help = action(self.tr('&Tutorial'), self.tutorial, icon='help', + tip=self.tr('Show tutorial page')) zoom = QtWidgets.QWidgetAction(self) zoom.setDefaultWidget(self.zoomWidget) self.zoomWidget.setWhatsThis( - 'Zoom in or out of the image. Also accessible with ' - '{} and {} from the canvas.' + self.tr('Zoom in or out of the image. Also accessible with ' + '{} and {} from the canvas.') .format( utils.fmtShortcut( '{},{}'.format( shortcuts['zoom_in'], shortcuts['zoom_out'] ) ), - utils.fmtShortcut("Ctrl+Wheel"), + utils.fmtShortcut(self.tr("Ctrl+Wheel")), ) ) self.zoomWidget.setEnabled(False) - zoomIn = action('Zoom &In', functools.partial(self.addZoom, 1.1), + zoomIn = action(self.tr('Zoom &In'), functools.partial(self.addZoom, 1.1), shortcuts['zoom_in'], 'zoom-in', - 'Increase zoom level', enabled=False) - zoomOut = action('&Zoom Out', functools.partial(self.addZoom, 0.9), + self.tr('Increase zoom level'), enabled=False) + zoomOut = action(self.tr('&Zoom Out'), functools.partial(self.addZoom, 0.9), shortcuts['zoom_out'], 'zoom-out', - 'Decrease zoom level', enabled=False) - zoomOrg = action('&Original size', + self.tr('Decrease zoom level'), enabled=False) + zoomOrg = action(self.tr('&Original size'), functools.partial(self.setZoom, 100), shortcuts['zoom_to_original'], 'zoom', - 'Zoom to original size', enabled=False) - fitWindow = action('&Fit Window', self.setFitWindow, + self.tr('Zoom to original size'), enabled=False) + fitWindow = action(self.tr('&Fit Window'), self.setFitWindow, shortcuts['fit_window'], 'fit-window', - 'Zoom follows window size', checkable=True, + self.tr('Zoom follows window size'), checkable=True, enabled=False) - fitWidth = action('Fit &Width', self.setFitWidth, + fitWidth = action(self.tr('Fit &Width'), self.setFitWidth, shortcuts['fit_width'], 'fit-width', - 'Zoom follows window width', + self.tr('Zoom follows window width'), checkable=True, enabled=False) # Group zoom controls into a list for easier toggling. zoomActions = (self.zoomWidget, zoomIn, zoomOut, zoomOrg, @@ -382,22 +382,22 @@ class MainWindow(QtWidgets.QMainWindow): self.MANUAL_ZOOM: lambda: 1, } - edit = action('&Edit Label', self.editLabel, shortcuts['edit_label'], - 'edit', 'Modify the label of the selected polygon', + edit = action(self.tr('&Edit Label'), self.editLabel, shortcuts['edit_label'], + 'edit', self.tr('Modify the label of the selected polygon'), enabled=False) shapeLineColor = action( - 'Shape &Line Color', self.chshapeLineColor, icon='color-line', - tip='Change the line color for this specific shape', enabled=False) + self.tr('Shape &Line Color'), self.chshapeLineColor, icon='color-line', + tip=self.tr('Change the line color for this specific shape'), enabled=False) shapeFillColor = action( - 'Shape &Fill Color', self.chshapeFillColor, icon='color', - tip='Change the fill color for this specific shape', enabled=False) + self.tr('Shape &Fill Color'), self.chshapeFillColor, icon='color', + tip=self.tr('Change the fill color for this specific shape'), enabled=False) fill_drawing = action( - 'Fill Drawing Polygon', + self.tr('Fill Drawing Polygon'), lambda x: self.canvas.setFillDrawing(x), None, 'color', - 'Fill polygon while drawing', + self.tr('Fill polygon while drawing'), checkable=True, enabled=True, ) @@ -484,11 +484,11 @@ class MainWindow(QtWidgets.QMainWindow): self.canvas.edgeSelected.connect(self.canvasShapeEdgeSelected) self.menus = utils.struct( - file=self.menu('&File'), - edit=self.menu('&Edit'), - view=self.menu('&View'), - help=self.menu('&Help'), - recentFiles=QtWidgets.QMenu('Open &Recent'), + file=self.menu(self.tr('&File')), + edit=self.menu(self.tr('&Edit')), + view=self.menu(self.tr('&View')), + help=self.menu(self.tr('&Help')), + recentFiles=QtWidgets.QMenu(self.tr('Open &Recent')), labelList=labelMenu, ) @@ -569,7 +569,7 @@ class MainWindow(QtWidgets.QMainWindow): fitWidth, ) - self.statusBar().showMessage('%s started.' % __appname__) + self.statusBar().showMessage(self.tr('%s started.') % __appname__) self.statusBar().show() if output_file is not None and self._config['auto_save']: @@ -885,8 +885,8 @@ class MainWindow(QtWidgets.QMainWindow): if text is None: return if not self.validateLabel(text): - self.errorMessage('Invalid label', - "Invalid label '{}' with validation type '{}'" + self.errorMessage(self.tr('Invalid label'), + self.tr("Invalid label '{}' with validation type '{}'") .format(text, self._config['validate_label'])) return shape.label = text @@ -1050,7 +1050,7 @@ class MainWindow(QtWidgets.QMainWindow): # self.filename = filename return True except LabelFileError as e: - self.errorMessage('Error saving label data', '%s' % e) + self.errorMessage(self.tr('Error saving label data'), self.tr('%s') % e) return False def copySelectedShape(self): @@ -1109,8 +1109,8 @@ class MainWindow(QtWidgets.QMainWindow): self.labelDialog.edit.setText(previous_label) if text and not self.validateLabel(text): - self.errorMessage('Invalid label', - "Invalid label '{}' with validation type '{}'" + self.errorMessage(self.tr('Invalid label'), + self.tr("Invalid label '{}' with validation type '{}'") .format(text, self._config['validate_label'])) text = '' if text: @@ -1190,10 +1190,10 @@ class MainWindow(QtWidgets.QMainWindow): filename = str(filename) if not QtCore.QFile.exists(filename): self.errorMessage( - 'Error opening file', 'No such file: %s' % filename) + self.tr('Error opening file'), self.tr('No such file: %s') % filename) return False # assumes same name, but json extension - self.status("Loading %s..." % osp.basename(str(filename))) + self.status(self.tr("Loading %s...") % osp.basename(str(filename))) label_file = osp.splitext(filename)[0] + '.json' if self.output_dir: label_file_without_path = osp.basename(label_file) @@ -1204,11 +1204,11 @@ class MainWindow(QtWidgets.QMainWindow): self.labelFile = LabelFile(label_file) except LabelFileError as e: self.errorMessage( - 'Error opening file', - "
%s
" - "Make sure %s is a valid label file." + self.tr('Error opening file'), + self.tr("
%s
" + "Make sure %s is a valid label file.") % (e, label_file)) - self.status("Error reading %s" % label_file) + self.status(self.tr("Error reading %s") % label_file) return False self.imageData = self.labelFile.imageData self.imagePath = osp.join( @@ -1231,11 +1231,11 @@ class MainWindow(QtWidgets.QMainWindow): formats = ['*.{}'.format(fmt.data().decode()) for fmt in QtGui.QImageReader.supportedImageFormats()] self.errorMessage( - 'Error opening file', - '
Make sure {0} is a valid image file.
'
- 'Supported image formats: {1}
Make sure {0} is a valid image file.
'
+ 'Supported image formats: {1}