CLI Module widget internationalization

Hello,

We are translating the 3D slicer and the loadable module can be done well but seems there is no good explanation document about CLI module internationalization.

As my understanding, SlicerExecutionModel defined a xml module description to the widget creation. But is there any official way to do the widget internaltionlization ?

Ted

I think you would just make sure the CLI widget is internationalizable itself, and then provide translations for all the text that appears in the XML descriptions of the CLI modules. Are there any complications with that approach?

Pieper,

What I mean is, Can we translate CLI module like the approach described below?

“We provide the translated version xml, BRAINSFit_zh_tw.xml and also keep the original BRAINSFit.xml file. When user select his language in system setting. the 3d Slicer will auto load the corresponded translation.”

I have read the source code of 3d Slicer CLI loader and saw the xml description will be loaded in

qSlicerAbstractCoreModule* qSlicerCLIExecutableModuleFactoryItem::instanciator()

but cannot see the same i18n translation loading logic as loadable module. I am wondering if there exist any official dynamic i18n loading support for CLI ?

You can try applying Qt translator to get localized string from the string specified in the xml files. It would be probably just a little change in the CLI GUI helper class.

Andras,

I cannot undertand exactly, I have tried lupdate to extract BRAINSFit module and got nothing, meanwhile the QT linguist doesn’t support the BRAINSFit.xml translation either.

My thought is to implement the dynamic xml loading myself(load BRAINSFit_zh_tw.xml or BRAINSFit_fr.xml corresponding current ui language setting), but don’t know if it’s a correct way or there is any official CLI i18n suppport i don’t know?

The translation i mentioned is as below (some real codes in BRAINSFit.xml), and my current understand is slicer will parse out the description “Transform Initialization Settings” in xml and generated the widget. I want to translate generated widget.

<parameters>
    <label>Transform Initialization Settings</label>
    <description>Options for initializing transform parameters.</description>
    <transform fileExtensions=".h5,.hdf5,.mat,.txt">
      <name>initialTransform</name>
      <longflag>initialTransform</longflag>
      <label>Initialization transform</label>
      <description>Transform to be applied to the moving image to initialize the registration.  This can only be used if Initialize Transform Mode is Off.</description>
      <channel>input</channel>
    </transform>
    <string-enumeration>
      <name>initializeTransformMode</name>
      <longflag>initializeTransformMode</longflag>
      <label>Initialize Transform Mode</label>
      <description>Determine how to initialize the transform center.  useMomentsAlign assumes that the center of mass of the images represent similar structures.  useCenterOfHeadAlign attempts to use the top of head and shape of neck to drive a center of mass estimate. useGeometryAlign on assumes that the center of the voxel lattice of the images represent similar structures.  Off assumes that the physical space of the images are close.  This flag is mutually exclusive with the Initialization transform.</description>
      <default>Off</default>
      <element>Off</element>
      <element>useMomentsAlign</element>
      <element>useCenterOfHeadAlign</element>
      <element>useGeometryAlign</element>
      <element>useCenterOfROIAlign</element>
    </string-enumeration>
  </parameters>

There could be many internationalization solutions, but the approach I think would be the simplest:

  • do not translate any CLI module descriptor XML files
  • update qSlicerCLIModuleUIHelper.cxx to translate strings that are retrieved from CLI module descriptor XML files before setting them in a widget
  • provide translations for strings in the CLI module descriptor XML files (Qt linguist will not collect text from CLI XML files but if you provide translation then they will be applied)

For example, to translate a parameter’s tooltip, change this line:

QString description = QString::fromStdString(moduleParameter.GetDescription());

to this:

QString description = tr(moduleParameter.GetDescription().c_str());
1 Like

Ah, I finally understand what you all mean.

I will think about it in advance… seems this approach will pollute the translated vocabulary space, especially when some same phrases may have to be translated into diff semantic translations.

To translate each CLI module independently, you can use QCoreApplication::translate method and use the CLI module name as translation context.

Andras,

I will give it a shot and thanks for your clear explanation.

Let us know if you find a solution that works. Also, we are happy to integrate pull requests that help internationalization.