Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. how to embed translation files?
Forum Update on Monday, May 27th 2025

how to embed translation files?

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
4 Posts 2 Posters 749 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.
  • R Offline
    R Offline
    r0ller
    wrote on last edited by
    #1

    Hi All,

    I'm trying to embed a translation (qm) file in the wasm app using the --embed-file option which I successfully used earlier in pure c++ projects. But I don't even know if it gets embedded at all since nothing complains about not being able to find the file. However, when loading it via translator.load(), I get back false as result. I suspect that the relative path may come in to play here. The emscripten doc (https://emscripten.org/docs/porting/files/packaging_files.html) says at the embed option:

    "By default, the files to be packaged should be nested in or below the compile-time command prompt directory. At runtime the same nested file structure is mapped to the virtual file system, with the root corresponding to the command prompt directory."

    How do I know what's the "compile-time command prompt directory" when I hit the build button? Currently, I just add these two lines to my project file:

    QMAKE_CFLAGS += --embed-file test_en.qm
    QMAKE_CXXFLAGS += --embed-file test_en.qm

    The file is currently in the project directory but according to the emscripten docs, it will only be picked up if emcc/em++ is called from the project directory. I also tried copying the translation file over to the build directory hoping that it gets picked up but that does not work either. Thanks for any hints in advance!

    Best regards,
    r0ller

    1 Reply Last reply
    0
    • R Offline
      R Offline
      r0ller
      wrote on last edited by
      #2

      Ok, managed to figure it out:

      1. The embedding flag must be passed to the linker (makes sense actually) like: QMAKE_LFLAGS += --embed-file test_en.qm
      2. The compile-time directory taken into account is not the project but the build directory so in the project file (.pro) the path for --embed-file must be specified relative to that. In 1. above it will expect that test_en.qm resides in the build directory. When calling QTranslator::load(), the path shall be the same as in the project file. So in my case it's just translator.load("test_en") as I simply copied the qm file to the build directory for the test.
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Out of curiosity, why not use Qt's resource system ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • R Offline
          R Offline
          r0ller
          wrote on last edited by
          #4

          I'm pretty new to Qt and did not know anything about the resource system :) So I simply googled for qml internationalization and in the results this page seemed appropriate:

          https://doc.qt.io/qt-5/qtquick-internationalization.html

          That one pointed to the Qt Linguist Manual: https://doc.qt.io/qt-5/qtlinguist-index.html

          On that page the developers section seemed relevant: https://doc.qt.io/qt-5/linguist-programmers.html

          Which referenced a simple example: https://doc.qt.io/qt-5/qtlinguist-hellotr-example.html

          So that's the reason how I ended up with this :) I can't recall that those pages mention the resource system. Thanks for the link by the way! I'll read that page to see if it's a better choice. But I guess the file embedding lesson learned here will come handy in that case as well.

          1 Reply Last reply
          3

          • Login

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