Is it possible to have superscript within the char* argument to the tr() function - particularily superscript 2(^2)?
-
-
Hi and welcome to devnet,
What version of Qt are you using ?
On what OS ?
With which compiler ?Your string works for me on macOS 10.12 with Qt 5.10.1.
-
@CLang I guess it works for @SGaist as he runs on macOS, and there the source file is encoded in UTF-8 (like on Linux too). The compiler on the other hand, expects the source file to be in UTF-8 and converts the string from UTF-8 to UTF-16 (the internal representation of QString).
On Windows, things are much more complicated. On my system (Western Europe) Visual Studio assumes the source files to be Latin-1 encoded, and that is true for a lot of C++ source files indeed. On the other hand,
tr()
expects thechar *
to be UTF-8 encoded.You may be able to convice Visual Studio to treat your source files as UTF-8 encoded, but that means you can only edit them with Editors that are UTF-8 aware afterwards.
I personally didn't go this way, but encoded the special characters with HTML tricks:
tr("ö");
outputs "ö".If you want to translate your applications anyway, you can avoid the special chars in source code and only add them in the translations. That should always work.
Regards.
-
@aha_1980 Thanks for the reply. That makes sense.
I am a little confused at your suggestion for HTML tricks:
I tried your example and the QString = "ö" - Is this due to my region?
On the last line, are you suggesting to edit the .ts file with the superscript characters?
-
@CLang said in Is it possible to have superscript within the char* argument to the tr() function - particularily superscript 2(^2)?:
@aha_1980 Thanks for the reply. That makes sense.
I am a little confused at your suggestion for HTML tricks:
I tried your example and the QString = "ö" - Is this due to my region?
If you see 'ö' then all is fine :) -> o with umlaut
On the last line, are you suggesting to edit the .ts file with the superscript characters?
exactly. as the .ts file is always UTF-8 this should work. however, you then need to load the translation in your code.