Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translating English to Arabic - tr() expecting a c_str which does not hold arabic characters????
Forum Updated to NodeBB v4.3 + New Features

Translating English to Arabic - tr() expecting a c_str which does not hold arabic characters????

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 5.0k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    Dolphin
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      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

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dolphin
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          miroslav
          wrote on last edited by
          #4

          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.

          Mirko Boehm | mirko@kde.org | KDE e.V.
          FSFE Fellow
          Qt Certified Specialist

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dolphin
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              miroslav
              wrote on last edited by
              #6

              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.

              Mirko Boehm | mirko@kde.org | KDE e.V.
              FSFE Fellow
              Qt Certified Specialist

              1 Reply Last reply
              0
              • S Offline
                S Offline
                soroush
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dbzhang800
                  wrote on last edited by
                  #8

                  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]

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dbzhang800
                    wrote on last edited by
                    #9

                    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]

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dbzhang800
                      wrote on last edited by
                      #10

                      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]

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        Dolphin
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0

                        • Login

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