Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMake LRELEASE .ts to .qm files
Qt 6.12 LTS is out! See what's new in the release blog

QMake LRELEASE .ts to .qm files

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dhmaster
    wrote on last edited by
    #1

    Hi,
    I'm new in software development and I'm searching for a way to automate the compiling of .ts translation files to .qm files using lrelease.exe in a .pro file. Therefore i need to get the filename out of the .ts filepath and create new .qm files, that $$LRELEASE can compile it and put the .qm files in my DEPLOYMENT_DIR. The following workaround worked for me:

    # this function is for making a full Path that worked for me on windows:
    defineReplace(fixPath) {
        rawPath = $$quote($$system_path($$absolute_path($$1)))
        return ($$rawPath)
    }
    
        # This function creates the translation .qm files in DEPLOYMENTDIR/translation
        # @Param: List with all .ts files
        # @Param example: C://myapp/translations/exampleLanguage.ts
        defineReplace(createQMFiles){
            TRANSLATION_FILES = $$1
    
            fileNames =
            for(translationElement, TRANSLATION_FILES){
                rawTranslations = $$split(translationElement,/)
                file = $$last(rawTranslations)
                fileNames += $$file
            }
    
            fileNamesNoEnding =
            for(fileElement, fileNames){
                rawFileNameNoEnding = $$split(fileElement,.)
                fileNamesNoEnding += $$first(rawFileNameNoEnding)
            }
    
            QM_FILES =
            for(fileNameNoEnding,fileNamesNoEnding){
                QM_FILES += $$fixPath($$join(fileNameNoEnding, .qm, $${DEPLOYMENTDIR}/translations/, .qm))
            }
    
            LRELEASE = $$[QT_INSTALL_BINS]/lrelease #.exe
    
            NEW_TRANSLATIONS =
            for(entry, TRANSLATION_FILES){
                NEW_TRANSLATIONS += $$fixPath($$entry)
            }
    
            for(tsFile, NEW_TRANSLATIONS){
                command = $$LRELEASE $${tsFile} -qm $$take_first(QM_FILES)
                message($$command)
                system($$command)|error("Failed to run: $$command")
            }
            return
        }
    

    I know that this is a really ugly way to do this. The "clean" way described in link did not work for me. Does anyone have a suggestion to do this in a cleaner way?

    more information: I'm using QT version 5.9.7.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved