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. Use of Unicode in Dynamic Translations related code.

Use of Unicode in Dynamic Translations related code.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.2k 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.
  • P Offline
    P Offline
    PoonamGupta
    wrote on last edited by
    #1

    Hello,

    I have used Unicode "\xE2\x84\x83" in my code.

    example: TextWidget *test = new TextWidget("\xE2\x84\x83", this); ----> it makes QString m_text = "\xE2\x84\x83" ;
    where m_text is a member variable of TextWidget.

    this TextWidget reacts to a languageChangeEvent.
    In Language change event it returns QObject::tr(m_text);

    In this case, it returns all question mark symbol. "????"

    in my translation file (.ts) I don't have any translation for this Unicode. also Ideally if tr doesn't find any translation then it returns QString::fromUtf8(string) but in my case, it returns all "?????"

    can anybody help for how to use Unicode in a dynamic translation environment?

    Thanks in advance.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      QObject::tr(m_text);

      Does this even compile?
      The problem is not the non-asci chars, tr arguments must be the string literals to translate, not a variable.
      http://doc.qt.io/qt-5/i18n-source-translation.html#using-qt-tr-noop-and-qt-translate-noop-in-c

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • P Offline
        P Offline
        PoonamGupta
        wrote on last edited by
        #3

        Hi,

        Yes, it compiles. I do this

        QByteArray text = m_immutableText.toLocal8Bit();
        m_text = QObject::tr(text);

        Also, I found this solution for this symbol issue :

        QTextCodec *utfCodec = QTextCodec::codecForName("UTF-8"); //creating new utf-8 codec
        QTextCodec::setCodecForLocale(utfCodec); // setting the utf-8 codec for the tr() tags

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Please read http://doc.qt.io/qt-5/i18n-source-translation.html#using-tr-for-all-literal-text

          tr can't translate variables, it must be used only with literals

          P.S.
          m_text = QObject::tr(text); still doesn't compile, you are using m_text = QObject::tr(text.constData()); but it still can't work

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          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