Lokalisierung Älterer Methoden

From FreeCAD Documentation
This page is a translated version of the page Localization Older Methods and the translation is 26% complete.
Other languages:

Dies ist eine Sammlung alter Lokalisierungstechniken, die von FreeCAD in der Vergangenheit verwendet wurden. Sie zeigen einige der Internas des Prozesses, aber die Techniken auf der Seite Lokalisierung sollten von nun an verwendet werden..

Übersetzen mit Qt-Linguist (alte Methode)

Die folgenden Informationen müssen nicht mehr verwendet werden und werden wahrscheinlich veraltet sein. Es wird hier aufbewahrt, damit sich Programmierer mit der Funktionsweise vertraut machen können. -

  • Öffne alle Sprachordner von FreeCAD, die unten gezeigt werden.
  • Vergewissere Dich, dass keine .ts-Datei mit Deinem Sprachcode existiert ("fr" für Französisch, "de" für Deutsch, etc....).
  • Wenn es existiert, kannst du diese Datei herunterladen, wenn du die Übersetzung ändern, überprüfen oder verbessern möchtest (klicke auf die Datei und lade sie herunter).
  • Wenn es nicht existiert, lade die.ts-Datei ohne Sprachcode herunter (oder jede andere verfügbare.ts, es wird auch funktionieren).
  • Benenne diese Datei mit deinem Sprachcode um.
  • Öffne es mit dem Qt-Linguist Programm.
  • Beginne mit der Übersetzung (Qt Linguist ist sehr einfach zu bedienen).
  • Sobald es vollständig erledigt ist, speichere Deine Datei.
  • sende die Dateien an uns, damit wir sie in den Freecad-Quellcode aufnehmen können, damit sie auch anderen Benutzern zugute kommen.

Verfügbare Übersetzungsdateien



Preparing your own modules/applications for translation

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.

Setting up python files for translation

To ease localization for the py files you can use 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 *.py -ts YourModule_fr.ts

the pylupdate tool will scan your .py files for translate() or tr() functions and create a YourModule_fr.ts file. That file can the be translated with QLinguist and a YourModule_fr.qm file produced from QLinguist or with the command

lrelease YourModule_fr.ts

Beware that the pylupdate4 tool is not very good at recognizing translate() functions, they need to be formatted very specifically ( see the Draft module files for examples). Inside your file, you can then setup a translator like this (after loading your QApplication but BEFORE creating any qt widget):

translator = QtCore.QTranslator()
translator.load("YourModule_"+languages[ln])
QtGui.QApplication.installTranslator(translator)


Optionally, you can also create the file XML Draft.qrc with this content:

<RCC>
<qresource prefix="/translations" > 
<file>Draft_fr.qm</file> 
</qresource> 
</RCC>

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