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

Improve i18n support #1162

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Improve i18n support #1162

wants to merge 5 commits into from

Conversation

jcfr
Copy link
Member

@jcfr jcfr commented Jun 28, 2019

  • Support for translating scripted modules (slicer.i18n.tr())
  • Generation of <ModuleName>_untranslated.ts files
  • Add targets GenerateSlicerTranslationTemplates and GenerateSlicerTranslationQMFiles
  • Support for generating and updating translation files in extension.

See https://github.com/NA-MIC/ProjectWeek/blob/master/PW31_2019_Boston/Projects/Globalization3DSlicer_OHIF/README.md#progress-and-next-steps

@hjmjohnson
Copy link
Member

@jcfr Is this relevant. It has been outstanding for more than 1 year.

@jcfr
Copy link
Member Author

jcfr commented Mar 5, 2020

Yes, let's keep it open.

@hjmjohnson
Copy link
Member

Can it be merged?

@jcfr
Copy link
Member Author

jcfr commented Mar 5, 2020

@carlos-luque I re-based the topic we worked on during one of the project week. Is it something you could test ?

jcfr and others added 5 commits March 5, 2020 21:59
This commit adds CMake function "SlicerFunctionAddPythonScriptTrFilesTargets"
used to ensure input expected by lupdate/lrelease translation tools are
generated.

The CMake function associates custom commands with each python scripts
and also adds a convenience target called "Add<TargetName>PythonScriptTrFiles"
to explicitly regenerate the .py.tr files.

The custom commands generate the .py.tr files by invoking a python cli
(CMake/Rewrite.py) replacing calls to "slicer.util.tr" with "QT_TRANSLATE_NOOP".

The python cli "CMake/Rewrite.py" internally uses the astor python
package.

Updates SlicerConfig to set Slicer_BUILD_I18N_SUPPORT,
Slicer_UPDATE_TRANSLATION and Slicer_LANGUAGES.

Co-authored-by: Carlos Luque <carlos.luque@ulpgc.es>
Removes the dependency of library to *.qm files and instead add
the target GenerateSlicerTranslationQMFiles allowing to explicitly
re-generate the '*.qm" files..
This commit adds GenerateSlicerTranslationTemplates target allowing to
generate "<BaseName>_untranslated.ts" files.

To facilitate their distribution, the files are generated in the directory
"<CMAKE_BINARY_DIR>/TranslationTemplates".
After talking with "Carlos Luque <carlos.luque@ulpgc.es>", we decided to
keep the file simpler. This could be revisited later.

Co-authored-by: Carlos Luque <carlos.luque@ulpgc.es>
Copy link
Contributor

@lassoan lassoan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice. Do we have a solution for translation of scripteddesigner modules (that generate module widget from a .ui file)?

import astor


class RewriteTr(ast.NodeTransformer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this function (and the whole file) do?

@@ -94,12 +96,12 @@ def setup(self):
inputFiducialsNodeSelector.addEnabled = False
inputFiducialsNodeSelector.removeEnabled = False
inputFiducialsNodeSelector.connect('currentNodeChanged(bool)', self.enableOrDisableCreateButton)
pathFormLayout.addRow("Input Fiducials:", inputFiducialsNodeSelector)
pathFormLayout.addRow(tr("EndoscopyWidget", "Input Fiducials:"), inputFiducialsNodeSelector)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr() arguments are in not in this order (see https://doc.qt.io/qt-5/qobject.html#tr).

It should be tr("Input Fiducials:", "EndoscopyWidget").

self.parent.connect('mrmlSceneChanged(vtkMRMLScene*)',
inputFiducialsNodeSelector, 'setMRMLScene(vtkMRMLScene*)')

# CreatePath button
createPathButton = qt.QPushButton("Create path")
createPathButton = qt.QPushButton(tr("EndoscopyWidget", "Create path"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding "EndoscopyWidget" everywhere, could we add a mixin to the class, which would add the class name automatically? It would simplify the syntax to tr("Create path").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants