Difference between revisions of "Slicer4:Internationalization of Slicer"
Line 5: | Line 5: | ||
This pages contains notes on source code additions and modifications of different modules within Slicer for the internationalization purpose. | This pages contains notes on source code additions and modifications of different modules within Slicer for the internationalization purpose. | ||
=QT-based Internationalization= | =QT-based Internationalization= | ||
− | Internationalization is well supported in QT. A lot of modules of Slicer are developed on QT. This has set a good ground for the internationalization of Slicer. The following | + | Internationalization is well supported in QT. A lot of modules of Slicer are developed on QT. This has set a good ground for the internationalization of Slicer. |
+ | *basic idea | ||
+ | In Qt, tr() is one of the static public members of QObject class, which returns a translated version of input sourceText. | ||
+ | QString QObject::tr ( const char * sourceText, const char * disambiguation = 0, int n = -1 ) [static] | ||
+ | tr() will search the translation in a so-called translation file. If nothing is found, then the sourceText instead of the translated version will be displayed directly. | ||
+ | *translation file template | ||
+ | The following is an example of the translation file, from English to Chinese. | ||
+ | <?xml version="1.0" encoding="utf-8"?> | ||
+ | <!DOCTYPE TS> | ||
+ | <TS version="2.0" language="zh_CN"> | ||
+ | <context> | ||
+ | <name>qSlicerMainWindow</name> | ||
+ | <message> | ||
+ | <source>&File</source> | ||
+ | <translation>文件</translation> | ||
+ | </message> | ||
+ | <message> | ||
+ | <source>&Edit</source> | ||
+ | <translation>编辑</translation> | ||
+ | </message> | ||
+ | <message> | ||
+ | <source>Feedback</source> | ||
+ | <translation>反馈</translation> | ||
+ | </message> | ||
+ | <message> | ||
+ | <source>Import Scene</source> | ||
+ | <translation>导入场景</translation> | ||
+ | </message> | ||
+ | <message> | ||
+ | <source>Add Data</source> | ||
+ | <translation>添加数据</translation> | ||
+ | </message> | ||
+ | </context> | ||
+ | </TS> | ||
+ | In the above example, all the texts are within the scope of qSlicerMainWindow class. That's why 'qSlicerMainWindo' occurs in section 'name'. | ||
+ | |||
+ | *The following modifications are are needed: | ||
In file \Slicer4\Base\QTCore\qSlicerCoreApplication.h, add the following line: | In file \Slicer4\Base\QTCore\qSlicerCoreApplication.h, add the following line: |
Revision as of 16:28, 8 August 2011
Home < Slicer4:Internationalization of SlicerIntroduction
This pages contains notes on source code additions and modifications of different modules within Slicer for the internationalization purpose.
QT-based Internationalization
Internationalization is well supported in QT. A lot of modules of Slicer are developed on QT. This has set a good ground for the internationalization of Slicer.
- basic idea
In Qt, tr() is one of the static public members of QObject class, which returns a translated version of input sourceText.
QString QObject::tr ( const char * sourceText, const char * disambiguation = 0, int n = -1 ) [static]
tr() will search the translation in a so-called translation file. If nothing is found, then the sourceText instead of the translated version will be displayed directly.
- translation file template
The following is an example of the translation file, from English to Chinese.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.0" language="zh_CN"> <context> <name>qSlicerMainWindow</name> <message>
&File
<translation>文件</translation> </message> <message>
&Edit
<translation>编辑</translation> </message> <message>
Feedback
<translation>反馈</translation> </message> <message>
Import Scene
<translation>导入场景</translation> </message> <message>
Add Data
<translation>添加数据</translation> </message> </context> </TS>
In the above example, all the texts are within the scope of qSlicerMainWindow class. That's why 'qSlicerMainWindo' occurs in section 'name'.
- The following modifications are are needed:
In file \Slicer4\Base\QTCore\qSlicerCoreApplication.h, add the following line:
#include <QTranslator>
In file \Slicer4\Applications\SlicerQT\main.cxx (around line#230), add the following lines:
static QTranslator* translator; if (translator != NULL) { qApp->removeTranslator(translator); delete translator; translator = NULL; } QString langCode= argv[1]; translator = new QTranslator; QString qmFilename = "lang_" + langCode; if (translator->load(qmFilename)) { qApp->installTranslator(translator); }
Scripted Module
Some modules are implemented in Python. Endoscopy is one of the typical examples. In endoscopy.py, if we change the code in line#10
parent.titel = “Endoscopy”
to
parent.title = slicer.app.translate(self.__class__.__name__, "Endoscopy")
then "Endoscopy" can be shown in other languages.Similarily, other displayable strings can be handled in the same way.