Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make most modules translatable #108

Merged
merged 11 commits into from
Feb 25, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import qt

import slicer
from slicer.i18n import tr as _
from slicer.i18n import translate
from slicer.ScriptedLoadableModule import *
from slicer.util import VTKObservationMixin
from slicer.parameterNodeWrapper import (
Expand All @@ -32,15 +34,15 @@ def __init__(self, parent):
self.parent.dependencies = []
self.parent.contributors = ["Saleem Edah-Tally [Surgeon] [Hobbyist developer]"] # TODO: replace with "Firstname Lastname (Organization)"
# TODO: update with short description of the module and a link to online module documentation
self.parent.helpText = """
self.parent.helpText = _("""
Segment calcifications around an arterial lumen within a margin.
See more information in <a href="href="https://github.com/vmtk/SlicerExtension-VMTK/">module documentation</a>.
"""
""")
# TODO: replace with organization, grant and thanks
self.parent.acknowledgementText = """
self.parent.acknowledgementText = _("""
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc., Andras Lasso, PerkLab,
and Steve Pieper, Isomics, Inc. and was partially funded by NIH grant 3P41RR013218-12S1.
"""
""")

#
# ArterialCalcificationPreProcessorParameterNode
Expand Down Expand Up @@ -102,7 +104,7 @@ def setup(self) -> None:
self.addObserver(slicer.mrmlScene, slicer.mrmlScene.EndCloseEvent, self.onSceneEndClose)

self.ui.applyButton.menu().clear()
self._show3DAction = qt.QAction("Show 3D on success")
self._show3DAction = qt.QAction(_("Show 3D on success"))
self._show3DAction.setCheckable(True)
self.ui.applyButton.menu().addAction(self._show3DAction)

Expand Down Expand Up @@ -177,7 +179,7 @@ def onApplyButton(self) -> None:
inputSegmentation = self.ui.segmentSelector.currentNode()
optionShow3D = self._show3DAction.checked

with slicer.util.tryWithErrorDisplay("Failed to compute results.", waitCursor=True):
with slicer.util.tryWithErrorDisplay(_("Failed to compute results."), waitCursor=True):

