{"slug": "finding-menu-items-in-31-languages-by-reading-the-app-s-own-translation-files", "title": "Finding menu items in 31 languages by reading the app's own translation files", "summary": "A developer building Movie Engine, an AI agent that drives Kdenlive's Windows UI Automation to reload projects, described reading the app's own shipped translation catalogs to resolve localized control names across 31 languages instead of guessing translations. The approach parses GNU gettext .mo files (kxmlgui6, kconfigwidgets6, kdenlive) with a minimal PowerShell reader and Qt .qm files by computing ELF hashes of source strings, since modern lrelease drops the English source text. The developer noted a Windows PowerShell 5.1 pitfall where the .mo magic number 0x950412de parses as a negative Int32, and that CJK accelerators like ファイル(F) are retained because UI Automation reports them.", "body_md": "*Part 3 of a series on Movie Engine, where an AI agent edits Kdenlive video projects while the editor stays open. Earlier: [Part 1, the overview](https://dev.to/vladtarrow/how-i-let-an-ai-agent-edit-video-in-kdenlive-without-touching-my-mouse-1faa), [Part 2, UI Automation without stealing focus](https://dev.to/vladtarrow/driving-a-windows-desktop-app-from-an-ai-agent-without-stealing-focus-2gg4).*\n\nMovie Engine makes a running Kdenlive reload a project by pressing File > Revert through Windows UI Automation. UI Automation finds controls by their **name**, and the name is whatever the interface shows. In English it is \"File\" and \"Revert\". In German it is \"Datei\" and \"Zuletzt gespeicherte Fassung\". In Japanese it is \"ファイル(F)\" and \"戻す(V)\".\n\nThe launchers start Kdenlive in English by default (`LANGUAGE=en_US`), but a user who prefers their own language sets `MOVIE_ENGINE_UI_LANG=de` and the automation must still work. This post is about where the names come from and how each language is checked.\n\nThe tempting approach is to type the names in from memory or a translation service. That fails quietly: KDE's German for \"Revert\" is not \"Zurücksetzen\", it is \"Zuletzt gespeicherte Fassung\". The only correct source is the translation catalog the program actually loads.\n\nThe portable Kdenlive 26.08.3 for Windows ships them under `bin/data/locale/<lang>/LC_MESSAGES/`. The strings we need come from four files:\n\n| String | File | Format | \n|---|---|---|\n| File (menu) | `kxmlgui6.mo` | GNU gettext | \n| Save, Revert, Open Recent | `kconfigwidgets6.mo` | GNU gettext | \n| Create Folder, \"Loading project\" | `kdenlive.mo` | GNU gettext | \n| Information (message box title) | `kwidgetsaddons6_qt.qm` | Qt Linguist | \n\nGNU `.mo` is a simple binary format: a magic number, a count, and two tables of (length, offset) pairs pointing to the original and the translated strings. Here is a minimal reader in PowerShell (written for this post and checked against the shipped files):\n\n``` php\nfunction Read-Mo([string]$path) {\n    $b = [IO.File]::ReadAllBytes($path)\n    $u32 = { param($o) [BitConverter]::ToUInt32($b, $o) }\n    if ((& $u32 0) -ne 2500072158) { throw 'not a little-endian .mo file' }   # 0x950412de\n    $count = & $u32 8; $orig = & $u32 12; $trans = & $u32 16\n    $utf8 = [Text.Encoding]::UTF8\n    $map = @{}\n    for ($i = 0; $i -lt $count; $i++) {\n        $ol = & $u32 ($orig + 8 * $i); $oo = & $u32 ($orig + 8 * $i + 4)\n        $tl = & $u32 ($trans + 8 * $i); $to = & $u32 ($trans + 8 * $i + 4)\n        # msgctxt is joined to msgid with 0x04, plural forms are split by 0x00\n        $id = $utf8.GetString($b, $oo, $ol).Split([char]4)[-1].Split([char]0)[0]\n        $map[$id] = $utf8.GetString($b, $to, $tl).Split([char]0)[0]\n    }\n    $map\n}\n(Read-Mo \"$loc\\de\\LC_MESSAGES\\kconfigwidgets6.mo\")['Re&vert']   # \"Zuletzt gespeicherte Fassung\" once the & is removed\n```\n\nNotice the magic number is written in decimal. In Windows PowerShell 5.1, `0x950412de` is parsed as a *negative* `Int32`, so comparing it with the unsigned value read from the file always fails. I hit that while writing this post.\n\nThe keys carry the keyboard accelerator: `&File`, `Re&vert`, `Open &Recent`. UI Automation reports names without the `&`, so it is stripped. CJK translations keep the accelerator in brackets at the end, `ファイル(F)`, and that part stays: it is what UIA reports.\n\nQt's `.qm` format surprised me. It is a sequence of tagged blocks (`0x42` hash table, `0x69` messages, ...), and the messages block holds translations as UTF-16BE, but **modern `lrelease` drops the English source text**. Qt looks a message up by an ELF hash of the source string. So to read \"Information\" you hash \"Information\" and follow the hash table:\n\n``` php\n[uint32]$h = 0\nforeach ($c in [Text.Encoding]::UTF8.GetBytes($source)) {\n    $h = (($h -shl 4) -band 0xFFFFFFFFL) + $c\n    $g = $h -band 0xF0000000L\n    if ($g) { $h = $h -bxor ($g -shr 24); $h = $h -band (-bnot $g -band 0xFFFFFFFFL) }\n}\nif (-not $h) { $h = 1 }\n# then: entries of the 0x42 block are (hash, offset into 0x69); at that offset,\n# tag 3 = translation (be32 length + UTF-16BE), tag 7 = context, tag 1 = end of message\n```\n\nThat gives `Informationen` for German, `Ilmoitus` for Finnish, `Bilgi` for Turkish: the same values that are in the engine.\n\nThe engine does not parse catalogs at run time. The names were extracted once and live in `engine/tools/kd-ui.ps1`, English first:\n\n```\n$script:KdNames = @{\n    File    = @('File', 'Файл', 'Datei', 'Fichier', 'Archivo', 'Arquivo', '文件(F)', 'ファイル(F)', 'Plik', ...)\n    Revert  = @('Revert', 'Восстановить', 'Відновити', 'Zuletzt gespeicherte Fassung', 'Annuler', ...)\n    ...\n}\nfunction New-KdNameCondition([string]$key) {\n    $conds = @($script:KdNames[$key] | ForEach-Object {\n        New-Object System.Windows.Automation.PropertyCondition($script:KdAE::NameProperty, $_) })\n    if ($conds.Count -eq 1) { return $conds[0] }\n    New-Object System.Windows.Automation.OrCondition(, [System.Windows.Automation.Condition[]]$conds)\n}\n```\n\nOne `OrCondition` covers every language at once, so the code that opens the File menu does not need to know which language is running. Dialog titles (\"Information\", \"Loading project\", the \"revert to last saved version?\" question) are matched by regular expressions built the same way. Several languages share a word (\"Fil\" is the File menu in Danish and Norwegian Bokmål, \"Datoteka\" in Bosnian, Croatian and Slovenian), so the File list has fewer entries than there are languages.\n\nThe supported set is 31 interface languages: en, ru, uk, de, fr, es, pt_BR, zh_CN, ja, it, pl, ar, bs, ca, cs, da, el, et, fi, ga, hr, hu, lt, lv, nb, nl, ro, sk, sl, sv, tr.\n\nA name table is only a claim until a real Kdenlive in that language confirms it. `engine/tools/kd-langcheck.ps1` starts a throw-away Kdenlive with `MOVIE_ENGINE_UI_LANG` set, on a separate Windows desktop created by `kd-hidden.ps1` (`CreateDesktop`, so it can never take my focus). It reads the menu bar, finds the File menu and the Save button, expands File and looks for Revert and Open Recent:\n\n``` php\n$menu = $file.GetCurrentPattern([System.Windows.Automation.ExpandCollapsePattern]::Pattern)\ntry { $menu.Expand() } catch { }\nfor ($i = 0; $i -lt 30 -and -not ($revert -and $recent); $i++) {\n    Start-Sleep -Milliseconds 200\n    if (-not $revert) { $revert = Find-KdNamed $file 'Revert' }\n    if (-not $recent) { $recent = Find-KdNamed $file 'Recent' }\n}\n```\n\nIt exits 0 only when all four were found. Each run's report is kept in `docs/proof/language-<lang>.txt`, for example:\n\n```\nlanguage check, 2026-11-23 05:12, MOVIE_ENGINE_UI_LANG='ja'\nmenu bar: ファイル(F) | 編集 | ビュー | メディア | シーケンス | ツール | モニタ | マーカー | 設定(S) |  | ヘルプ(H)\nFile menu found: True as 'ファイル(F)'\nSave button found: True as '保存(S)'\nRevert item found: True as '戻す(V)'\n```\n\nThe German check passed, but its menu bar looked like this:\n\n```\nmenu bar: Datei | Bearbeiten | Ansicht | Мультимедиа | Последовательность | Werkzeug | ...\n```\n\n\"Media\" and \"Sequence\" are Russian. Those strings are missing from the German translation, and instead of falling back to English, the missing ones fell back to the **Windows display language** of the test machine, which is Russian. The four items the engine needs are translated, so the check passes, but it is a reminder that an interface can mix languages, and that a table built on one PC is only proven for what it actually checked.\n\nTwo more notes from the docs: a language Kdenlive has no `kdenlive.mo` for (for example Swahili or Amharic) shows English menus, which already work. Adding a new language means adding its names to `kd-ui.ps1` and running `kd-langcheck.ps1` with `MOVIE_ENGINE_UI_LANG` set to it.\n\n`.mo` is easy to parse; `.qm` needs the ELF hash of the source text.\nWindows only, Kdenlive 26.08.3, MIT licensed: **[https://github.com/vladtarrow/movie-engine](https://github.com/vladtarrow/movie-engine)**. To try it, clone the repo and run:\n\n```\n.\\setup.cmd\n```\n\n", "url": "https://wpnews.pro/news/finding-menu-items-in-31-languages-by-reading-the-app-s-own-translation-files", "canonical_source": "https://dev.to/vladtarrow/finding-menu-items-in-31-languages-by-reading-the-apps-own-translation-files-l2c", "published_at": "2026-11-23 04:04:40+00:00", "updated_at": "2026-11-23 04:11:49.370695+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["Movie Engine", "Kdenlive", "KDE", "Qt", "Windows UI Automation", "PowerShell"], "also_reported_by": [], "takeaway": "Resolve localized UI Automation control names from the app's shipped gettext .mo and Qt .qm catalogs rather than typed translations, hashing source strings with Qt's ELF hash for .qm lookups and comparing the .mo magic number as unsigned (2500072158) to avoid PowerShell 5.1's negative Int32 parse.", "recommendation": {"advice": "Read control names from the app's own .mo/.qm catalogs and strip '&' accelerators, keeping CJK bracketed accelerators, so UI Automation agents work under any UI language.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/finding-menu-items-in-31-languages-by-reading-the-app-s-own-translation-files", "markdown": "https://wpnews.pro/news/finding-menu-items-in-31-languages-by-reading-the-app-s-own-translation-files.md", "text": "https://wpnews.pro/news/finding-menu-items-in-31-languages-by-reading-the-app-s-own-translation-files.txt", "jsonld": "https://wpnews.pro/news/finding-menu-items-in-31-languages-by-reading-the-app-s-own-translation-files.jsonld"}}