Vecchi metodi di localizzazione
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
- 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.
- FreeCAD main GUI
- Complete Workbench
- Drawing Workbench
- Draft Workbench
- Reverse Engineering Workbench
- FEM Workbench
- Robot Workbench
- Image Workbench
- Sketcher Workbench
- Mesh Workbench
- Test Workbench
- Points Workbench
- Raytracing Workbench
- Part Workbench
- PartDesign Workbench
- Assembly Workbench
- 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
Preparare i propri moduli o applicazioni per la traduzione
Prerequisiti
Per realizzare la traduzione del modulo dell'applicazione servono delle utility fornite con Qt. Esse si possono scaricare da Trolltech-Website, ma sono anche contenute in LibPack:
- qmake
- Genera i file del progetto
- lupdate
- Estrae o aggiorna i testi originali del progetto tramite la scansione del codice sorgente
- Qt-Linguist
- Qt-Linguist è molto facile da usare, agevola la traduzione con pratiche funzioni e dispone di un frasario per le espressioni più comuni.
Setup del progetto
Per iniziare la localizzazione del proprio progetto andare alla GUI-Part del modulo e digitare sulla riga di comando:
qmake -project
Questo esegue la scansione della directory del progetto alla ricerca dei file contenenti stringhe di testo e crea un file di progetto come nel seguente esempio:
###################################################################### # 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
È possibile aggiungere manualmente i file qui. La sezione TRANSLATIONS contiene un elenco di file con la traduzione per ogni lingua. Nell'esempio precedente MyMod_de.ts è la traduzione in tedesco.
Ora è necessario eseguire lupdate per estrarre tutte le stringhe letterali nella propria GUI. Eseguire lupdate dopo le modifiche del codice sorgente è sempre una operazione sicura in quanto non cancella mai stringhe dai file di traduzione. Aggiunge solo le nuove stringhe.
Ora è necessario aggiungere i file .ts al proprio progetto VisualStudio. Specificare per essi il seguente metodo di costruzione personalizzato:
python ..\..\..\Tools\qembed.py "$(InputDir)\$(InputName).ts"
"$(InputDir)\$(InputName).h" "$(InputName)"
Nota: Inserire questo comando in un'unica riga, l'interruzione di riga è finalizzata solo alla visualizzazione.
Compilando il file .ts dell'esempio precedente, si crea un file di di intestazione MyMod_de.h. La posizione migliore per memorizzare questo file è App<Modul>Gui.cpp. In questo esempio potrebbe essere AppMyModGui.cpp. Aggiungere lì la riga:
new Gui::LanguageProducer("Deutsch", <Modul>_de_h_data, <Modul>_de_h_len);
per pubblicare la traduzione nell'applicazione.
Configurare i file python per la traduzione
Per facilitare la localizzazione dei file .py è possibile utilizzare lo strumento pylupdate4 che accetta uno o più file .py. Con l'opzione -ts si può preparare / aggiornare uno o più file .ts. Ad esempio per preparare un file .ts per la traduzione in francese è sufficiente inserire nella riga di comando:
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>
e eseguire pyrcc4 Draft.qrc -o qrc_Draft.py che crea un grande file Python contenente tutte le risorse. Questo metodo funziona anche per inserire i file di icona in un file di risorse