Localisation/en: Difference between revisions

From FreeCAD Documentation
No edit summary
(Updating to match new version of source page)
Line 1: Line 1:
<languages/>
'''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. On Unix/Linux systems, FreeCAD uses the current locale settings of your system by default.
'''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. On Unix/Linux systems, FreeCAD uses the current locale settings of your system by default.


Line 18: Line 19:
to this issue: http://www.freecadweb.org/tracker/view.php?id=137
to this issue: http://www.freecadweb.org/tracker/view.php?id=137


== Preparing your FreeCAD/master modules for translation ==
These are the parts to the FreeCAD translation process:
* extract text strings from source code into *.ts files
* load *.ts files into [http://crowdin.net/project/freecad FreeCAD Crowdin].
* translation of strings within Crowdin
* extract modified/new *.ts files from Crowdin
* convert *.ts files into *.qm files and update each module's *.qrc file
* update FreeCAD master


All of the above steps are performed by the "translation scripts" which are run by an administrator periodically.
=== Translating with Qt-Linguist (old way) ===


Preparing your module for translation is quite easy. First, you need to ensure that you have a "translations" directory in myModule/Gui/Resources. Then open a terminal window (or Windows/OSX equivalent) in your "translations" directory and enter the following command:
{| class="mw-collapsible mw-collapsed wikitable"
{{Code|code=lupdate -ts myModule.ts}}
|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
* [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 />
''' Available translation files '''<br />
* The following links all direct to the sourceforge which is no longer used by FreeCAD. The code is hosted at https://github.com/FreeCAD/FreeCAD.
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Gui/Language/ FreeCAD main GUI]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Complete/Gui/Resources/translations/ Complete Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Drawing/Gui/Resources/translations/ Drawing Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Draft/Resources/translations/ Draft Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/ReverseEngineering/Gui/Resources/translations/ Reverse Engineering Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Fem/Gui/Resources/translations/ FEM Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Robot/Gui/Resources/translations/ Robot Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Image/Gui/Resources/translations/ Image Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Sketcher/Gui/Resources/translations/ Sketcher Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Mesh/Gui/Resources/translations/ Mesh Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Test/Gui/Resources/translations/ Test Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Points/Gui/Resources/translations/ Points Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Raytracing/Gui/Resources/translations/ Raytracing Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Part/Gui/Resources/translations/ Part Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/PartDesign/Gui/Resources/translations/ PartDesign Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/Assembly/Gui/Resources/translations/ Assembly Workbench]
* [http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Mod/MeshPart/Gui/Resources/translations/ MeshPart Workbench]
* There is a very good Forum post about the old way of translation, but it is in German. See http://forum.freecadweb.org/viewtopic.php?f=13&t=19496&start=60#p152655
|}

