internationalization support
-
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.
-
@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.
( the menu is originally on french and using embedded resource .qm it is translated accorgindly to browser language. -
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
-
@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.
-
:/
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.
-
@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.
-
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.
-
@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.
-
@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.... -
@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)? -
@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.
-
@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.
-
@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.
( the menu is originally on french and using embedded resource .qm it is translated accorgindly to browser language. -
-
@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.