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. Cannot internationalization, help

Cannot internationalization, help

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 1.4k 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.
  • A Offline
    A Offline
    ayanamirei
    wrote on last edited by
    #1

    environment: desktop, qtcreator, qt 5.1.1

    In a simple test application, I cannot translate English into Chinese using QTranslator.

    A simple dialog with a label, initialize label text when dialog loading.
    @Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    ui->label->setText(tr("--helloworld--!"));
    }
    @
    Create ts file and release it as qm file, "--helloworld--!" is translated into Chinese using Linguist tool.

    main is

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QTranslator qtTranslator;
    qDebug()<<QCoreApplication::applicationDirPath();
    qDebug()<<qtTranslator.load("helloworld.qm");
    qDebug()<<a.installTranslator(&qtTranslator);

    Dialog w;
    w.show();
    return a.exec&#40;&#41;;
    

    }@

    load and installTranslator return true, but "--helloworld--!" is still showed, not translated text. Where is error in my procedure?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mapron
      wrote on last edited by
      #2

      maybe you should have a look on
      void QLocale::setDefault(const QLocale & locale) [static]

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        code is correct.

        Please make sure that your translation file really contains a translation for "--helloworld--!" and not as your wrote "—helloworld—!"

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ayanamirei
          wrote on last edited by
          #4

          My fool, double checked Linguist GUI, I mistook "translation comment" as "translation", thanks raven.

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Maybe add the event that is given when translation is changed:
            @
            void MainWindow::changeEvent(QEvent* event)
            {
            if (event->type() == QEvent::LanguageChange)
            {
            // retranslate designer form
            ui->retranslateUi(this);
            }
            @
            This will trigger the widgets to update there language. Also, check that the created label you have made is translatable (should be default in designer, but check anyway).
            Did you use QtLiquist to translate your file?

            Greetz, Jeroen

            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