Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Qt translation (QM)

From ReverseEngineering.wiki
Format
Magic 3C B8 64 18 CA EF 9C 95 CD 21 1C BF 60 A1 BD DD
Extensions .qm
Endianness big
License Qt (LGPL-3.0/GPL-3.0/commercial)
Website https://doc.qt.io/qt-6/linguist-manager.html
On this wiki Facts · Code · Notes · Topics

Compiled translation file of Qt (.qm, made by lrelease from .ts): the 16-byte magic 3C B8 64 18 CA EF 9C 95 CD 21 1C BF 60 A1 BD DD, then tagged blocks (u8 tag, big-endian u32 length) for contexts, a sorted hash table, messages, numerus rules, dependencies and language.

Overview

QTranslator::load reads a .qm file (from disk, or from a Format:Qt resource :/i18n/app_de.qm) and QCoreApplication::translate/tr() look up (context, source text, disambiguation comment) in it. Qt's own strings come as qt_<lang>.qm/qtbase_<lang>.qm next to the program. Part of Library:Qt.

Layout

After the 16-byte magic, the file is a sequence of blocks: uint8 tag, uint32 length (big endian), data. The loader stops at a zero tag or zero length.

Tag Block
0x2f Contexts: uint16 hTableSize, uint16 table[hTableSize] (hash buckets, 0 = empty, otherwise a halfword offset), then lists of context names as uint8 length + bytes, ended by length 0
0x42 Hashes: sorted array of 8-byte pairs (uint32 hash, uint32 offset into the Messages block); hash = ElfHash over source text then comment, 0 mapped to 1
0x69 Messages: records of 1-byte tags (below)
0x88 NumerusRules: plural rule bytecode
0x96 Dependencies: QDataStream list of QString names of further .qm files
0xa7 Language: UTF-8 locale name

A message record is a series of tag bytes: 1 End, 3 Translation (uint32 byteLength, UTF-16 big endian; several for plural forms), 6 SourceText (uint32 length, bytes), 7 Context, 8 Comment (same form), 2/4 older UTF-16 source/context, 5 and 9 obsolete. Lookup hashes the source text (and comment), binary searches the Hashes block, walks equal hashes and compares the stored context/source/comment. lrelease normally keeps source texts, so the English UI strings are readable in a .qm; files compiled with -idbased or -compress differ (unverified).

Identification

First 16 bytes equal the magic (confirmed in qtranslator.cpp, which cites mcookie as its origin). Library:Qt page links here.

Evidence & references

  • https://github.com/qt/qtbase at commit b99cb0eb78d85506ad39afde16a4a268f2c2fdab (dev branch): src/corelib/kernel/qtranslator.cpp lines 50-67 (message tags, magic), do_load and do_translate (block loop, hash search, getMessage); src/corelib/kernel/qtranslator_p.h (block tag enum Contexts 0x2f, Hashes 0x42, Messages 0x69, NumerusRules 0x88, Dependencies 0x96, Language 0xa7).