Can Qt lrelease tool process XLIFF files instead of ts-files? - qt

In the documentation of the Qt lrelease tool I read, that .ts files can be compiled to .qm binaries using following command:
lrelease.exe main_en.ts languages\main_fr.ts
Is it possible to take .xliff files as well as input instead of the .ts files to compile .xliff files to .qm files? How is it done?

From the documentation of lupdate, it is mentioned that you can generate .ts file from XLIFF files. You can then use lrelease to generate the .qm file.
Be aware that only the XLIFF 1.1 format is supported, not the 1.0.

To convert a xliff file to ts, you can use the lconvert utility with a command line like this:
lconvert -o converted.ts -i original.xlf
Here is the output of lconvert -help:
Usage:
lconvert [options] [...]
lconvert is part of Qt's Linguist tool chain. It can be used as a
stand-alone tool to convert and filter translation data files. The
following file formats are supported:
qm - Compiled Qt translations
pot - GNU Gettext localization template files
ts11 - Qt translation sources (format 1.1)
ts20 - Qt translation sources (format 2.0)
qph - Qt Linguist 'Phrase Book'
ts - Qt translation sources (latest format)
po - GNU Gettext localization files
xlf - XLIFF localization files
If multiple input files are specified, they are merged with
translations from later files taking precedence.
Options:
-h
--help Display this information and exit.
-i <infile>
--input-file <infile>
Specify input file. Use if <infile> might start with a dash.
This option can be used several times to merge inputs.
May be '-' (standard input) for use in a pipe.
-o <outfile>
--output-file <outfile>
More info here about this Qt tool

Related

run lupdate and lrelease command from qt creator in linux

I want to run lupdate and lrelease command from qtcreator at the time of build.
Is it possible?
If yes then how?
Note: I am using lupdate and lrelease command from linux terminal and its working fine but i want to run these commands from qt creator at the time of build.
Assuming you're using qmake, you should use the TRANSLATIONS variable:
https://doc.qt.io/qt-5/qmake-variable-reference.html#translations
This page has some examples:
HEADERS = main-dlg.h \
options-dlg.h
SOURCES = main-dlg.cpp \
options-dlg.cpp \
main.cpp
FORMS = search-dlg.ui
TRANSLATIONS = superapp_dk.ts \
superapp_fi.ts \
superapp_no.ts \
superapp_se.ts
The Hello tr() Example explains the process in more detail:
Note that the file extension is .ts, not .qm. The .ts translation
source format is designed for use during the application's
development. Programmers or release managers run the lupdate program
to generate and update TS files with the source text that is extracted
from the source code. Translators read and update the TS files using
Qt Linguist adding and editing their translations.
[...]
Once the translations are complete the lrelease program is used to
convert the TS files into the QM Qt message file format. The QM format
is a compact binary format designed to deliver very fast lookup
performance. Both lupdate and lrelease read all the project's source
and header files (as specified in the HEADERS and SOURCES lines of the
project file) and extract the strings that appear in tr() function
calls.
lupdate is used to create and update the message files (hellotr_la.ts
in this case) to keep them in sync with the source code. It is safe to
run lupdate at any time, as lupdate does not remove any information.
For example, you can put it in the makefile, so the TS files are
updated whenever the source changes.
in your Qt Creator, go to Projects > Build Steps
there you can add two Custom Process Steps with your commands lupdate and lrelease

Qt lupdate in .pro file issue

I had to mark some of the .xml files for internationalization. I do not use lupdate manually from cmd, instead I put it in the project's .pro file like:
lupdate_only{
SOURCES += $$EXTRA_XML
}
The above code works just fine, but as you noticed I had to put the xml files in SOURCES. As a consequence the .xml files appear in the Sources virtual folder from the left Projects' perspective window, just next to the .cpp files. I find this solution a bit nasty and confusing.
- Project
- - Headers
- - Sources
- - - main.cpp
- - - some.xml //not wanted here
Is there a way to use lupdate, in .pro, on different files such that those files won't appear in the Sources folder? Thanks!
UPDATE
I use Qt Creator 4.0.3
lupdate_only {
SOURCES += $$EXTRA_XML
}
With this conditional statement, lupdate tool sees the .qml files but qmake will ignore it.
I found the solution to my problem, however I think it's a Qt Creator bug. I just moved the lupdate statement with its contents into a .pri file and now the xml files do not appear under the Sources virtual folder. (the .pri file is included in .pro)

