You can generate the translation file by running lupdate
on QML file :
lupdate main.qml -ts main.ts
To get the .ts file by running lupdate
on the project .pro file you can use a workaround. From the Qt documentation :
The lupdate tool extracts user interface strings from your
application. lupdate reads your application's .pro file to identify
which source files contain texts to be translated. This means your
source files must be listed in the SOURCES or HEADERS entry in the
.pro file. If your files are not listed the texts in them will not be
found.
However, the SOURCES variable is intended for C++ source files. If you
list QML or JavaScript source files there, the compiler tries to build
them as though they are C++ files. As a workaround, you can use an
lupdate_only{...} conditional statement so the lupdate tool sees the
.qml files but the C++ compiler ignores them.
If you specify your .qml files in the application like :
lupdate_only{
SOURCES = content/main.qml
}
When you run lupdate
on the project .pro, the resulting .ts file will contain the QML translation context.
Note that you must stick to the brace style shown, using an alternate style such as e.g.
# DON'T USE, FAILS!
lupdate_only
{
SOURCES = content/main.qml
}
fails (at least on OS X 10.12 / Qt 5.7) with large amounts of compiler warnings and errors that are far from giving any hint at the actual problem, e.g.
clang: warning: <qml source file>: 'linker' input unused
clang: warning: argument unused during compilation: '-g'
clang: warning: argument unused during compilation: '-isysroot /Applications/Xcode_7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk'
...
clang: error: no such file or directory: 'Page1.o'
clang: error: no such file or directory: 'Page1Form.ui.o'
Alternately, you can use a continuation character:
lupdate_only \
{
SOURCES = content/main.qml
}