Translating English to Arabic - tr() expecting a c_str which does not hold arabic characters????
-
Anyone any ideas why tr() wants to work with ASCII?
Any ideas for getting round this for Arabic translation? Shouldn't everything the Unicode for platform independence let alone text translation.
-
What is ASKI? You mean ASCII codes, they are integers, tr needs char array as input?
What is exactly your problem? Post it here.For more information about Internationalization take a look "here":http://qt-project.org/doc/qt-4.8/internationalization.html
Maybe you are looking for something like "this":http://qt-project.org/doc/qt-4.8/qobject.html#trUtf8
-
I am trying to work out how to get round the fact that Arabic characters are Unicode but tr() only accept chars. Put an Arabic phrase into tr() and it gives back "????????".
The only solution I can see is to only use chars in the code and add the Arabic strings via Qt Translator (i.e. have a char string in the code representing what we want then write the correct string in the translation file).
Just seems absurd that Qt is asking for char strings at all - should it not all be Unicode?
-
This is still pre-C++0x C++, where the assumption was that all C++ code is ASCII encoded. To get international characters in your program, they can be add using Linguist (the Qt translation program), or you can have them UTF-8 encoded (which is ASCII) in the code, and use QString::fromUtf8() on it.
At runtime, all your QStrings are unicode internally. It is just that your source code is ASCII.
-
OK, I can see that is what is happening I just thought it was something I was missing - you've got to admit it is counter intuitive for a tool written this century.
-
Actually, I think the C++ standard this is based on is last century :-) I agree it feels outdated, and it actually is - the new standard fixes it.
-
No, tr() does not accept only chars. It accepts QString values. Nevertheless, a c-style char array can be implicitly used to generate a QString. So the code:
@
tr("النص العربي");
@
is equivalent to:
@
tr(QString("النص العربي"));
@Your problem is that you're not using UTF8 encoding for your source file. Change your encoding to UTF8. In windows, open your file with notepad and save it again. in the save file dialog, change encoding. In Linux use "enca command line tool":http://linux.die.net/man/1/enca.
Also there are some "online services":http://www.fileformat.info/convert/text/charset.htm for converting character sets.
-
soroush,
You are wrong here.
[quote author="soroush" date="1339086230"]No, tr() does not accept only chars. It accepts QString values. Nevertheless, a c-style char array can be implicitly used to generate a QString. So the code:
@
tr("النص العربي");
@
is equivalent to:
@
tr(QString("النص العربي"));
@
[/quote] -
Hi Dolphin,
What do you mean by "Arabic characters are Unicode" ? Are you using wchar_t/char16_t/char32_t?
you mean
@
const char * arabic = u8"Arabic..."
@And are you using Qt4 or Qt5?
If you are using Qt4, please reference:
@
QTextCodec::setCodecForTr()
@If you are using Qt5, make sure the exec-char-set provided by your compiler is UTF-8.
Debao
[quote author="Dolphin" date="1339077231"]I am trying to work out how to get round the fact that Arabic characters are Unicode but tr() only accept chars. Put an Arabic phrase into tr() and it gives back "????????".The only solution I can see is to only use chars in the code and add the Arabic strings via Qt Translator (i.e. have a char string in the code representing what we want then write the correct string in the translation file).
Just seems absurd that Qt is asking for char strings at all - should it not all be Unicode?[/quote]
-
Of course, C++98 is more than 14 years old.
However, C++11 still doesn't totally resolve the problem.
If you want to use non-ascii-char in your source-code, you must know
- input-char-set
- exec-char-set
[quote author="Dolphin" date="1339077951"]OK, I can see that is what is happening I just thought it was something I was missing - you've got to admit it is counter intuitive for a tool written this century.[/quote]
-
Hi 1+1=2
I am using Qt 4.8 and Visual Studio 2010.
Ideally I am sticking to QStrings which is why I am questioning/double checking the idea of having to pass chars to Qt functions - all this encoding stuff is giving me a headache :-S