Skip to content

Commit

Permalink
BUG: Mark translatable strings in ExtensionWizard and Terminologies
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedAllali authored and lassoan committed Jun 1, 2024
1 parent 43024e6 commit 1edcf59
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 85 deletions.
5 changes: 3 additions & 2 deletions Modules/Loadable/Terminologies/qSlicerTerminologiesModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ qSlicerTerminologiesModule::~qSlicerTerminologiesModule() = default;
QString qSlicerTerminologiesModule::helpText()const
{
QString help =
"The Terminologies module enables viewing and editing terminology dictionaries used for segmentation.";
tr("The Terminologies module enables viewing and editing terminology dictionaries used for segmentation.");
help += this->defaultDocumentationLink();
return help;
}

//-----------------------------------------------------------------------------
QString qSlicerTerminologiesModule::acknowledgementText()const
{
return "This work is part of SparKit project, funded by Cancer Care Ontario (CCO)'s ACRU program and Ontario Consortium for Adaptive Interventions in Radiation Oncology (OCAIRO).";
return tr("This work is part of SparKit project, funded by Cancer Care Ontario (CCO)'s ACRU program"
" and Ontario Consortium for Adaptive Interventions in Radiation Oncology (OCAIRO).");
}

//-----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ vtkSlicerTerminologiesModuleLogic* qSlicerTerminologiesReader::terminologiesLogi
//-----------------------------------------------------------------------------
QString qSlicerTerminologiesReader::description()const
{
return "Terminology";
return tr("Terminology");
}

//-----------------------------------------------------------------------------
Expand Down
83 changes: 41 additions & 42 deletions Modules/Scripted/ExtensionWizard/ExtensionWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

from ExtensionWizardLib import *

from slicer.i18n import tr as _
from slicer.i18n import translate


# -----------------------------------------------------------------------------
def _settingsList(settings, key, convertToAbsolutePaths=False):
Expand Down Expand Up @@ -41,17 +44,13 @@ def _settingsList(settings, key, convertToAbsolutePaths=False):
class ExtensionWizard:
# ---------------------------------------------------------------------------
def __init__(self, parent):
parent.title = "Extension Wizard"
parent.title = _("Extension Wizard")
parent.icon = qt.QIcon(":/Icons/Medium/ExtensionWizard.png")
parent.categories = ["Developer Tools"]
parent.categories = [translate("qSlicerAbstractCoreModule", "Developer Tools")]
parent.dependencies = []
parent.contributors = ["Matthew Woehlke (Kitware)"]
parent.helpText = """
This module provides tools to create and manage extensions from within Slicer.
"""
parent.acknowledgementText = """
This work is supported by NA-MIC, NAC, BIRN, NCIGT, and the Slicer Community.
"""
parent.helpText = _("This module provides tools to create and manage extensions from within Slicer.")
parent.acknowledgementText = _("This work is supported by NA-MIC, NAC, BIRN, NCIGT, and the Slicer Community.")
self.parent = parent

self.settingsPanel = SettingsPanel()
Expand Down Expand Up @@ -122,13 +121,13 @@ def createReadOnlyLineEdit():
# Tools Area
#
self.toolsCollapsibleButton = ctk.ctkCollapsibleButton()
self.toolsCollapsibleButton.text = "Extension Tools"
self.toolsCollapsibleButton.text = _("Extension Tools")
self.layout.addWidget(self.toolsCollapsibleButton)

self.createExtensionButton = createToolButton("Create Extension")
self.createExtensionButton = createToolButton(_("Create Extension"))
self.createExtensionButton.connect("clicked(bool)", self.createExtension)

self.selectExtensionButton = createToolButton("Select Extension")
self.selectExtensionButton = createToolButton(_("Select Extension"))
self.selectExtensionButton.connect("clicked(bool)", self.selectExtension)

toolsLayout = qt.QVBoxLayout(self.toolsCollapsibleButton)
Expand All @@ -139,7 +138,7 @@ def createReadOnlyLineEdit():
# Editor Area
#
self.editorCollapsibleButton = ctk.ctkCollapsibleButton()
self.editorCollapsibleButton.text = "Extension Editor"
self.editorCollapsibleButton.text = _("Extension Editor")
self.editorCollapsibleButton.enabled = False
self.editorCollapsibleButton.collapsed = True
self.layout.addWidget(self.editorCollapsibleButton)
Expand All @@ -154,19 +153,19 @@ def createReadOnlyLineEdit():
self.extensionContentsView.sortingEnabled = True
self.extensionContentsView.hideColumn(3)

self.createExtensionModuleButton = createToolButton("Add Module to Extension")
self.createExtensionModuleButton = createToolButton(_("Add Module to Extension"))
self.createExtensionModuleButton.connect("clicked(bool)",
self.createExtensionModule)

self.editExtensionMetadataButton = createToolButton("Edit Extension Metadata")
self.editExtensionMetadataButton = createToolButton(_("Edit Extension Metadata"))
self.editExtensionMetadataButton.connect("clicked(bool)",
self.editExtensionMetadata)