How to convert GNU Gettext .po files to Qt's .ts files?

Is there a tool to convert the translations in GNU Gettext .po format into Qt's native .ts format?
Today I found that it could be done using the lconvert tool that comes with the Qt distribution and had already been present on my system.
So I simply did
lconvert -locations relative <file>.po -o <file>.ts
It also supports the backward conversion:
lconvert <file>.ts -o <file>.po
You could use po2ts which is meant for exactly this task. It is part of the Translate Toolkit which you can download for your appropriate platform.

how to create header file and source file of a .ui file in Qtdesigner?

I have an application in which i have a mainwindow.ui file and i create a new designer file dialoge.ui in same application now how i can create source file and header file for dialoge.ui .I am using QtCreater(windows).
I am a beginner in qt , i think there should be a way for the same but i am not getting.
Help me.
Thanks
You can create source & header out of .ui file externally & then import them into your application(Dont forget to reference then in the .pro file.). Create a executable(.bat or .exe) to execute following commands. Below is the shell script(I am a linux user.)
echo HEADERS
<path to your uic compiler>/uic -o form.h form.ui
echo SOURCES
<path to your uic compiler>/uic -i form.h -o form.cpp form.ui
For each file somewidget.ui, during the build process ui_somewidget.h and ui_somewidget.cpp will be created. The tool used to generate them is uic.
All you have to make sure that the .ui files are added to the .pro file of your project, along with the other source and header files, like this:
FORMS += somewidget.ui
qmake/make will automatically generate and build the .cpp and .h files for somewidget.ui.
you can do this:
Save your dialoge.ui file in a directory.
Use qmake to create the .pro file (qmake -project), qmake is smart enough to detect the .ui.
This will also generate the appropriate makefile rules to invoke uic, Qt's user interface compiler.
If you are using visual studio, you can call qmake -tp vc, this will generate a visual studio project, linked and ready to use.
The visual studio project will generate a ui_dialoge.h for you, you can copy this to another project and use it in another header file which will use this dialoge.ui
I'm not sure I've completely understood your question. You have an application developed in QtCreator in which you have 2 .ui files. And you want to generate the corresponding header/source files to these 2 files.
Using QtCreator you don't need to worry about generating header files. This is done automatically. During the build phase, the User Interface Compiler (uic) is called and translates the .xml files into c++ header files.
Additionally to the already correct answers: change from Debug to Release mode in the general settings. In my case, the header file wasn't created in Debug mode

linking a .proto file using qmake

I have 4 files
message.proto
udp.h
udp.cpp
main.cpp
message.proto is a google protocol buffer file. I am trying to write a protocol buffer and send and receive data using UDP. udp.h and udp.cpp are just classes to implement UDP.
I can write my own makefile and do the needful for this small example. Later I would require to integrate this code into my QT program. I am using qmake -project, qmake to generate the Makefile. I am using Ubuntu 9.10
Could some one tell me the changes I need to make in the .pro file or the Makefile generated by qmake to satisfy the dependencies.
Usually you just need to add the respective header and source files to the corresponding HEADERS and SOURCES variables in the .pro file, i.e.
SOURCES += udp.cpp message.pb.cc
HEADERS += udp.h message.pb.h
where I implicity assumed that message.pb.cc and message.pb.h are the files generated by protoc (the protocol buffer compiler). If you additionally want the generated makefile to run protoc for you, you can accomplish that with the system function (http://doc.trolltech.com/4.6/qmake-function-reference.html#system-command).
I hope that helps.

Resources