Localization Older Methods/it: Difference between revisions

From FreeCAD Documentation
(Created page with "Compilando il file <tt>.ts</tt> dell'esempio precedente, si crea un file di di intestazione ''MyMod_de.h''. La posizione migliore per memorizzare questo file è ''App<Modul>Gu...")
(Created page with "per pubblicare la traduzione nell'applicazione.")
Line 88: Line 88:
new Gui::LanguageProducer("Deutsch", <Modul>_de_h_data, <Modul>_de_h_len);
new Gui::LanguageProducer("Deutsch", <Modul>_de_h_data, <Modul>_de_h_len);
}}
}}
per pubblicare la traduzione nell'applicazione.
to publish your translation in the application.


=== Setting up python files for translation ===
=== Setting up python files for translation ===

Revision as of 21:54, 30 August 2018

Other languages:

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

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.

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> 

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

Branding
Extra python modules