<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QMake LRELEASE .ts to .qm files]]></title><description><![CDATA[<p dir="auto">Hi,<br />
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:</p>
<pre><code># 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
    }
</code></pre>
<p dir="auto">I know that this is a really ugly way to do this.  The "clean" way described in <a href="https://wiki.qt.io/Automating_generation_of_qm_files" target="_blank" rel="noopener noreferrer nofollow ugc">link</a> did not work for me. Does anyone have a suggestion to do this in a cleaner way?</p>
<p dir="auto">more information: I'm using QT version 5.9.7.</p>
]]></description><link>https://forum.qt.io/topic/116770/qmake-lrelease-ts-to-qm-files</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 10:55:46 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116770.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Jul 2020 08:34:01 GMT</pubDate><ttl>60</ttl></channel></rss>