== 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 [http://www.trolltech.com/products/qt/downloads Trolltech-Website], but they are also contained in the [[Third Party Libraries|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:
<pre>
qmake -project
</pre>
This scans your project directory for files containing text strings and creates a project file like the following example:
<pre>
######################################################################
# 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
</pre>

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.


This creates an empty translation file. Once this is done, you need to ensure that the translation scripts are updated as in this [https://github.com/FreeCAD/FreeCAD/pull/810 pull request].
Now you need to add the <tt>.ts</tt>-files to your VisualStudio project. Specifiy the following custom build method for them:
{{Code|code=
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.


Everything after this is automatic as far as a developer is concerned. The administrator will extract the text strings, the translators will translate them, then the administrator will extract the translations and update FreeCAD/master.
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
{{Code|code=
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 ===
== Preparing your 3rd party module or macro for translation ==
3rd party modules or macros are translated in much the same fashion, except that you must do some of the work yourself.
This [https://www.forum.freecadweb.org/viewtopic.php?f=3&t=25180 forum discussion] describes the details .


== Older module translation techniques ==
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:
[[Localization Older Methods]] describes the use of translation tools such as Qt Linguist, lupdate, lrelease, pylupdate4, etc in detail. Most of this is no longer required for FreeCAD/master modules, but may be helpful preparing and updating 3rd party modules.
<pre>
pylupdate4 *.py -ts YourModule_fr.ts
</pre>
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
<pre>
lrelease YourModule_fr.ts
</pre>
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):
<pre>
translator = QtCore.QTranslator()
translator.load("YourModule_"+languages[ln])
QtGui.QApplication.installTranslator(translator)
</pre>
Optionally, you can also create the file XML Draft.qrc with this content:
<pre>
<RCC>
<qresource prefix="/translations" >
<file>Draft_fr.qm</file>
</qresource>
</RCC>
</pre>
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


== Translating the wiki ==
== Translating the wiki ==
Line 193: Line 102:
{{docnav|Branding|Extra python modules}}
{{docnav|Branding|Extra python modules}}


[[Category:Developer Documentation/en]]
[[Category:Developer Documentation]]


{{clear}}
{{clear}}
<languages/>

Revision as of 13:39, 4 August 2018

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. On Unix/Linux systems, FreeCAD uses the current locale settings of your system by default.

Helping to translate FreeCAD

One of the very important things you can do for FreeCAD if you are not a programmer, is to help to translate the program in your language. To do so is now easier than ever, with the use of the Crowdin collaborative on-line translation system.

How to Translate

  • Go to the FreeCAD translation project page on Crowdin;
  • Login by creating a new profile, or using a third-party account like your GMail address;
  • Click on the language you wish to work on;
  • Start translating by clicking on the Translate button next to one of the files. For example, FreeCAD.ts contains the text strings for the FreeCAD main GUI.
  • You can vote for existing translations, or you can create your own.
Note: If you are actively taking part in translating FreeCAD and want to be 
informed before next release is ready to be launched, 
so there is time to review your translation, please subscribe 
to this issue: http://www.freecadweb.org/tracker/view.php?id=137

Preparing your FreeCAD/master modules for translation

These are the parts to the FreeCAD translation process:

  • extract text strings from source code into *.ts files
  • load *.ts files into FreeCAD Crowdin.
  • translation of strings within Crowdin
  • extract modified/new *.ts files from Crowdin
  • convert *.ts files into *.qm files and update each module's *.qrc file
  • update FreeCAD master

All of the above steps are performed by the "translation scripts" which are run by an administrator periodically.

Preparing your module for translation is quite easy. First, you need to ensure that you have a "translations" directory in myModule/Gui/Resources. Then open a terminal window (or Windows/OSX equivalent) in your "translations" directory and enter the following command:

lupdate -ts myModule.ts

This creates an empty translation file. Once this is done, you need to ensure that the translation scripts are updated as in this pull request.

Everything after this is automatic as far as a developer is concerned. The administrator will extract the text strings, the translators will translate them, then the administrator will extract the translations and update FreeCAD/master.

Preparing your 3rd party module or macro for translation

3rd party modules or macros are translated in much the same fashion, except that you must do some of the work yourself. This forum discussion describes the details .

Older module translation techniques

Localization Older Methods describes the use of translation tools such as Qt Linguist, lupdate, lrelease, pylupdate4, etc in detail. Most of this is no longer required for FreeCAD/master modules, but may be helpful preparing and updating 3rd party modules.

Translating the wiki

This wiki is hosting a lot of contents, the majority of which build up the manual. You can browse the documentation starting from the Main Page, or have a look at the User's manual Online Help Toc.

Translation plugin

When the Wiki moved away from SourceForge, Yorik installed a Translation plugin which allows to ease translations between pages. For example, the page title can now be translated. Other advantages of the Translation plugin are that it keeps track of translations, notifies if the original page has been updated, and maintains translations in sync with the original English page.

The tool is documented in Extension:Translate, and is part of a Language Extension Bundle.

To quickly get started on preparing a page for translation and activating the plugin, please read the Page translation example.

To see an example of how the Translation tool works once the translation plugin is activated on a page, you can visit the Main Page. You will see a new language menu bar at the bottom. It is automatically generated. Click for instance on the German link, it will get you to Main Page/de. Right under the title, you can read "This page is a translated version of a page Main Page and the translation is xx% complete." (xx being the actual percentage of translation). Click on the "translated version" link to start translation, or to update or correct the existing translation.

You will notice that you cannot directly edit a page anymore once it's been marked as a translation. You have to go through the translation utility.

When adding new content, the English page should be created first, then translated into another language. If someone wants to change/add content in a page, he should do the English one first.

It is recommended to have basic knowledge of wiki style formatting and general guidelines of the FreeCAD wiki, because you will have to deal with some tags while translating. You can find this information on WikiPages.

The sidebar (navigation menu on the left) is also translatable. Please follow dedicated instructions on Localisation Sidebar page.

REMARK: The first time you switch a page to the new translation system, it looses all its old 'manual' translations. To recover the translation, you need to open an earlier version from the history, and copy/paste manually the paragraphs to the new translation system.

Remark: to be able to translate in the wiki, you must of course gain wiki edit permission.


If you are unsure how to proceed, don't hesitate to ask for help in the forum.

Old translation instructions

These instructions are for historical background only, while the pages are being passed to the new translation plugin.

So the first step is to check if the manual translation has already been started for your language (look in the left sidebar, under "manual").
If not, head to the forum and say that you want to start a new translation, we'll create the basic setup for the language you want to work on.
You must then gain wiki edit permission.
If your language is already listed, see what pages are still missing a translation (they will be listed in red). The technique is simple: go into a red page, and copy/paste the contents of the corresponding English page, and start translating.
Do not forget to include all the tags and templates from the original English page. Some of those templates will have an equivalent in your language (for example, there is a French Docnav template called Docnav/fr). You should use a slash and your language code in almost all the links. Look at other already translated pages to see how they did it.
Add a slash and your language code in the categories, like [[Category:Developer Documentation/fr]]
And if you are unsure, head to the forums and ask people to check what you did and tell you if it's right or not.
Four templates are commonly used in manual pages. These 4 templates have localized versions (Template:Docnav/fr, Template:fr, etc...)

  • Template:GuiCommand : is the Gui Command information block in upper-right of command documentation.
  • Template:Docnav : it is the navigation bar at the bottom of the pages, showing previous and next pages.

Page Naming Convention
Please take note that, due to limitations in the Sourceforge implementation of the MediaWiki engine, we require that your pages all keep their original English counterpart's name, appending a slash and your language code. For example, the translated page for About FreeCAD should be About Freecad/es for Spanish, About FreeCAD/pl for polish, etc. The reason is simple: so that if translators go away, the wiki's administrators, who do not speak all languages, will know what these pages are for. This will facilitate maintenance and avoid lost pages.
If you want the Docnav template to show linked pages in your language, you can use redirect pages. They are basically shortcut links to the actual page. Here is an example with the French page for About FreeCAD.

  • The page About FreeCAD/fr is the page with content
  • The page À propos de FreeCAD contains this code:
#REDIRECT [[About FreeCAD/fr]]
  • In the About FreeCAD/fr page, the Docnav code will look like this:
{{docnav/fr|Bienvenue sur l'aide en ligne|Fonctionnalités}}

The page "Bienvenue sur l'aide en ligne" redirects to Online Help Startpage/fr, and the page "Fonctionnalités" redirects to Feature list/fr.

Branding
Extra python modules