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

BUG: Fix lupdate warnings on translation function calls #1067

Merged
merged 1 commit into from
Mar 1, 2023

Conversation

mhdiop
Copy link
Contributor

@mhdiop mhdiop commented Feb 13, 2023

Qt lupdate tool throws Cannot invoke tr() like this warnings when translation function is called using q->tr(...). The problem is that lupdate cannot determine the class name tr() is called on and therefore it does not know the translation context. The solution is to spell out the class name in the call, for example qSlicerScalarVolumeDisplayWidget::tr(...). More details are described here: https://github.com/Slicer/SlicerLanguagePacks/blob/main/DevelopersManual.md

see Slicer/SlicerLanguagePacks#17
see Slicer/SlicerLanguagePacks#12

Copy link
Member

@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 good, just added a few minor comments.

Libs/DICOM/Widgets/ctkDICOMBrowser.cpp Outdated Show resolved Hide resolved
@@ -167,11 +167,11 @@ void ctkSettingsDialogPrivate::updateRestartRequiredLabel()
bool restartRequired = !restartRequiredSettings.isEmpty();
if (restartRequired)
{
QString header = q->tr(
QString header = ctkSettingsDialog::tr(
Copy link
Member

Choose a reason for hiding this comment

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

If not too complicated, remove HTML tags from translatable text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, HTML tags are now separated from the translatable text.

@mhdiop mhdiop force-pushed the translation-function-call-fix branch 2 times, most recently from 1d02596 to 04c3dcc Compare February 16, 2023 01:51
@mhdiop mhdiop force-pushed the translation-function-call-fix branch from 04c3dcc to e83aa1e Compare February 23, 2023 10:28
Copy link
Member

@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.

Thank you, it all looks good except a trivial change (see inline).

QString footer = q->tr("</small>");
QString header = "<b style=\"color:red\">" + ctkSettingsDialog::tr("Restart required!") + "</b><br>\n<small>";
header += ctkSettingsDialog::tr(
"The application must be restarted to take into account the new values of the following properties:\n"
Copy link
Member

Choose a reason for hiding this comment

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

Could you move out the \n from the translatable string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, it's done now, thanks !

@mhdiop mhdiop force-pushed the translation-function-call-fix branch from e83aa1e to dc6e488 Compare March 1, 2023 19:29
QString header = "<b style=\"color:red\">" + ctkSettingsDialog::tr("Restart required!") + "</b><br><small>";
header += ctkSettingsDialog::tr(
"The application must be restarted to take into account the new values of the following properties:"
);
Copy link
Member

Choose a reason for hiding this comment

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

We still need the \n at the end of the header, I just asked for adding it outside the tr() function.

Could you add "\n" to the header after the header += ctkSettingsDialog::tr("The application must be restarted...properties:"); line? Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok I see, the update is done. Thanks.

Qt lupdate tool throws `Cannot invoke tr() like this` warnings when translation function is called using `q->tr(...)`.
The problem is that lupdate cannot determine the class name `tr()` is called on and therefore it does not know the translation context.
The solution is to spell out the class name in the call, for example `ctkSettingsDialog::tr(...)`.
More details are described here: https://github.com/Slicer/SlicerLanguagePacks/blob/main/DevelopersManual.md

see Slicer/SlicerLanguagePacks#17
see Slicer/SlicerLanguagePacks#12
@mhdiop mhdiop force-pushed the translation-function-call-fix branch from dc6e488 to 37a6fbd Compare March 1, 2023 20:05
Copy link
Member

@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.

Thank you, it looks good, ready to be merged!

@lassoan lassoan merged commit 30237e9 into commontk:master Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants