-
Notifications
You must be signed in to change notification settings - Fork 512
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
Translate user-visible text coming from logic classes #6647
Comments
Examples:
|
A new
Source text for translation should be possible by specifying extra options for A global function or singleton class could be added to MRML that would call |
Instead of a macro,
|
I've started working on the implementation of the I first wanted to use a function pointer as stated in the previous posts but the I then create a However, strings present in the logic classes are not always of the same type. Many of them are I know that any choice will have impact on the source code since it may result in many string conversions at translation function calls. Also, I wonder if those types are suitable for storing translated strings without any encoding issue ? Here are some suggested implementations : QString vtkMRMLTr(const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1)
{
return QCoreApplication::translate(context, sourceText, disambiguation, n);
} std::string vtkMRMLTr(const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1)
{
return QCoreApplication::translate(context, sourceText, disambiguation, n).toStdString();
} Regards. |
Assuming we are focusing on translating strings from logic, what about adding virtual function |
Thank you for working on this. It seems like you are doing nice progress. We cannot use any Qt functions or variables in vtkMRMLCore component. That's why we need the callback function. You have figured out the solution for default argument issue (create a function that has default arguments) you just need to call a function pointer from there (you cannot call in vtkMRMLCore (Qt classes cannot be used): vtkMRMLTranslateFunctionPtr = nullptr;
std::string vtkMRMLTr(const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1)
{
if (vtkMRMLTranslateFunctionPtr)
{
return (*vtkMRMLTranslateFunctionPtr)(context, sourceText, disambiguation, n);
}
else
{
return sourceText;
}
}
in Slicer application (Qt classes can be used): std::string SlicerAppMRMLTranslate(const char *context, const char *sourceText, const char *disambiguation, int n)
{
return QCoreApplication::translate(context, sourceText, disambiguation, n).toStdString();
}
qSlicerApplicationPrivate::init()
{
vtkMRMLTranslateFunctionPtr = SlicerAppMRMLTranslate;
} Using std::string return value of vtkMRMLTr is good because it avoids pointer ownership issues. Using It may be better to use namespaces or class names instead of polluting the global namespace with functions and function pointers. |
I like @jcfr's suggestion of using virtual functions instead of global function pointers. It keeps the global namespace more tidy and syntax of virtual functions is much more readable than function pointers. |
I agree with the virtual method approach. But I'd suggest that instead of creating a |
Great idea. And this is consistent with the existing Footnotes |
It could be inplemented the same way as vtkOutputWindow with static GetInstance/SetInstance methods. |
vtkMRMLI18N singleton class is responsible for internationalization related features in MRML. It currently only stores a language translator. A translator that uses Qt for translation is specified in qSlicerCoreApplication. Enables fixing of these issues: Slicer/SlicerLanguagePacks#12 Slicer#6647 Slicer#6177 Co-authored-by: Mouhamed DIOP <mouhamed.diop@esp.sn>
vtkMRMLI18N singleton class is responsible for internationalization related features in MRML. It currently only stores a language translator. A translator that uses Qt for translation is specified in qSlicerCoreApplication. Enables fixing of these issues: Slicer/SlicerLanguagePacks#12 #6647 #6177 Co-authored-by: Mouhamed DIOP <mouhamed.diop@esp.sn>
Most text that is displayed for users is coming from Qt GUI classes and translated using Qt translation infrastructure. However, there are probably cases when the GUI displays messages coming from logic classes. We need to review all the module logics classes (e.g., in all Logic, MRML, MRMLDM, VTKWidgets folders) if they provide any strings that end up being displayed for users and make sure they are translated.
Design options:
The text was updated successfully, but these errors were encountered: