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. internationalization support
QtWS25 Last Chance

internationalization support

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
translations
15 Posts 4 Posters 1.3k 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.
  • G Offline
    G Offline
    Gilboonet
    wrote on 27 Jun 2023, 20:02 last edited by
    #1

    Hello, I'm currently adding internationalization support to my Qt C++ application, and I tried to compile it for WA, and apparently it is not handled. I was hoping it could be simply using the .qm files, but I will simply have one project for each language, each one having its huge .wasm file. If there is a better way I would be happy to try it.

    J 1 Reply Last reply 28 Jun 2023, 10:37
    1
    • J JonB
      30 Jun 2023, 08:11

      @Gilboonet
      Great to hear. Sorry I wasted my time trying to help you. Stick to your relative paths, they are good. Best of luck.

      G Offline
      G Offline
      Gilboonet
      wrote on 30 Jun 2023, 09:39 last edited by
      #14

      @JonB Well, here is is, by simply using Qt Resource System, it is working, absolutely not due to anything from you but all others who gave me good hints to follow instead of only criticizing.
      Screenshot_20230630_113404.png
      ( the menu is originally on french and using embedded resource .qm it is translated accorgindly to browser language.

      J 1 Reply Last reply 30 Jun 2023, 09:48
      0
      • G Gilboonet
        27 Jun 2023, 20:02

        Hello, I'm currently adding internationalization support to my Qt C++ application, and I tried to compile it for WA, and apparently it is not handled. I was hoping it could be simply using the .qm files, but I will simply have one project for each language, each one having its huge .wasm file. If there is a better way I would be happy to try it.

        J Offline
        J Offline
        JasonWong
        wrote on 28 Jun 2023, 10:37 last edited by JasonWong
        #2

        @Gilboonet

        In WASM, you can load the qm file like a normal Qt program, and then install it in the program, such as qApp->installTranslator. Why do you say that the qm file cannot be used?

        My WASM program can use qm files normally. It should be noted that these qm files are in qrc, not http/local files

        G 1 Reply Last reply 28 Jun 2023, 11:53
        1
        • J JasonWong
          28 Jun 2023, 10:37

          @Gilboonet

          In WASM, you can load the qm file like a normal Qt program, and then install it in the program, such as qApp->installTranslator. Why do you say that the qm file cannot be used?

          My WASM program can use qm files normally. It should be noted that these qm files are in qrc, not http/local files

          G Offline
          G Offline
          Gilboonet
          wrote on 28 Jun 2023, 11:53 last edited by
          #3

          @JasonWong Thank you for your answer. What I did is simply first develop my application for desktop, with anything need for translation, and when it worked, I tried to compile it for WA, it compiles but even when I was with english locale it appears as in french (which is my default and was the language used on the Qt C++ project).

          I am brand new to Qt ecosystem and it's yesterday that I learnt that ":/" at the start of a directory string means that it uses Qt Resource System. But it was because of that ":/" that my Qt C++ Desktop application didn't work when I added internationalization code. So I certainly need to make it work correctly with that ":/" to have it also working for WA.

          J 1 Reply Last reply 28 Jun 2023, 12:11
          0
          • G Gilboonet
            28 Jun 2023, 11:53

            @JasonWong Thank you for your answer. What I did is simply first develop my application for desktop, with anything need for translation, and when it worked, I tried to compile it for WA, it compiles but even when I was with english locale it appears as in french (which is my default and was the language used on the Qt C++ project).

            I am brand new to Qt ecosystem and it's yesterday that I learnt that ":/" at the start of a directory string means that it uses Qt Resource System. But it was because of that ":/" that my Qt C++ Desktop application didn't work when I added internationalization code. So I certainly need to make it work correctly with that ":/" to have it also working for WA.

            J Offline
            J Offline
            JonB
            wrote on 28 Jun 2023, 12:11 last edited by
            #4

            @Gilboonet

            • :/ is special to Qt and indicates the file is actually a Qt resource embedded within the generated executable.
            • Without the leading :/ it refers to an external file.

            I don't know anything about QML or translator files, whether they work with or without resources or you can choose. But you should discover how WebAssembly access resource files if they are allowed, or external files, depending on which you use.

            G 1 Reply Last reply 28 Jun 2023, 12:47
            0
            • J JonB
              28 Jun 2023, 12:11

              @Gilboonet

              • :/ is special to Qt and indicates the file is actually a Qt resource embedded within the generated executable.
              • Without the leading :/ it refers to an external file.

              I don't know anything about QML or translator files, whether they work with or without resources or you can choose. But you should discover how WebAssembly access resource files if they are allowed, or external files, depending on which you use.

              G Offline
              G Offline
              Gilboonet
              wrote on 28 Jun 2023, 12:47 last edited by
              #5

              @JonB No QML for this project, It's Qt C++. Indeed for the moment I started making it as a Desktop project, and after I made installer for Linux and Windows, I tried to compile it for WA and it worked even if I needed to change the way it accessed local files to be able to save/load in order to make it fully usable on a browser. Then I tried to add 3d support and it was not possible using Qt3D so I tried QML but didn't find a way to access local files from QML, so I fallback to OpenGL ES 2.0 3D that works for WA but what was easy to do using Qt3D seems much harder with that. Then I finally added translation and I need to dig the way WA access resources files again to use the .qm files.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on 29 Jun 2023, 07:13 last edited by
                #6

                Within Qt, i.e. QFile, it doesn't matter if you have a regular file or an embedded file. In any case you install the translation with the corresponding path. I don't use WA, so I don't know how to access local files there. In order to embed a file you need to create a resource file (.qrc) and add the .qm file into it. Only then can you use paths starting with :/. And embedded files are part of the executable which hopefully work even when local files don't work with WA.

                Concerning local files: Are you using relative paths to access them? Then maybe the web app is running in a different folder than you are assuming. First try with absolute paths (just for testing) to see if local files work at all.

                G 1 Reply Last reply 29 Jun 2023, 08:29
                1
                • S SimonSchroeder
                  29 Jun 2023, 07:13

                  Within Qt, i.e. QFile, it doesn't matter if you have a regular file or an embedded file. In any case you install the translation with the corresponding path. I don't use WA, so I don't know how to access local files there. In order to embed a file you need to create a resource file (.qrc) and add the .qm file into it. Only then can you use paths starting with :/. And embedded files are part of the executable which hopefully work even when local files don't work with WA.

                  Concerning local files: Are you using relative paths to access them? Then maybe the web app is running in a different folder than you are assuming. First try with absolute paths (just for testing) to see if local files work at all.

                  G Offline
                  G Offline
                  Gilboonet
                  wrote on 29 Jun 2023, 08:29 last edited by
                  #7

                  @SimonSchroeder For the moment I only tried to run the Web app (I mean with internationalization code) from Qt Creator. I'm using relative path, as I give a filename and a folder to translator.load(). I can change the folder to an absolute path, but I will also try to create a ressource file.

                  J 1 Reply Last reply 29 Jun 2023, 08:55
                  0
                  • G Gilboonet
                    29 Jun 2023, 08:29

                    @SimonSchroeder For the moment I only tried to run the Web app (I mean with internationalization code) from Qt Creator. I'm using relative path, as I give a filename and a folder to translator.load(). I can change the folder to an absolute path, but I will also try to create a ressource file.

                    J Offline
                    J Offline
                    JonB
                    wrote on 29 Jun 2023, 08:55 last edited by
                    #8

                    @Gilboonet
                    If you give any kind of relative path in your code you are relying on what the current working directory is when you run your application. And you don't know what that might be. Certainly it is likely to be different from what it is when you run from Creator.

                    Paths for this sort of thing should always be either absolute file paths (possibly built with the help of QStandardPaths) or embedded resources paths. However these two work with WebAssembly. Using any relative path is just asking for trouble....

                    G 1 Reply Last reply 29 Jun 2023, 09:26
                    2
                    • J JonB
                      29 Jun 2023, 08:55

                      @Gilboonet
                      If you give any kind of relative path in your code you are relying on what the current working directory is when you run your application. And you don't know what that might be. Certainly it is likely to be different from what it is when you run from Creator.

                      Paths for this sort of thing should always be either absolute file paths (possibly built with the help of QStandardPaths) or embedded resources paths. However these two work with WebAssembly. Using any relative path is just asking for trouble....

                      G Offline
                      G Offline
                      Gilboonet
                      wrote on 29 Jun 2023, 09:26 last edited by Gilboonet
                      #9

                      @JonB You're going too far too fast but as what I read from your posts you're prone to do so. It's not that I use any relative path, just that I used a function that needs one file name and one folder, function that was an example given by someone here and that worked on the Desktop Application it was given for. I simply start by using that working code and compile for Web Assembly to start from somewhere, but I would be happy to learn a way to get out of trouble from the start, digging into a new field where people here say that they don't use. And how is it that now you tell something about WebAssembly when just a few post before you told that you knew nothing about it (sorry I mismatch WA and QML)?

                      J 1 Reply Last reply 29 Jun 2023, 10:44
                      0
                      • G Gilboonet
                        29 Jun 2023, 09:26

                        @JonB You're going too far too fast but as what I read from your posts you're prone to do so. It's not that I use any relative path, just that I used a function that needs one file name and one folder, function that was an example given by someone here and that worked on the Desktop Application it was given for. I simply start by using that working code and compile for Web Assembly to start from somewhere, but I would be happy to learn a way to get out of trouble from the start, digging into a new field where people here say that they don't use. And how is it that now you tell something about WebAssembly when just a few post before you told that you knew nothing about it (sorry I mismatch WA and QML)?

                        J Offline
                        J Offline
                        JonB
                        wrote on 29 Jun 2023, 10:44 last edited by JonB
                        #10

                        @Gilboonet said in internationalization support:

                        You're going too far too fast

                        I have no idea what this means, or what the rest of your post adds up to.

                        It's not that I use any relative path

                        You wrote earlier:

                        I'm using relative path

                        That's me being "prone to do so" is it?

                        I explained what happens to a relative path. I explained that it will probably differ in what it resolves to between running desktop from Creator, running desktop outside Creator and running WebAssembly version. As a developer I'm sure you know what the current directory is, and how that works. If you really have a relative path then best of luck.

                        One thing you could do: in your code immediately before passing whatever path you do to the translator check what QFile::exists() returns on the identical path. If it's false you have a problem.

                        Anyway I don't know about WebAssembly so I will leave you to it.

                        G 1 Reply Last reply 30 Jun 2023, 07:17
                        1
                        • G Offline
                          G Offline
                          Gilboonet
                          wrote on 30 Jun 2023, 07:11 last edited by
                          #11

                          Looking at the documentation about Qt Resource System, I found an entry that seems to miss what needs to be added to the QMake project file (it's blank). I found it on the online version of the doc. Maybe this needs to be updated ?

                          Screenshot_20230630_090644.png

                          1 Reply Last reply
                          0
                          • J JonB
                            29 Jun 2023, 10:44

                            @Gilboonet said in internationalization support:

                            You're going too far too fast

                            I have no idea what this means, or what the rest of your post adds up to.

                            It's not that I use any relative path

                            You wrote earlier:

                            I'm using relative path

                            That's me being "prone to do so" is it?

                            I explained what happens to a relative path. I explained that it will probably differ in what it resolves to between running desktop from Creator, running desktop outside Creator and running WebAssembly version. As a developer I'm sure you know what the current directory is, and how that works. If you really have a relative path then best of luck.

                            One thing you could do: in your code immediately before passing whatever path you do to the translator check what QFile::exists() returns on the identical path. If it's false you have a problem.

                            Anyway I don't know about WebAssembly so I will leave you to it.

                            G Offline
                            G Offline
                            Gilboonet
                            wrote on 30 Jun 2023, 07:17 last edited by
                            #12

                            @JonB Well I said I used a relative path AND added as i used a filename and a folder, that's certainly the fact that the folder part was not absolute that can lead to it being relative, that's not the same thing, and YES that is you being once again prone to going too far too fast, period. it's good news that you leave this to me, as on almost all your posts you start with stating that you don't know about this and that, then at the end you didn't help but only hammered things we all already know.

                            J 1 Reply Last reply 30 Jun 2023, 08:11
                            0
                            • G Gilboonet
                              30 Jun 2023, 07:17

                              @JonB Well I said I used a relative path AND added as i used a filename and a folder, that's certainly the fact that the folder part was not absolute that can lead to it being relative, that's not the same thing, and YES that is you being once again prone to going too far too fast, period. it's good news that you leave this to me, as on almost all your posts you start with stating that you don't know about this and that, then at the end you didn't help but only hammered things we all already know.

                              J Offline
                              J Offline
                              JonB
                              wrote on 30 Jun 2023, 08:11 last edited by
                              #13

                              @Gilboonet
                              Great to hear. Sorry I wasted my time trying to help you. Stick to your relative paths, they are good. Best of luck.

                              G 1 Reply Last reply 30 Jun 2023, 09:39
                              0
                              • J JonB
                                30 Jun 2023, 08:11

                                @Gilboonet
                                Great to hear. Sorry I wasted my time trying to help you. Stick to your relative paths, they are good. Best of luck.

                                G Offline
                                G Offline
                                Gilboonet
                                wrote on 30 Jun 2023, 09:39 last edited by
                                #14

                                @JonB Well, here is is, by simply using Qt Resource System, it is working, absolutely not due to anything from you but all others who gave me good hints to follow instead of only criticizing.
                                Screenshot_20230630_113404.png
                                ( the menu is originally on french and using embedded resource .qm it is translated accorgindly to browser language.

                                J 1 Reply Last reply 30 Jun 2023, 09:48
                                0
                                • G Gilboonet has marked this topic as solved on 30 Jun 2023, 09:39
                                • G Gilboonet
                                  30 Jun 2023, 09:39

                                  @JonB Well, here is is, by simply using Qt Resource System, it is working, absolutely not due to anything from you but all others who gave me good hints to follow instead of only criticizing.
                                  Screenshot_20230630_113404.png
                                  ( the menu is originally on french and using embedded resource .qm it is translated accorgindly to browser language.

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 30 Jun 2023, 09:48 last edited by JonB
                                  #15

                                  @Gilboonet
                                  Nowhere did I criticize you at any point. Not once. Just tried to help. Politely, unlike your reponse.

                                  Since you have expressed your opinion of my time and efforts in trying to help you, could you now please get off my case and stop putting in my name in your posts to express how dissatisfied you are with my unpaid efforts to aid you. Thanks.

                                  1 Reply Last reply
                                  0

                                  9/15

                                  29 Jun 2023, 09:26

                                  • Login

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