Difference between revisions of "Localization Older Methods"

From FreeCAD Documentation
Jump to: navigation, search
(Marked this version for translation)
m (space)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<languages/>
 
<languages/>
 
<translate>
 
<translate>
 +
 +
<!--T:117-->
 +
{{docnav
 +
|[[Branding|Branding]]
 +
|[[Extra python modules|Extra python module]]
 +
}}
 +
 
<!--T:88-->
 
<!--T:88-->
This is a collection of old localization techniques used by FreeCAD in the past.  They show some of the internals of the processs, '''but the techniques on the [[Localisation]] page should be used from now on.'''
+
This is a collection of old localization techniques used by FreeCAD in the past.  They show some of the internals of the processs, '''but the techniques on the [[Localisation|Localisation]] page should be used from now on.'''
 
 
  
 
=== Translating with Qt-Linguist (old way) === <!--T:65-->
 
=== Translating with Qt-Linguist (old way) === <!--T:65-->
Line 21: Line 27:
 
* Start translating (Qt Linguist is very easy to use)
 
* Start translating (Qt Linguist is very easy to use)
 
* Once it's completely done, save your file
 
* Once it's completely done, save your file
* [http://www.freecadweb.org/tracker/main_page.php send the files to us] so we can include them in the freecad source code so they benefit other users too.<br />
+
* [http://www.freecadweb.org/tracker/main_page.php send the files to us] so we can include them in the Freecad source code so they benefit other users too.
''' Available translation files '''<br />
+
 
 +
<!--T:118-->
 +
''' Available translation files '''
 +
 
  
 
<!--T:116-->
 
<!--T:116-->
Line 60: Line 69:
 
<!--T:74-->
 
<!--T:74-->
 
To start the localisation of your project go to the GUI-Part of you module and type on the command line:
 
To start the localisation of your project go to the GUI-Part of you module and type on the command line:
 +
 
</translate>
 
</translate>
<pre>
+
{{Code|code=
 
qmake -project
 
qmake -project
</pre>
+
}}
 
<translate>
 
<translate>
 +
 
<!--T:75-->
 
<!--T:75-->
 
This scans your project directory for files containing text strings and creates a project file like the following example:
 
This scans your project directory for files containing text strings and creates a project file like the following example:
 +
 
</translate>
 
</translate>
<pre>
+
{{Code|code=
 
  ######################################################################
 
  ######################################################################
 
  # Automatically generated by qmake (1.06c) Do 2. Nov 14:44:21 2006
 
  # Automatically generated by qmake (1.06c) Do 2. Nov 14:44:21 2006
Line 84: Line 96:
 
             Workbench.cpp
 
             Workbench.cpp
 
  TRANSLATIONS += MyMod_de.ts
 
  TRANSLATIONS += MyMod_de.ts
</pre>
+
}}
 
<translate>
 
<translate>
  
Line 95: Line 107:
 
<!--T:78-->
 
<!--T:78-->
 
Now you need to add the <tt>.ts</tt>-files to your VisualStudio project. Specifiy the following custom build method for them:
 
Now you need to add the <tt>.ts</tt>-files to your VisualStudio project. Specifiy the following custom build method for them:
 +
 
</translate>
 
</translate>
 
{{Code|code=
 
{{Code|code=
Line 101: Line 114:
 
}}
 
}}
 
<translate>
 
<translate>
 +
 
<!--T:79-->
 
<!--T:79-->
 
Note: Enter this in one command line, the line break is only for layout purpose.  
 
Note: Enter this in one command line, the line break is only for layout purpose.  
Line 106: Line 120:
 
<!--T:80-->
 
<!--T:80-->
 
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
 
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
 +
 
</translate>
 
</translate>
 
{{Code|code=
 
{{Code|code=
Line 111: Line 126:
 
}}
 
}}
 
<translate>
 
<translate>
 +
 
<!--T:81-->
 
<!--T:81-->
 
to publish your translation in the application.
 
to publish your translation in the application.
Line 118: Line 134:
 
<!--T:83-->
 
<!--T:83-->
 
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:
 
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:
 +
 
</translate>
 
</translate>
<pre>
+
{{Code|code=
 
pylupdate4 *.py -ts YourModule_fr.ts  
 
pylupdate4 *.py -ts YourModule_fr.ts  
</pre>
+
}}
 
<translate>
 
<translate>
 +
 
<!--T:84-->
 
<!--T:84-->
 
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
 
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
 +
 
</translate>
 
</translate>
<pre>
+
{{Code|code=
 
lrelease YourModule_fr.ts
 
lrelease YourModule_fr.ts
</pre>
+
}}
 
<translate>
 
<translate>
 +
 
<!--T:85-->
 
<!--T:85-->
 
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):
 
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):
 +
 
</translate>
 
</translate>
<pre>
+
{{Code|code=
 
translator = QtCore.QTranslator()
 
translator = QtCore.QTranslator()
 
translator.load("YourModule_"+languages[ln])
 
translator.load("YourModule_"+languages[ln])
 
QtGui.QApplication.installTranslator(translator)
 
QtGui.QApplication.installTranslator(translator)
</pre>
+
}}
 
<translate>  
 
<translate>  
 +
 
<!--T:86-->
 
<!--T:86-->
 
Optionally, you can also create the file XML Draft.qrc with this content:
 
Optionally, you can also create the file XML Draft.qrc with this content:
 +
 
</translate>
 
</translate>
<pre> 
+
{{Code|code=
 
<RCC>
 
<RCC>
 
<qresource prefix="/translations" >  
 
<qresource prefix="/translations" >  
Line 148: Line 171:
 
</qresource>  
 
</qresource>  
 
</RCC>  
 
</RCC>  
</pre>
+
}}
 
<translate>
 
<translate>
 +
 
<!--T:87-->
 
<!--T:87-->
 
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
 
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
  
 
<!--T:113-->
 
<!--T:113-->
{{docnav|Branding|Extra python modules}}
+
{{docnav
 +
|[[Branding|Branding]]
 +
|[[Extra python modules|Extra python module]]
 +
}}
  
 
<!--T:114-->
 
<!--T:114-->
 +
{{Userdocnavi}}
 +
 +
<!--T:119-->
 
[[Category:Developer Documentation]]
 
[[Category:Developer Documentation]]
 +
  
 
</translate>
 
</translate>
  
 
{{clear}}
 
{{clear}}

Latest revision as of 13:47, 22 October 2019

Other languages:
English • ‎français • ‎italiano

This is a collection of old localization techniques used by FreeCAD in the past. They show some of the internals of the processs, but the techniques on the Localisation page should be used from now on.

Translating with Qt-Linguist (old way)

The following information doesn't need to be used anymore and will likely become obsolete. It is being kept here so that programmers may familiarize themselves with how it works. -

  • Open all of the language folders of FreeCAD shown below
  • Verify that a .ts file with your language code doesn't exist ("fr" for french, "de" for german, etc...)
  • If it exists, you can download that file, if you want to modify/review/better the translation (click the file, then download)
  • If it doesn't exist, download the .ts file without language code (or any other .ts available, it will work too)
  • Rename that file with your language code
  • Open it with the Qt-Linguist program
  • Start translating (Qt Linguist is very easy to use)
  • Once it's completely done, save your file
  • send the files to us so we can include them in the Freecad source code so they benefit other users too.

Available translation files



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