Skip to content

Commit

Permalink
BUG: Mark translatable strings in module ExtensionWizard
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedAllali committed May 21, 2024
2 parents 021a8be + 7038c73 commit c034056
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 44 deletions.
23 changes: 14 additions & 9 deletions Modules/Scripted/ExtensionWizard/ExtensionWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ def setupTemplates(self):
try:
self.templateManager.addPath(builtinPath)
except:

qt.qWarning(_("failed to add built-in template {path}").format(path=builtinPath))

qt.qWarning(traceback.format_exc())

# Read base template paths
Expand All @@ -198,7 +200,9 @@ def setupTemplates(self):
try:
self.templateManager.addPath(path)
except:

qt.qWarning(_("failed to add template {path}").format(path=path)

qt.qWarning(traceback.format_exc())

# Read per-category template paths
Expand Down Expand Up @@ -243,7 +247,7 @@ def createExtension(self):
" directory containing CMakeLists.txt file at '%s'" % dlg.destination)

path = self.templateManager.copyTemplate(
destination, _("extensions"),
destination, "extensions",
dlg.componentType, dlg.componentName,
createInSubdirectory, requireEmptyDirectory)

Expand Down Expand Up @@ -301,7 +305,7 @@ def selectExtension(self, path=None):
self.extensionNameField.text = xp.project
self.extensionLocationField.text = path

if xd.scmurl == _("NA"):
if xd.scmurl == "NA":
if repo is None:
repoText = _("(none)")
elif hasattr(repo, _("remotes")):
Expand Down Expand Up @@ -339,7 +343,7 @@ def loadModules(path=None, depth=1, modules=None, parent=None):
# Get list of modules in specified path
modules = ModuleInfo.findModules(path, depth)
elif modules is None:
raise RuntimeError("loadModules require 'path' or _('modules') input")
raise RuntimeError("loadModules require 'path' or 'modules' input")

# Determine which modules in above are not already loaded
factory = slicer.app.moduleManager().factoryManager()
Expand All @@ -358,7 +362,7 @@ def loadModules(path=None, depth=1, modules=None, parent=None):
# Add module(s) to permanent search paths, if requested
if dlg.addToSearchPaths:
settings = slicer.app.revisionUserSettings()
rawSearchPaths = list(_settingsList(settings, _("Modules/AdditionalPaths"), convertToAbsolutePaths=True))
rawSearchPaths = list(_settingsList(settings, "Modules/AdditionalPaths", convertToAbsolutePaths=True))
searchPaths = [qt.QDir(path) for path in rawSearchPaths]
modified = False

Expand All @@ -371,11 +375,11 @@ def loadModules(path=None, depth=1, modules=None, parent=None):
modified = True

if modified:
settings.setValue(_("Modules/AdditionalPaths"), slicer.app.toSlicerHomeRelativePaths(rawSearchPaths))
settings.setValue("Modules/AdditionalPaths", slicer.app.toSlicerHomeRelativePaths(rawSearchPaths))

# Enable developer mode (shows Reload&Test section, etc.), if requested
if dlg.enableDeveloperMode:
qt.QSettings().setValue(_("Developer/DeveloperMode"), _("true"))
qt.QSettings().setValue("Developer/DeveloperMode", "true")

# Register requested module(s)
failed = []
Expand All @@ -389,7 +393,8 @@ def loadModules(path=None, depth=1, modules=None, parent=None):
if len(failed) > 1:
text = _("{count} modules could not be registered")
else:
text = _("The '%s' module could not be registered:") % failed[0].key
# text = _("The '%s' module could not be registered:") % failed[0].key
text = _("The {ExtensionWizard} module could not be registered").format(ExtensionWizard=failed[0].key)

failedFormat = "<ul><li>%(key)s<br/>(%(path)s)</li></ul>"
detailedInformation = "".join(
Expand Down Expand Up @@ -417,7 +422,7 @@ def createExtensionModule(self):

dlg = CreateComponentDialog(_("module"), self.parent.window())
dlg.setTemplates(self.templateManager.templates("modules"),
default=_"scripted")
default="scripted")
dlg.showDestination = False

while dlg.exec_() == qt.QDialog.Accepted:
Expand Down Expand Up @@ -478,7 +483,7 @@ def editExtensionMetadata(self):


