Skip to content

Commit 9b6c71b

Browse files
committed
ENH: i18n: Improve translation support
This commit adds or improves support for text translation of: * the main window (strings in module panel, and action in the toolbar) * loadable module by updating build system * MRML libraries by updating build system * Modules: * SceneView by ensuring the title is translatable. * SampleData by translating associated file menu action
1 parent 69e135e commit 9b6c71b

File tree

6 files changed

+91
-18
lines changed

6 files changed

+91
-18
lines changed

Applications/SlicerApp/qSlicerAppMainWindow.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ void qSlicerAppMainWindowPrivate::setupUi(QMainWindow * mainWindow)
162162
//----------------------------------------------------------------------------
163163
// ModulePanel
164164
//----------------------------------------------------------------------------
165-
this->PanelDockWidget->toggleViewAction()->setText("&Module Panel");
165+
this->PanelDockWidget->toggleViewAction()->setText(qSlicerAppMainWindow::tr("&Module Panel"));
166166
this->PanelDockWidget->toggleViewAction()->setToolTip(
167-
q->tr("Collapse/Expand the GUI panel and allows Slicer's viewers to occupy "
167+
qSlicerAppMainWindow::tr("Collapse/Expand the GUI panel and allows Slicer's viewers to occupy "
168168
"the entire application window"));
169169
this->PanelDockWidget->toggleViewAction()->setShortcut(QKeySequence("Ctrl+5"));
170170
this->ViewMenu->insertAction(this->WindowToolBarsMenu->menuAction(),
@@ -510,8 +510,8 @@ void qSlicerAppMainWindowPrivate::setupUi(QMainWindow * mainWindow)
510510
QObject::connect(q->pythonConsole(), SIGNAL(aboutToExecute(const QString&)),
511511
q, SLOT(onPythonConsoleUserInput(const QString&)));
512512
// Set up show/hide action
513-
this->PythonConsoleToggleViewAction->setText(q->tr("&Python Interactor"));
514-
this->PythonConsoleToggleViewAction->setToolTip(q->tr(
513+
this->PythonConsoleToggleViewAction->setText(qSlicerAppMainWindow::tr("&Python Interactor"));
514+
this->PythonConsoleToggleViewAction->setToolTip(qSlicerAppMainWindow::tr(
515515
"Show Python Interactor window for controlling the application's data, user interface, and internals"));
516516
this->PythonConsoleToggleViewAction->setShortcut(QKeySequence("Ctrl+3"));
517517
QObject::connect(this->PythonConsoleToggleViewAction, SIGNAL(toggled(bool)),

CMake/SlicerMacroBuildLoadableModule.cmake

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,63 @@ macro(slicerMacroBuildLoadableModule)
179179
${dynamicHeaders}
180180
)
181181

182+
# --------------------------------------------------------------------------
183+
# Translation
184+
# --------------------------------------------------------------------------
185+
if(Slicer_BUILD_I18N_SUPPORT)
186+
set(TS_DIR
187+
"${CMAKE_CURRENT_SOURCE_DIR}/Resources/Translations/"
188+
)
189+
get_property(Slicer_LANGUAGES GLOBAL PROPERTY Slicer_LANGUAGES)
190+
191+
192+
# Check translation file existence.
193+
set(TS_FILE_EXIST TRUE)
194+
foreach(language ${Slicer_LANGUAGES})
195+
if(NOT EXISTS "${TS_DIR}${LOADABLEMODULE_NAME}_${language}.ts")
196+
message(STATUS "[DTC] ${TS_DIR}${LOADABLEMODULE_NAME}_${language}.ts exist")
197+
198+
SET(TS_FILE_EXIST FALSE)
199+
break()
200+
endif()
201+
endforeach()
202+
203+
if(TS_FILE_EXIST)
204+
include(SlicerMacroTranslation)
205+
SlicerMacroTranslation(
206+
SRCS ${LOADABLEMODULE_SRCS}
207+
UI_SRCS ${LOADABLEMODULE_UI_SRCS}
208+
TS_DIR ${TS_DIR}
209+
TS_BASEFILENAME ${LOADABLEMODULE_NAME}
210+
TS_LANGUAGES ${Slicer_LANGUAGES}
211+
QM_OUTPUT_DIR_VAR QM_OUTPUT_DIR
212+
QM_OUTPUT_FILES_VAR QM_OUTPUT_FILES
213+
)
214+
215+
set_property(GLOBAL APPEND PROPERTY Slicer_QM_OUTPUT_DIRS ${QM_OUTPUT_DIR})
216+
endif()
217+
218+
endif()
219+
182220
# --------------------------------------------------------------------------
183221
# Build library
184222
#-----------------------------------------------------------------------------
185-
add_library(${lib_name}
186-
${LOADABLEMODULE_SRCS}
187-
${LOADABLEMODULE_MOC_OUTPUT}
188-
${LOADABLEMODULE_UI_CXX}
189-
${LOADABLEMODULE_QRC_SRCS}
190-
)
223+
if(Slicer_BUILD_I18N_SUPPORT AND TS_FILE_EXIST)
224+
add_library(${lib_name}
225+
${LOADABLEMODULE_SRCS}
226+
${LOADABLEMODULE_MOC_OUTPUT}
227+
${LOADABLEMODULE_UI_CXX}
228+
${LOADABLEMODULE_QRC_SRCS}
229+
${QM_OUTPUT_FILES}
230+
)
231+
else()
232+
add_library(${lib_name}
233+
${LOADABLEMODULE_SRCS}
234+
${LOADABLEMODULE_MOC_OUTPUT}
235+
${LOADABLEMODULE_UI_CXX}
236+
${LOADABLEMODULE_QRC_SRCS}
237+
)
238+
endif()
191239

192240
# Set loadable modules output path
193241
set_target_properties(${lib_name} PROPERTIES

Libs/MRML/Widgets/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,29 @@ if(NOT ${PROJECT_NAME}_INSTALL_NO_DEVELOPMENT)
454454
DESTINATION include/${PROJECT_NAME} COMPONENT Development)
455455
endif()
456456

457+
# --------------------------------------------------------------------------
458+
# Translation
459+
# --------------------------------------------------------------------------
460+
if(Slicer_BUILD_I18N_SUPPORT)
461+
set(TS_DIR
462+
"${CMAKE_CURRENT_SOURCE_DIR}/Resources/Translations/"
463+
)
464+
get_property(Slicer_LANGUAGES GLOBAL PROPERTY Slicer_LANGUAGES)
465+
466+
include(SlicerMacroTranslation)
467+
SlicerMacroTranslation(
468+
SRCS ${MRMLWidgets_SRCS}
469+
UI_SRCS ${MRMLWidgets_UI_SRCS}
470+
TS_DIR ${TS_DIR}
471+
TS_BASEFILENAME ${PROJECT_NAME}
472+
TS_LANGUAGES ${Slicer_LANGUAGES}
473+
QM_OUTPUT_DIR_VAR QM_OUTPUT_DIR
474+
QM_OUTPUT_FILES_VAR QM_OUTPUT_FILES
475+
)
476+
477+
set_property(GLOBAL APPEND PROPERTY Slicer_QM_OUTPUT_DIRS ${QM_OUTPUT_DIR})
478+
endif()
479+
457480
# --------------------------------------------------------------------------
458481
# Build library
459482
# --------------------------------------------------------------------------
@@ -465,6 +488,7 @@ add_library(${lib_name}
465488
${MRMLWidgets_MOC_CXX}
466489
${MRMLWidgets_UI_CXX}
467490
${MRMLWidgets_QRC_CXX}
491+
${QM_OUTPUT_FILES}
468492
)
469493

470494
set(MRMLWidgets_LIBRARIES

Libs/MRML/Widgets/qMRMLCaptureToolBar.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void qMRMLCaptureToolBarPrivate::init()
9999
// Screenshot button
100100
this->ScreenshotAction = new QAction(q);
101101
this->ScreenshotAction->setIcon(QIcon(":/Icons/ViewCapture.png"));
102-
this->ScreenshotAction->setText(q->tr("Screenshot"));
103-
this->ScreenshotAction->setToolTip(q->tr(
102+
this->ScreenshotAction->setText(qMRMLCaptureToolBar::tr("Screenshot"));
103+
this->ScreenshotAction->setToolTip(qMRMLCaptureToolBar::tr(
104104
"Capture a screenshot of the full layout, 3D view or slice views. Use File, Save to save the image. Edit in the Annotations module."));
105105
QObject::connect(this->ScreenshotAction, SIGNAL(triggered()),
106106
q, SIGNAL(screenshotButtonClicked()));
@@ -109,15 +109,15 @@ void qMRMLCaptureToolBarPrivate::init()
109109
// Scene View buttons
110110
this->SceneViewAction = new QAction(q);
111111
this->SceneViewAction->setIcon(QIcon(":/Icons/ViewCamera.png"));
112-
this->SceneViewAction->setText(q->tr("Scene view"));
113-
this->SceneViewAction->setToolTip(q->tr("Capture and name a scene view."));
112+
this->SceneViewAction->setText(qMRMLCaptureToolBar::tr("Scene view"));
113+
this->SceneViewAction->setToolTip(qMRMLCaptureToolBar::tr("Capture and name a scene view."));
114114
QObject::connect(this->SceneViewAction, SIGNAL(triggered()),
115115
q, SIGNAL(sceneViewButtonClicked()));
116116
q->addAction(this->SceneViewAction);
117117

118118
// Scene view menu
119119
QToolButton* sceneViewMenuButton = new QToolButton(q);
120-
sceneViewMenuButton->setText(q->tr("Restore view"));
120+
sceneViewMenuButton->setText(qMRMLCaptureToolBar::tr("Restore view"));
121121
sceneViewMenuButton->setIcon(QIcon(":/Icons/ViewCameraSelect.png"));
122122
sceneViewMenuButton->setToolTip(QObject::tr("Restore or delete saved scene views."));
123123
this->SceneViewMenu = new qMRMLSceneViewMenu(sceneViewMenuButton);

Modules/Loadable/SceneViews/GUI/qSlicerSceneViewsModuleDialog.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ qSlicerSceneViewsModuleDialog::qSlicerSceneViewsModuleDialog()
2727
this->m_Logic = 0;
2828
this->setLayoutManager(qSlicerApplication::application()->layoutManager());
2929
this->setShowScaleFactorSpinBox(false);
30-
this->setWindowTitle("3D Slicer SceneView");
30+
this->setWindowTitle(tr("3D Slicer SceneView"));
3131

3232
// default name
3333
QString name("SceneView");

Modules/Scripted/SampleData/SampleData.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ def __init__(self, parent):
4949

5050
def addMenu(self):
5151
actionIcon = self.parent.icon
52-
a = qt.QAction(actionIcon, 'Download Sample Data', slicer.util.mainWindow())
52+
mTranslate = slicer.app.translate("qSlicerWelcomeModuleWidget", "Download Sample Data")
53+
a = qt.QAction(actionIcon, mTranslate, slicer.util.mainWindow())
5354
a.setToolTip('Go to the SampleData module to download data from the network')
5455
a.connect('triggered()', self.select)
5556

5657
fileMenu = slicer.util.lookupTopLevelWidget('FileMenu')
5758
if fileMenu:
5859
for action in fileMenu.actions():
59-
if action.text == 'Save':
60+
if action.name == 'FileSaveSceneAction':
6061
fileMenu.insertAction(action,a)
6162

6263

0 commit comments

Comments
 (0)