Results 1 to 9 of 9

Thread: QML internationalization does not work

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    5

    Default QML internationalization does not work

    Hello all!

    I am having a problem with the translation of my app developed in QML

    The translation file (.qm) is done but it does not work.

    Can anyone help me?

    Thanks in advance.

    Code below:

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. #include <QTranslator>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QGuiApplication app(argc, argv);
    9.  
    10. QTranslator tradutor;
    11.  
    12. tradutor.load("qml_en", "./");
    13. app.installTranslator(&tradutor);
    14.  
    15. QQmlApplicationEngine engine;
    16. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QML internationalization does not work

    What does QTranslator::load() return?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    5

    Default Re: QML internationalization does not work

    Sorry, with this config (./) it returns false, but now I changed to (:/) and the qml_en.qm is inserted in resources.

    Now it returns true but the translation stills not working.

    I tried using 2 ways:

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. #include <QTranslator>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QGuiApplication app(argc, argv);
    9.  
    10. QTranslator tradutor;
    11.  
    12. tradutor.load("qml_en", ":/");
    13. app.installTranslator(&tradutor);
    14.  
    15. QQmlApplicationEngine engine;
    16. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. #include <QTranslator>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QGuiApplication app(argc, argv);
    9.  
    10. QQmlApplicationEngine engine;
    11. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    12.  
    13. QTranslator tradutor;
    14.  
    15. tradutor.load("qml_en", ":/");
    16. app.installTranslator(&tradutor);
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QML internationalization does not work

    You need to install the translator before loading the scene.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2014
    Posts
    94
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    5

    Default Re: QML internationalization does not work

    I have tried both ways, before and after. Neither of then works

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. #include <QTranslator>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QGuiApplication app(argc, argv);
    9.  
    10. QQmlApplicationEngine engine;
    11. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    12.  
    13. QTranslator tradutor;
    14.  
    15. tradutor.load("qml_en", ":/");
    16. app.installTranslator(&tradutor);
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. #include <QTranslator>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QGuiApplication app(argc, argv);
    9.  
    10. QTranslator tradutor;
    11.  
    12. tradutor.load("qml_en", ":/");
    13. app.installTranslator(&tradutor);
    14.  
    15. QQmlApplicationEngine engine;
    16. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QML internationalization does not work

    Are you sure the catalog file is correct for the messages used in the QML file? How did you produce it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2014
    Posts
    94
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    5

    Default Re: QML internationalization does not work

    I think it is. I created it using Lupdate and Lrelease

    Here is the TS file

    Qt Code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <!DOCTYPE TS>
    3. <TS version="2.0" language="en_US">
    4. <context>
    5. <name>MainForm</name>
    6. <message>
    7. <location filename="MainForm.ui.qml" line="57"/>
    8. <source>Taxa de juros</source>
    9. <translation>Interest rate</translation>
    10. </message>
    11. <message>
    12. <location filename="MainForm.ui.qml" line="98"/>
    13. <source>Diária</source>
    14. <translation>Daily</translation>
    15. </message>
    16. <message>
    17. <location filename="MainForm.ui.qml" line="98"/>
    18. <source>Mensal</source>
    19. <translation>Monthly</translation>
    20. </message>
    21. <message>
    22. <location filename="MainForm.ui.qml" line="98"/>
    23. <source>Bimestral</source>
    24. <translation>Bimonthly</translation>
    25. </message>
    26. <message>
    27. <location filename="MainForm.ui.qml" line="98"/>
    28. <source>Trimestral</source>
    29. <translation>Quarterly</translation>
    30. </message>
    31. <message>
    32. <location filename="MainForm.ui.qml" line="98"/>
    33. <source>Semestral</source>
    34. <translation>Semiannual</translation>
    35. </message>
    36. <message>
    37. <location filename="MainForm.ui.qml" line="98"/>
    38. <source>Anual</source>
    39. <translation>Yearly</translation>
    40. </message>
    41. <message>
    42. <location filename="MainForm.ui.qml" line="111"/>
    43. <source>Calcular</source>
    44. <translation>Calculate</translation>
    45. </message>
    46. <message>
    47. <location filename="MainForm.ui.qml" line="130"/>
    48. <source>Conversões (%) </source>
    49. <translation>Conversions (%)</translation>
    50. </message>
    51. <message>
    52. <location filename="MainForm.ui.qml" line="142"/>
    53. <source>Ao dia: </source>
    54. <translation>Per day:</translation>
    55. </message>
    56. <message>
    57. <location filename="MainForm.ui.qml" line="169"/>
    58. <source>Ao mês: </source>
    59. <translation>Per month:</translation>
    60. </message>
    61. <message>
    62. <location filename="MainForm.ui.qml" line="196"/>
    63. <source>Ao bimestre: </source>
    64. <translation>Per bimester:</translation>
    65. </message>
    66. <message>
    67. <location filename="MainForm.ui.qml" line="223"/>
    68. <source>Ao trimestre: </source>
    69. <translation>Per quarter:</translation>
    70. </message>
    71. <message>
    72. <location filename="MainForm.ui.qml" line="250"/>
    73. <source>Ao semestre: </source>
    74. <translation>Per semester:</translation>
    75. </message>
    76. <message>
    77. <location filename="MainForm.ui.qml" line="277"/>
    78. <source>Ao ano: </source>
    79. <translation>Per year:</translation>
    80. </message>
    81. </context>
    82. <context>
    83. <name>main</name>
    84. <message>
    85. <location filename="main.qml" line="100"/>
    86. <location filename="main.qml" line="113"/>
    87. <location filename="main.qml" line="126"/>
    88. <location filename="main.qml" line="138"/>
    89. <location filename="main.qml" line="151"/>
    90. <location filename="main.qml" line="164"/>
    91. <source>mais de 10 trilhões</source>
    92. <translation>Higher then 10 trillion</translation>
    93. </message>
    94. </context>
    95. </TS>
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QML internationalization does not work

    What does the main.qml file look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Internationalization and English
    By Zingam in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2014, 09:36
  2. FONTS According to languages (Internationalization)
    By Gaurav K SIngh in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 17th July 2007, 07:10
  3. Internationalization with Qt
    By vermarajeev in forum Qt Programming
    Replies: 5
    Last Post: 16th November 2006, 10:22
  4. Problem in Internationalization with Qt
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2006, 15:06
  5. Plugin and internationalization
    By blackliteon in forum Qt Programming
    Replies: 10
    Last Post: 14th February 2006, 07:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.