Localisation
Localisation is in general the process of providing a Software with a multiple language user interface. In FreeCAD you can set the language of the user interface under Edit→Preferences→Application. FreeCAD uses Qt to enable multiple language support.
Prerequisites
To localise your application module your need to helpers that come with Qt. You can download them from the Trolltech-Website, but they are also contained in the LibPack:
- qmake
- Generates project files
- lupdate
- Extracts or updates the original texts in your project by scanning the source code
- Qt-Linguist
- The Qt-Linguist is very easy to use and helps you translating with nice features like a phrase book for common sentences.
Project Setup
To start the localisation of your project go to the GUI-Part of you module and type on the command line:
qmake -project
This scans your project directory for files containing text strings and creates a project file like the following example:
###################################################################### # Automatically generated by qmake (1.06c) Do 2. Nov 14:44:21 2006 ###################################################################### TEMPLATE = app DEPENDPATH += .\Icons INCLUDEPATH += . # Input HEADERS += ViewProvider.h Workbench.h SOURCES += AppMyModGui.cpp \ Command.cpp \ ViewProvider.cpp \ Workbench.cpp TRANSLATIONS += MyMod_de.ts
You can manually add files here. The section TRANSLATIONS contains a list of files with the translation for each language. In the above example MyMod_de.ts is the german translation.
Now you need to run lupdate to extract all string literals in your GUI. Running lupdate after changes in the source code is allways safe since it never deletes strings from your translations files. It only adds new strings.
Now you need to add the .ts-files to your VisualStudio project. Specifiy the following custom build method for them:
python ..\..\..\Tools\qembed.py "$(InputDir)\$(InputName).ts" "$(InputDir)\$(InputName).h" "$(InputName)"
Note: Enter this in one command line, the line break is only for layout purpose.
By compiling the .ts-file of the above example, a header file MyMod_de.h is created. The best place to include this is in App<Modul>Gui.cpp. In our example this would be AppMyModGui.cpp. There you add the line
new Gui::LanguageProducer("Deutsch", <Modul>_de_h_data, <Modul>_de_h_len);
to publish your translation in the application.
How to Translate
To translate a part of FreeCAD, locate files with the ".ts" ending in the source tree. Each of these files contains text snippets from the user interface in the original english version and - if allready translated - in another language. The filename specifies the language with a two byte code in the pattern "basename_LC.ts" where LC is a language code like "de" for german. Open it with the Qt-Linguist and start translating. You will see, it is really simple!