#
# ExtentsionWizardFileDialog
# ExtentsionWizardFileDialog
#
class ExtensionWizardFileDialog:
"""This specially named class is detected by the scripted loadable
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(_("%s name may not be empty.") % self._typetc,
windowTitle=_("Cannot create %s") % 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 %s") % 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)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .EditableTreeWidget import EditableTreeWidget

from slicer.i18n import tr as _

# -----------------------------------------------------------------------------
def _map_property(objfunc, name):
Expand All @@ -25,18 +26,21 @@ def __init__(self, parent):
formLayout = qt.QFormLayout()

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

self.categoryEdit = qt.QLineEdit()
formLayout.addRow(_("Category:"), self.categoryEdit)

self.descriptionEdit = qt.QTextEdit()
self.descriptionEdit.acceptRichText = False
formLayout.addRow("Description:", self.descriptionEdit)
formLayout.addRow(_("Description:"), self.descriptionEdit)

self.contributorsList = EditableTreeWidget()
self.contributorsList.rootIsDecorated = False
self.contributorsList.selectionBehavior = qt.QAbstractItemView.SelectRows
self.contributorsList.selectionMode = qt.QAbstractItemView.ExtendedSelection
self.contributorsList.setHeaderLabels(["Name", "Organization"])
formLayout.addRow("Contributors:", self.contributorsList)
self.contributorsList.setHeaderLabels([_("Name"), _("Organization")])
formLayout.addRow(_("Contributors:"), self.contributorsList)

vLayout.addLayout(formLayout)
vLayout.addStretch(1)
Expand All @@ -53,9 +57,15 @@ def __init__(self, parent):
#
# =============================================================================
class EditExtensionMetadataDialog:

project = _map_property(lambda self: self.ui.nameEdit, "text")
description = _map_property(lambda self: self.ui.descriptionEdit, "plainText")

project = _map_property(lambda self: self.ui.nameEdit, "text")
category = _map_property(lambda self: self.ui.categoryEdit, "text")
description = _map_property(lambda self: self.ui.descriptionEdit, "plainText")


# ---------------------------------------------------------------------------
def __init__(self, parent):
self.dialog = qt.QDialog(parent)
Expand All @@ -67,12 +77,12 @@ def __init__(self, parent):
# ---------------------------------------------------------------------------
def accept(self):
if not len(self.project):
slicer.util.errorDisplay("Extension name may not be empty.", windowTitle="Invalid metadata", parent=self.dialog)
slicer.util.errorDisplay(_("Extension name may not be empty."), windowTitle=_("Invalid metadata"), parent=self.dialog)
return

if not len(self.description):
slicer.util.errorDisplay("Extension description may not be empty.",
windowTitle="Invalid metadata", parent=self.dialog)
slicer.util.errorDisplay(_("Extension description may not be empty."),
windowTitle=_("Invalid metadata"), parent=self.dialog)
return

self.dialog.accept()
Expand Down Expand Up @@ -109,7 +119,7 @@ def contributors(self, value):
item.setText(1, c[n + 1 : -1].strip())

except ValueError:
qt.qWarning("%r: badly formatted contributor" % c)
qt.qWarning(_("%r: badly formatted contributor") % c)
item.setText(0, c)

self.ui.contributorsList.addItem(item)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import qt

from slicer.i18n import tr as _

# -----------------------------------------------------------------------------
def _makeAction(parent, text, icon=None, shortcut=None, slot=None):
Expand Down Expand Up @@ -27,7 +28,7 @@ def _newItemPlaceholderItem(parent):
color.setAlphaF(0.5)

item = qt.QTreeWidgetItem()
item.setText(0, "(New item)")
item.setText(0, _("(New item)"))
item.setForeground(0, qt.QBrush(color))

return item
Expand All @@ -48,17 +49,17 @@ def __init__(self, *args, **kwargs):
self.addItem(_newItemPlaceholderItem(self), placeholder=True)

# Set up context menu
self._shiftUpAction = _makeAction(self, text="Move &Up",
self._shiftUpAction = _makeAction(self, text=_("Move &Up"),
icon="arrow-up",
shortcut="ctrl+shift+up",
slot=self.shiftSelectionUp)

self._shiftDownAction = _makeAction(self, text="Move &Down",
self._shiftDownAction = _makeAction(self, text=_("Move &Down"),
icon="arrow-down",
shortcut="ctrl+shift+down",
slot=self.shiftSelectionDown)

self._deleteAction = _makeAction(self, text="&Delete", icon="edit-delete",
self._deleteAction = _makeAction(self, text=_("&Delete"), icon="edit-delete",
shortcut="del", slot=self.deleteSelection)

self.contextMenuPolicy = qt.Qt.ActionsContextMenu
Expand Down Expand Up @@ -126,7 +127,7 @@ def updateItemData(self, item, column):
# Remove placeholder effect from new item
item.setData(0, qt.Qt.ForegroundRole, None)
if column != 0:
item.setText(0, "Anonymous")
item.setText(0, _("Anonymous"))

# Update actions so new item can be moved/deleted
self.updateActions()
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 _

# -----------------------------------------------------------------------------
def _dialogIcon(icon):
Expand Down Expand Up @@ -40,8 +41,12 @@ def __init__(self, parent):
self.addToSearchPaths.checked = True

self.enableDeveloperMode = qt.QCheckBox()
self.enableDeveloperMode.text = "Enable developer mode"
self.enableDeveloperMode.toolTip = "Sets the 'Developer mode' application option to enabled. Enabling developer mode is recommended while developing scripted modules, as it makes the Reload and Testing section displayed in the module user interface."
self.enableDeveloperMode.text = _("Enable developer mode")
self.enableDeveloperMode.toolTip = _("Sets the 'Developer mode' "
"application option to enabled. Enabling developer mode is "
"recommended while developing scripted modules, as it makes "
"the Reload and Testing section displayed in "
"the module user interface.")
self.enableDeveloperMode.checked = True
vLayout.addWidget(self.enableDeveloperMode)

Expand Down Expand Up @@ -81,9 +86,9 @@ def validate(self):
self.ui.addToSearchPaths.enabled = True

if moduleCount == 1:
self.ui.addToSearchPaths.text = "Add selected module to 'Additional module paths'"
self.ui.addToSearchPaths.text = _("Add selected module to 'Additional module paths'")
else:
self.ui.addToSearchPaths.text = "Add selected modules to 'Additional module paths'"
self.ui.addToSearchPaths.text = _("Add selected modules to 'Additional module paths'")

# If developer mode is already enabled then don't even show the option
developerModeAlreadyEnabled = slicer.util.settingsValue("Developer/DeveloperMode", False, converter=slicer.util.toBool)
Expand All @@ -108,17 +113,17 @@ def setModules(self, modules):
self._moduleItems[item] = module

if len(modules) > 1:
self.ui.label.text = (
self.ui.label.text = _(
"The following modules can be loaded. "
"Would you like to load them now?")

elif len(modules) == 1:
self.ui.label.text = (
self.ui.label.text = _(
"The following module can be loaded. "
"Would you like to load it now?")

else:
raise ValueError("At least one module must be provided")
raise ValueError(_("At least one module must be provided"))

self.validate()

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

from .DirectoryListWidget import DirectoryListWidget
from .TemplatePathUtilities import *

from slicer.i18n import tr as _

# =============================================================================
#
Expand All @@ -22,19 +22,19 @@ def __init__(self, parent):
if builtinPath:
self.builtinPath.text = builtinPath
else:
self.builtinPath.text = "(Unavailable)"
self.builtinPath.text = _("(Unavailable)")
self.builtinPath.enabled = False
self.builtinPath.readOnly = True
self.addRow("Built-in template path:", self.builtinPath)
self.addRow(_("Built-in template path:"), self.builtinPath)

self.genericPaths = DirectoryListWidget()
self.addRow("Additional template\npaths:", self.genericPaths)
self.addRow(_("Additional template\npaths:"), self.genericPaths)

self.paths = {}

for category in SlicerWizard.TemplateManager.categories():
self.paths[category] = DirectoryListWidget()
self.addRow("Additional template\npaths for %s:" % category,
self.addRow(_("Additional template\npaths for %s:") % category,
self.paths[category])

# ---------------------------------------------------------------------------
Expand Down

0 comments on commit c034056

Please sign in to comment.