Localisation: Difference between revisions

From FreeCAD Documentation
(Added navigation bar, Article has to be reworked...)
(Reworked with informations from Werner)
Line 1: Line 1:
'''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 [[wikipedia:Qt (toolkit)|Qt]] to enable multiple language support.
'''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 [[wikipedia:Qt (toolkit)|Qt]] to enable multiple language support.


== How to Translate ==
== Prerequisites ==
In the [[LibPack]] of FreeCAD you find the ''Qt-Linguist'' tool that helps you to translate FreeCAD in the language of your choice, but you can also download it from [http://www.trolltech.com/products/qt/downloads www.trolltech.com].
To localise your application module your need to helpers that come with ''Qt''. You can download them from the [http://www.trolltech.com/products/qt/downloads 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 translate a part of FreeCAD, locate files with the "<tt>.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 "<tt>basename_LC.ts</tt>" where <tt>LC</tt> is a language code like "en" for ''english'' or "de" for german. To provide a new language copy one these files to a new file with the country code of your language. Then open it with the ''Qt-Linguist'' and start translating. The ''Qt-Linguist'' is very easy to use and helps you translating with nice features like a phrase book for common sentences.
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 <tt>TRANSLATIONS</tt> 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 <tt>lupdate</tt> to extract all string literals in your GUI. Running <tt>lupdate</tt> 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 <tt>.ts</tt>-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 <tt>.ts</tt>-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 "<tt>.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 "<tt>basename_LC.ts</tt>" where <tt>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!


{{Devdocnavi}}
{{Devdocnavi}}

Revision as of 14:01, 8 December 2006

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!

Template:Devdocnavi