# Compute output
self.logic.process(inputSegmentation,
Expand Down Expand Up @@ -214,11 +216,11 @@ def process(self,
marginSize: float = 4.0) -> None:

if not inputSegmentation or not inputVolume or not segmentID or segmentID == "":
raise ValueError("Input segmentation, volume or segment ID is invalid")
raise ValueError(_("Input segmentation, volume or segment ID is invalid"))

import time
startTime = time.time()
logging.info('Processing started')
logging.info(_("Processing started"))

"""
We need the volume to get intensity values.
Expand Down Expand Up @@ -291,7 +293,8 @@ def process(self,
inputSegmentation.GetDisplayNode().SetSegmentOpacity3D(calcifSegmentID, 0.5)

stopTime = time.time()
logging.info(f'Processing completed in {stopTime-startTime:.2f} seconds')
durationValue = '%.2f' % (stopTime-startTime)
logging.info(_("Processing completed in {duration} seconds").format(duration=durationValue))

#
# ArterialCalcificationPreProcessorTest
Expand All @@ -312,6 +315,6 @@ def runTest(self):

def test_ArterialCalcificationPreProcessor1(self):

self.delayDisplay("Starting the test")
self.delayDisplay(_("Starting the test"))

self.delayDisplay('Test passed')
self.delayDisplay(_("Test passed"))
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<double>4.000000000000000</double>
</property>
<property name="SlicerParameterName" stdset="0">
<string>marginSize</string>
<string notr="true">marginSize</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -98,7 +98,7 @@
<string notr="true"/>
</property>
<property name="SlicerParameterName" stdset="0">
<string>inputVolume</string>
<string notr="true">inputVolume</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -139,6 +139,7 @@
<class>qMRMLNodeComboBox</class>
<extends>QWidget</extends>
<header>qMRMLNodeComboBox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qMRMLWidget</class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<string>Pick the input centerline model.</string>
</property>
<property name="nodeTypes">
<stringlist>
<stringlist notr="true">
<string>vtkMRMLModelNode</string>
</stringlist>
</property>
Expand Down Expand Up @@ -82,7 +82,7 @@ The input centerline is expected to be inside the lumen surface.</string>
<locale language="English" country="UnitedStates"/>
</property>
<property name="nodeTypes">
<stringlist>
<stringlist notr="true">
<string>vtkMRMLSegmentationNode</string>
</stringlist>
</property>
Expand Down
54 changes: 29 additions & 25 deletions BranchClipper/qSlicerBranchClipperModuleWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void qSlicerBranchClipperModuleWidget::onApply()
vtkMRMLModelNode * centerlineModel = vtkMRMLModelNode::SafeDownCast( d->inputCenterlineSelector->currentNode());
if (centerlineModel == nullptr)
{
this->showStatusMessage("No centerline selected.", 5000);
this->showStatusMessage(qSlicerBranchClipperModuleWidget::tr("No centerline selected."), 5000);
return;
}
centerlines->DeepCopy(centerlineModel->GetPolyData());
Expand All @@ -98,13 +98,13 @@ void qSlicerBranchClipperModuleWidget::onApply()
vtkMRMLNode * segmentationNode = d->segmentationSelector->currentNode();
if (segmentationNode == nullptr)
{
this->showStatusMessage("No segmentation selected.", 5000);
this->showStatusMessage(qSlicerBranchClipperModuleWidget::tr("No segmentation selected."), 5000);
return;
}
if ((d->bifurcationProfilesToolButton->isChecked() == false)
&& (d->branchSegmentsToolButton->isChecked() == false))
{
this->showStatusMessage("No output selected.", 5000);
this->showStatusMessage(qSlicerBranchClipperModuleWidget::tr("No output selected."), 5000);
return;
}
// Use controlled segment IDs. We can find and delete them precisely.
Expand All @@ -118,8 +118,8 @@ void qSlicerBranchClipperModuleWidget::onApply()
segmentation = vtkMRMLSegmentationNode::SafeDownCast(d->segmentationSelector->currentNode());
if (segmentation->GetSegmentation() == nullptr) // Can it happen ?
{
const char * msg = "Segmentation is NULL in MRML node, aborting";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Segmentation is NULL in MRML node, aborting");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
Expand All @@ -129,7 +129,7 @@ void qSlicerBranchClipperModuleWidget::onApply()
segmentID = d->segmentSelector->currentSegmentID().toStdString();
if (segmentID.empty())
{
const char * msg = "No segment selected.";
const QString msg = qSlicerBranchClipperModuleWidget::tr("No segment selected.");
this->showStatusMessage(msg, 5000);
return;
}
Expand All @@ -140,17 +140,17 @@ void qSlicerBranchClipperModuleWidget::onApply()
}
else
{
const char * msg = "Could not create closed surface representation.";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Could not create closed surface representation.");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
}
else
{
// Should not happen.
const char * msg = "Unknown surface node";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Unknown surface node");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
Expand All @@ -159,15 +159,16 @@ void qSlicerBranchClipperModuleWidget::onApply()

// Debranch now. Execute() can be a long process on heavy segmentations.
timer->StartTimer();
this->showStatusMessage("Debranching, please wait...");
this->showStatusMessage(qSlicerBranchClipperModuleWidget::tr("Debranching, please wait..."));

vtkNew<vtkSlicerBranchClipperLogic> logic;
logic->SetCenterlines(centerlines);
logic->SetSurface(surface);
logic->Execute();
if (logic->GetOutput() == nullptr)
{
const char * msg = "Could not create a valid surface.";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Could not create a valid surface.");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
Expand All @@ -186,26 +187,29 @@ void qSlicerBranchClipperModuleWidget::onApply()
if (numberOfBranches == 0)
{
mrmlScene()->EndState(vtkMRMLScene::BatchProcessState);
const char * msg = "No branches could be retrieved; the centerline may be invalid.";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("No branches could be retrieved; the centerline may be invalid.");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
for (vtkIdType i = 0; i < numberOfBranches; i++)
{
timer->StartTimer();
std::string info("Processing branch ");
std::string info(qSlicerBranchClipperModuleWidget::tr("Processing branch ").toStdString());
info += std::to_string(i + 1) + std::string("/") + std::to_string(numberOfBranches);
cout << info; // no endl
this->showStatusMessage(info.c_str());

std::string consoleInfo("Processing branch ");
consoleInfo += std::to_string(i + 1) + std::string("/") + std::to_string(numberOfBranches);
cout << consoleInfo; // no endl

vtkNew<vtkPolyData> branchSurface;
logic->GetBranch(i, branchSurface);
if (branchSurface == nullptr)
{
cout << endl;
const char * msg = "Could not retrieve branch surface ";
cerr << msg << i << "." << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Could not retrieve branch surface ");
cerr << msg.toStdString() << i << "." << endl;
this->showStatusMessage(msg, 5000);
continue;
}
Expand Down Expand Up @@ -260,17 +264,17 @@ void qSlicerBranchClipperModuleWidget::onApply()
if (!profiledPolyDatas)
{
mrmlScene()->EndState(vtkMRMLScene::BatchProcessState);
const char * msg = "Could not get a valid collection of bifurcation profiles.";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Could not get a valid collection of bifurcation profiles.");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
vtkMRMLSubjectHierarchyNode * shNode = mrmlScene()->GetSubjectHierarchyNode();
if (shNode == nullptr) // ?
{
mrmlScene()->EndState(vtkMRMLScene::BatchProcessState);
const char * msg = "Could not get a valid subject hierarchy node.";
cerr << msg << endl;
const QString msg = qSlicerBranchClipperModuleWidget::tr("Could not get a valid subject hierarchy node.");
cerr << msg.toStdString() << endl;
this->showStatusMessage(msg, 5000);
return;
}
Expand All @@ -279,7 +283,7 @@ void qSlicerBranchClipperModuleWidget::onApply()

// Create a child folder of the input centerline to contain all created models.
vtkIdType shMasterCenterlineId = shNode->GetItemByDataNode(centerlineModel);
vtkIdType shFolderId = shNode->CreateFolderItem(shMasterCenterlineId, "Bifurcation profiles");
vtkIdType shFolderId = shNode->CreateFolderItem(shMasterCenterlineId, qSlicerBranchClipperModuleWidget::tr("Bifurcation profiles").toStdString());
shNode->SetItemExpanded(shFolderId, false);
// Seed with a constant for predictable random table and colours.
vtkMath::RandomSeed(7);
Expand All @@ -305,7 +309,7 @@ void qSlicerBranchClipperModuleWidget::onApply()
}

mrmlScene()->EndState(vtkMRMLScene::BatchProcessState);
this->showStatusMessage("Finished", 5000);
this->showStatusMessage(qSlicerBranchClipperModuleWidget::tr("Finished"), 5000);
}

//-------------------------- From util.py -------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions CenterlineDisassembly/CenterlineDisassembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ def createCenterlineCurve(self, centerlinePolyData, curveNode):
curveNode.SetName(curveName)

stopTime = time.time()
logging.info(f"Processing curve creation completed in {stopTime-startTime:.2f} seconds")
durationValue = '%.2f' % (stopTime-startTime)
logging.info(_("Processing curve creation completed in {duration} seconds").format(duration=durationValue))

def processCenterlineIds(self):

Expand Down Expand Up @@ -514,7 +515,8 @@ def processCenterlineIds(self):
centerlinePolyDatas.append(appendPolyData.GetOutput())

stopTime = time.time()
logging.info(f"Processing centerline ids completed in {stopTime-startTime:.2f} seconds")
durationValue = '%.2f' % (stopTime-startTime)
logging.info(_("Processing centerline ids completed in {duration} seconds").format(duration=durationValue))
return centerlinePolyDatas

def processGroupIds(self, bifurcations):
Expand Down Expand Up @@ -556,7 +558,8 @@ def processGroupIds(self, bifurcations):
groupIdsPolyDatas.append(unitCellPolyData)

stopTime = time.time()
logging.info(f"Processing group ids completed in {stopTime-startTime:.2f} seconds")
durationValue = '%.2f' % (stopTime-startTime)
logging.info(_("Processing group ids completed in {duration} seconds").format(duration=durationValue))
return groupIdsPolyDatas
#
# CenterlineDisassemblyTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Upon curve creation, the visibility of the names can be specified via the menu.<
<class>qMRMLNodeComboBox</class>
<extends>QWidget</extends>
<header>qMRMLNodeComboBox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qMRMLWidget</class>
Expand Down