Localizing Qt Quick Apps


  • Qt Champions 2016

    while evaluating Qt 5.6 for Android / iOS and preparing blogs with recipes for BlackBery Cascades developers HowTo go with Qt 5.6 I run into a problem.

    Using Cascades (qt 4.8) and Eclipse Momentics translation is easy:

    Open Projectfile (bardescriptor.xml)
    add languages
    

    and you're done. All the work under the hood: creation of .ts files and generating .qm files was done automagically.
    I only had to use QtLinguist, translate the strings, save, go back to Eclipse Momentics, refresh and run on device.

    Have expected something similar with Qt Creator and learned that there are many (for newcomers confusing - steps of file creation, copy files, running commands from commandline ...:
    https://blog.qt.io/blog/2014/03/19/qt-weekly-2-localizing-qt-quick-apps/

    fortunately I found this article:
    https://wiki.qt.io/Automating_generation_of_qm_files

    then looked at the .pro from mentioned sample:
    https://qt.gitorious.org/qt-labs/weather-app?p=qt-labs:weather-app.git;a=blob_plain;f=weatherapp.pro;hb=HEAD

    tried to understand all what happened inside the .pro and thought that I added the important parts to a .pro file from my sample. project.
    Here's the .pro - the part below qml.qrc was inserted by me

    TEMPLATE = app
    
    QT += qml quick
    
    CONFIG += c++11
    
    SOURCES += main.cpp
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    
    RESOURCES += qml.qrc
    
    # var, prepend, append
     defineReplace(prependAll) {
         for(a,$$1):result += $$2$${a}$$3
         return($$result)
     }
    # Supported languages
    LANGUAGES = de en
    # Available translations
    TRANSLATIONS = $$prependAll(LANGUAGES, $$PWD/translations/EkkesSampleApp_, .ts)
    # Used to embed the qm files in resources
    TRANSLATIONS_FILES =
    # run LRELEASE to generate the qm files
    qtPrepareTool(LRELEASE, lrelease)
     for(tsfile, TRANSLATIONS) {
         qmfile = $$shadowed($$tsfile)
         qmfile ~= s,\\.ts$,.qm,
         qmdir = $$dirname(qmfile)
         !exists($$qmdir) {
             mkpath($$qmdir)|error("Aborting.")
         }
         command = $$LRELEASE -removeidentical $$tsfile -qm  $$qmfile
         system($$command)|error("Failed to run: $$command")
         TRANSLATIONS_FILES += $$qmfile
     }
    
     # TRANSLATIONS - Create extra targets for convenience
     wd = $$replace(PWD, /, $$QMAKE_DIR_SEP)
     # LUPDATE - Make new targets for each and all languages
     qtPrepareTool(LUPDATE, lupdate)
     LUPDATE += -locations relative -no-ui-lines
     TSFILES = $$files($$PWD/translations/QuickForecast_*.ts) $$PWD/translations/EkkesSampleApp_untranslated.ts
     for(file, TSFILES) {
         lang = $$replace(file, .*_([^/]*)\\.ts, \\1)
         v = ts-$${lang}.commands
         $$v = cd $$wd && $$LUPDATE $$SOURCES $$APP_FILES -ts $$file
         QMAKE_EXTRA_TARGETS += ts-$$lang
     }
    

    Getting an error:

    12:14:37: Starting: "/usr/bin/make" 
    /daten/_QT/5.6/android_armv7/bin/qmake -spec android-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../EkkesSampleApp/EkkesSampleApp.pro
    lrelease error: Cannot open /daten/_qt_work/EkkesSampleApp/translations/EkkesSampleApp_de.ts: No such file or directory
    Project ERROR: Failed to run: /daten/_QT/5.6/android_armv7/bin/lrelease -removeidentical /daten/_qt_work/EkkesSampleApp/translations/EkkesSampleApp_de.ts -qm /daten/_qt_work/build-EkkesSampleApp-Android_f_r_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/translations/EkkesSampleApp_de.qm
    make: *** [Makefile] Error 3
    12:14:37: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project EkkesSampleApp (kit: Android für armeabi-v7a (GCC 4.9, Qt 5.6.0))
    When executing step "Make"
    

    Am I missing anything ?
    Or do I have to add something to the project ?
    Tried creating the folder translations inside project outside QtCreator from OSX Finder but didn't help.
    Or must folders added another way from inside Qt Creator ?


  • Lifetime Qt Champion

    Hi,

    Did you call lupdate once before calling lrelease ?


  • Qt Champions 2016

    @SGaist I did it exactly as described above.
    there's a lupdate at the end

    I followed the sample from wiki

    please can you tell me what exactly I should insert into the .pro and where ?

    this kind of stuff is new for me - in cascades it was handled automatically udner the hood

    thanks


  • Lifetime Qt Champion

    I meant call it by hand the first time to generate the .ts files


  • Qt Champions 2016

    @SGaist generation of qm files works if at first lupdate was run manually.
    so the part of creation of ts files from
    https://wiki.qt.io/Automating_generation_of_qm_files
    doesn't work as expected


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.