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:

TEMPLATE = app DEPENDPATH += .\Icons INCLUDEPATH +=. HEADERS += ViewProvider.h Workbench.h SOURCES += AppMyModGui.cpp \ Command.cpp \ ViewProvider.cpp \ Workbench.cpp TRANSLATIONS += MyMod_de.ts
 * 1) Automatically generated by qmake (1.06c) Do 2. Nov 14:44:21 2006
 * 1) Automatically generated by qmake (1.06c) Do 2. Nov 14:44:21 2006
 * 1) Input

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 AppGui.cpp. In our example this would be AppMyModGui.cpp. There you add the line new Gui::LanguageProducer("Deutsch", _de_h_data, _de_h_len); to publish your translation in the application.

Setting up python files for translation
To ease localization for the py files I found the tool "pylupdate4" which accepts one or more py files. With the -ts option you can prepare/update one or more .ts files. For instance to prepare a .ts file for French simply enter into the command line: pylupdate4 draftGui.py -ts Draft_fr.ts Creating the file XML Draft.qrc with thi content:   Draft_fr.qm 

and running pyrcc4 Draft.qrc -o qrc_Draft.py creates a big Python containing all resources. BTW this approach also works to put icon files in one resource file

How to Translate
To translate a part of FreeCAD, locate files with the ".ts</tt>" 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</tt>" where LC</tt> is a language code like "de" for german. Open it with the Qt-Linguist and start translating. You will see, it is really simple!