editorLayout = qt.QFormLayout(self.editorCollapsibleButton)
editorLayout.addRow("Name:", self.extensionNameField)
editorLayout.addRow("Location:", self.extensionLocationField)
editorLayout.addRow("Repository:", self.extensionRepositoryField)
editorLayout.addRow("Contents:", self.extensionContentsView)
editorLayout.addRow(_("Name:"), self.extensionNameField)
editorLayout.addRow(_("Location:"), self.extensionLocationField)
editorLayout.addRow(_("Repository:"), self.extensionRepositoryField)
editorLayout.addRow(_("Contents:"), self.extensionContentsView)
editorLayout.addRow(self.createExtensionModuleButton)
editorLayout.addRow(self.editExtensionMetadataButton)

Expand All @@ -186,7 +185,7 @@ def setupTemplates(self):
try:
self.templateManager.addPath(builtinPath)
except:
qt.qWarning("failed to add built-in template path %r" % builtinPath)
qt.qWarning(f"failed to add built-in template {builtinPath}")
qt.qWarning(traceback.format_exc())

# Read base template paths
Expand All @@ -195,7 +194,7 @@ def setupTemplates(self):
try:
self.templateManager.addPath(path)
except:
qt.qWarning("failed to add template path %r" % path)
qt.qWarning(f"failed to add template {path}")
qt.qWarning(traceback.format_exc())

# Read per-category template paths
Expand All @@ -206,7 +205,7 @@ def setupTemplates(self):
self.templateManager.addCategoryPath(c, path)
except:
mp = (c, path)
qt.qWarning("failed to add template path %r for category %r" % mp)
qt.qWarning(f"failed to add template {path} for category {c}")
qt.qWarning(traceback.format_exc())

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -245,7 +244,7 @@ def createExtension(self):
createInSubdirectory, requireEmptyDirectory)

