Translating an external workbench/pl

W poniższych uwagach, powinien być nazwą twojego dodatku lub środowiska pracy, na przykład,  lub, lub cokolwiek innego. Ten kontekst sprawia, że wszystkie tłumaczenia twojego kodu będą zebrane pod tą samą nazwą, aby tłumacze mogli je łatwiej zidentyfikować. Oznacza to, że będą oni dokładnie wiedzieli, do którego dodatku lub środowiska pracy należy dany ciąg znaków.

Uwaga: Oto skrypt all-in-one, który automatyzuje całą procedurę opisaną poniżej (zalecamy jednak przeczytanie procedury, aby wiedzieć, co skrypt powinien zrobić): https://github.com/yorikvanhavre/BIM_Workbench/blob/master/utils/updateTranslations.py

Informacje ogólne

 * Dodaj folder . Możesz nadać mu inną nazwę, ale tak będzie łatwiej, ponieważ jest on taki sam w całym FreeCAD. W tym folderze umieścisz pliki (pliki tłumaczenia "źródła") i  (skompilowane pliki tłumaczenia).
 * Należy tłumaczyć tylko tekst, który jest wyświetlany użytkownikowi w interfejsie użytkownika programu FreeCAD. Tekst, wyświetlany w konsoli Python nie powinien być tłumaczony.
 * Tekst, który jest wyświetlany w, jest wyświetlany w oknie "Widok raportu" i dlatego powinien zostać przetłumaczony. Okno "Widok raportu" jest czymś innym niż konsola Python.

W każdym pliku .py Python

 * W każdym pliku, w którym musisz przetłumaczyć tekst, musisz mieć zdefiniowaną funkcję . Łatwym sposobem jest użycie tej z środowiska Rysunek Roboczy:

Od wersji FreeCAD 0.19 moduł FreeCAD definiuje również funkcję translate, najlepiej użyć właśnie tej:


 * Cały tekst, który musi zostać przetłumaczony, musi zostać przekazany przez funkcję.

staje się

This can be used anywhere: in, in , in Qt dialogs, etc. The functions do not automatically add the newline character , so this must be added at the end if desired. This character doesn't need translation either, so it can be outside the translating function:


 * If you are using files made with QtDesigner, nothing special needs to be done with them.
 * When creating new objects, do not translate the object's "Name". Rather, translate object's "Label". The difference is that a "Name" is unique; it stays the same throughout the life of the object; on the other hand, a "Label" can be changed by the user as desired.
 * When creating properties for your objects, don’t translate the property name. But place the description inside :

Don't use your own in this specific case. Keep.
 * Do not translate the text of document transactions made with

In InitGui.py

 * Add the following line, close to the top of the file:


 * To translate menu names:


 * The macro doesn’t do anything, but it marks texts to be picked up by the  utility later on. Since it doesn't actually do anything, we only use it in special cases where FreeCAD itself takes care of everything.
 * Add the path to your folder in the Initialized function:

The file has no file attribute, so it is not easy to find the translations folder’s relative location. An easy way to work around this is to make it import another file from the same folder, and in that file, do

Inside each FreeCAD command class

 * Add the following line, close to the top of the file:


 * Translate the and  of the command like this:

where is the name of the command, defined by

Gather all the strings from your module

 * You will need the, , and  tools installed on your system. In Linux distributions they usually come in packages named  or . On some systems  is named  or  or  or similar. Same for the other tools. You may use the Qt4 or Qt5 version at your choice.
 * If you have files, you need to run  first:

This is recursive and will find files inside all your directory structure
 * If you have files, you need to run  too:


 * If you ran both operations, you now need to unify these two files into one:


 * Check the contents of the three files to make sure that they contain the strings, then you can delete both  and.
 * You can do it all in one bash script like this:

Send the .ts file to a translation platform
It is time to have your file translated. You can choose to set up an account on a public translation platform such as Crowdin or Transifex, or you can benefit from our existing FreeCAD-addons account at Crowdin, which has many users already, and therefore more chance to have your file translated quickly and by people who know FreeCAD.

If you wish to host your file on the FreeCAD Crowdin account, get in touch with Yorik on the FreeCAD forum.

some platforms like Crowdin can integrate with GitHub and do all the process from points 2, 3 and 4 automatically. For that, you can’t use the FreeCAD Crowdin account; you will need to set up your own account.

Merge the translations
Once your file has been translated, even if partially, you can download the translations from the site:


 * You will usually download a file containing one  per language
 * Place all the translated files, together with your base  file, in the  folder

Compile the translations
Now run the program on each file that you have.

Możesz zautomatyzować ten proces

You should find one file for each translated  file. The files is what will be used by Qt and FreeCAD at runtime.

That's all you need. Note that certain parts of your workbench cannot be translated on-the-fly if you decide to switch languages. If this is the case, you will need to restart FreeCAD for the new language to take effect.

Testing translations

 * 1) Switch FreeCAD to a language you have translated (ex. German)
 * 2) Load translation into FreeCAD, ex.
 * 3) Test something, ex.

Result: This should give you the German translation. If this works ok, then the basic setup is OK. Then we can look at something else. For ex, command names should always use a special context that is the name of the command as registered to FreeCAD.

Important notes

 * Make sure you are using a *context* and *string* that actually are in the ts/qm file of course.

Convenience script
Yorik maintains a convenience script for the BIM workbench, that can gather, upload and download ts files. You can just copy and adapt that script for your workbench:

https://github.com/yorikvanhavre/BIM_Workbench/blob/master/utils/updateTranslations.py

Important references

 * Why and how to translate functions (forum thread)

Related Pages

 * External Workbenches
 * Localisation
 * For more informations make your requests here Translating external workbenches