except:
if not slicer.util.confirmRetryCloseDisplay("An error occurred while trying to create the extension.",
if not slicer.util.confirmRetryCloseDisplay(_("An error occurred while trying to create the extension."),
parent=self.parent.window(), detailedText=traceback.format_exc()):
return

Expand All @@ -260,7 +259,7 @@ def createExtension(self):
def selectExtension(self, path=None):
if path is None or isinstance(path, bool):
path = qt.QFileDialog.getExistingDirectory(
self.parent.window(), "Select Extension...",
self.parent.window(), _("Select Extension..."),
self.extensionLocation)

if not len(path):
Expand All @@ -286,7 +285,7 @@ def selectExtension(self, path=None):
xp = SlicerWizard.ExtensionProject(path)

except:
slicer.util.errorDisplay("Failed to open extension '%s'." % path, parent=self.parent.window(),
slicer.util.errorDisplay(_("Failed to open extension {path}.").format(path=path), parent=self.parent.window(),
detailedText=traceback.format_exc(), standardButtons=qt.QMessageBox.Close)
return False

Expand All @@ -300,11 +299,11 @@ def selectExtension(self, path=None):

if xd.scmurl == "NA":
if repo is None:
repoText = "(none)"
repoText = _("(none)")
elif hasattr(repo, "remotes"):
repoText = "(local git repository)"
repoText = _("(local git repository)")
else:
repoText = "(unknown local repository)"
repoText = _("(unknown local repository)")

self.extensionRepositoryField.clear()
self.extensionRepositoryField.placeholderText = repoText
Expand Down Expand Up @@ -384,25 +383,25 @@ def loadModules(path=None, depth=1, modules=None, parent=None):

if len(failed):
if len(failed) > 1:
text = "The following modules could not be registered:"
text = _("{count} modules could not be registered").format(count=count)
else:
text = "The '%s' module could not be registered:" % failed[0].key
text = _("The {name} module could not be registered").format(name=failed[0].key)

failedFormat = "<ul><li>%(key)s<br/>(%(path)s)</li></ul>"
detailedInformation = "".join(
[failedFormat % m.__dict__ for m in failed])

slicer.util.errorDisplay(text, parent=parent, windowTitle="Module loading failed",
slicer.util.errorDisplay(text, parent=parent, windowTitle=_("Module loading failed"),
standardButtons=qt.QMessageBox.Close, informativeText=detailedInformation)

return

# Instantiate and load requested module(s)
if not factory.loadModules([module.key for module in modulesToLoad]):
text = ("The module factory manager reported an error. "
text = _("The module factory manager reported an error. "
"One or more of the requested module(s) and/or "
"dependencies thereof may not have been loaded.")
slicer.util.errorDisplay(text, parent=parent, windowTitle="Error loading module(s)",
slicer.util.errorDisplay(text, parent=parent, windowTitle=_("Error loading module(s)"),
standardButtons=qt.QMessageBox.Close)

# ---------------------------------------------------------------------------
Expand All @@ -425,7 +424,7 @@ def createExtensionModule(self):
dlg.componentType, name)

except:
if not slicer.util.confirmRetryCloseDisplay("An error occurred while trying to create the module.",
if not slicer.util.confirmRetryCloseDisplay(_("An error occurred while trying to create the module."),
parent=self.parent.window(),
detailedText=traceback.format_exc()):
return
Expand All @@ -437,12 +436,12 @@ def createExtensionModule(self):
self.extensionProject.save()

except:
text = "An error occurred while adding the module to the extension."
detailedInformation = "The module has been created, but the extension" \
" CMakeLists.txt could not be updated. In order" \
" to include the module in the extension build," \
" you will need to update the extension" \
" CMakeLists.txt by hand."
text = _("An error occurred while adding the module to the extension.")
detailedInformation = _("The module has been created, but the extension"
" CMakeLists.txt could not be updated. In order"
" to include the module in the extension build,"
" you will need to update the extension"
" CMakeLists.txt by hand.")
slicer.util.errorDisplay(text, parent=self.parent.window(), detailedText=traceback.format_exc(),
standardButtons=qt.QMessageBox.Close, informativeText=detailedInformation)

Expand Down Expand Up @@ -475,7 +474,7 @@ def editExtensionMetadata(self):


#
# ExtentsionWizardFileDialog
# ExtensionWizardFileDialog
#
class ExtensionWizardFileDialog:
"""This specially named class is detected by the scripted loadable
Expand All @@ -489,8 +488,8 @@ class ExtensionWizardFileDialog:

def __init__(self, qSlicerFileDialog):
self.qSlicerFileDialog = qSlicerFileDialog
qSlicerFileDialog.fileType = "Python scripted modules"
qSlicerFileDialog.description = "Add Python scripted modules to the application"
qSlicerFileDialog.fileType = _("Python scripted modules")
qSlicerFileDialog.description = _("Add Python scripted modules to the application")
qSlicerFileDialog.action = slicer.qSlicerFileDialog.Read
self.foundModules = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import slicer

from slicer.i18n import tr as _


# =============================================================================
#
Expand All @@ -18,18 +20,18 @@ def __init__(self, parent):
self.formLayout = qt.QFormLayout()

self.componentName = qt.QLineEdit()
self.formLayout.addRow("Name:", self.componentName)
self.formLayout.addRow(_("Name:"), self.componentName)

self.componentNameValidator = qt.QRegExpValidator(
qt.QRegExp(r"^[a-zA-Z_][a-zA-Z0-9_]*$"))
self.componentName.setValidator(self.componentNameValidator)

self.componentType = qt.QComboBox()
self.formLayout.addRow("Type:", self.componentType)
self.formLayout.addRow(_("Type:"), self.componentType)

self.destination = ctk.ctkPathLineEdit()
self.destination.filters = ctk.ctkPathLineEdit.Dirs
self.formLayout.addRow("Destination:", self.destination)
self.formLayout.addRow(_("Destination:"), self.destination)

self.vLayout.addLayout(self.formLayout)
self.vLayout.addStretch(1)
Expand Down Expand Up @@ -60,15 +62,15 @@ def __init__(self, componenttype, parent):
# ---------------------------------------------------------------------------
def accept(self):
if not len(self.componentName):
slicer.util.errorDisplay("%s name may not be empty." % self._typetc,
windowTitle="Cannot create %s" % self._typelc, parent=self.dialog)
slicer.util.errorDisplay(_("{type} name may not be empty.").format(type=self._typetc),
windowTitle=_("Cannot create {type}").format(type=self._typelc), parent=self.dialog)
return

if self.showDestination:
dest = self.destination
if not len(dest) or not os.path.exists(dest):
slicer.util.errorDisplay("Destination must be an existing directory.",
windowTitle="Cannot create %s" % self._typelc, parent=self.dialog)
slicer.util.errorDisplay(_("Destination must be an existing directory."),
windowTitle=_("Cannot create {type}").format(type=self._typelc), parent=self.dialog)
return

self.dialog.accept()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import slicer

from slicer.i18n import tr as _

# =============================================================================
#
Expand All @@ -18,12 +19,12 @@ def __init__(self, parent):

self.addPathButton = qt.QToolButton()
self.addPathButton.icon = qt.QIcon.fromTheme("list-add")
self.addPathButton.text = "Add"
self.addPathButton.text = _("Add")
layout.addWidget(self.addPathButton, 0, 1)

self.removePathButton = qt.QToolButton()
self.removePathButton.icon = qt.QIcon.fromTheme("list-remove")
self.removePathButton.text = "Remove"
self.removePathButton.text = _("Remove")
layout.addWidget(self.removePathButton, 1, 1)


Expand All @@ -44,6 +45,6 @@ def __init__(self, *args, **kwargs):

# ---------------------------------------------------------------------------
def addDirectory(self):
path = qt.QFileDialog.getExistingDirectory(self.window(), "Select folder")
path = qt.QFileDialog.getExistingDirectory(self.window(), _("Select folder"))
if len(path):
self.ui.pathList.addDirectory(path)
Loading

0 comments on commit 1edcf59

Please sign in to comment.