Results 1 to 9 of 9

Thread: QML internationalization does not work

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

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    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,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


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

    Default Re: QML internationalization does not work

    main.qml

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Window 2.2
    3.  
    4. Window {
    5. visible: true
    6.  
    7. //width: Screen.width
    8. //height: Screen.height
    9.  
    10. //maximumHeight: Screen.height
    11. //minimumHeight: Screen.height
    12.  
    13. //maximumWidth: Screen.width
    14. //minimumWidth: Screen.width
    15.  
    16. width: 360
    17. height: 640
    18.  
    19. maximumHeight: 640
    20. minimumHeight: 640
    21.  
    22. maximumWidth: 360
    23. minimumWidth: 360
    24.  
    25. title: "InterestC-Mobile"
    26.  
    27. MainForm {
    28. anchors.fill: parent
    29.  
    30. mainContainer.width: parent.width
    31. mainContainer.height: parent.height
    32.  
    33. conversaoDiariaValorText.text: Number(0.0).toLocaleString(Qt.locale());
    34. conversaoMensalValorText.text: Number(0.0).toLocaleString(Qt.locale());
    35. conversaoBimestralValorText.text: Number(0.0).toLocaleString(Qt.locale());
    36. conversaoTrimestralValorText.text: Number(0.0).toLocaleString(Qt.locale());
    37. conversaoSemestralValorText.text: Number(0.0).toLocaleString(Qt.locale());
    38. conversaoAnualValorText.text: Number(0.0).toLocaleString(Qt.locale());
    39.  
    40. calcularButton.onClicked:
    41. {
    42. calculaConversoes();
    43. }
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 


    MainForm.ui.qml

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.2
    3.  
    4. Rectangle {
    5. id: mainContainer
    6.  
    7. width: 360
    8. height: 640
    9.  
    10. property alias mainContainer: mainContainer
    11.  
    12. property alias taxaJurosSpinBox: taxaJurosSpinBox
    13. property alias periodoJurosComboBox: periodoJurosComboBox
    14.  
    15. property alias calcularButton: calcularButton
    16.  
    17. property alias conversaoDiariaValorText: conversaoDiariaValorText
    18. property alias conversaoMensalValorText: conversaoMensalValorText
    19. property alias conversaoBimestralValorText: conversaoBimestralValorText
    20. property alias conversaoTrimestralValorText: conversaoTrimestralValorText
    21. property alias conversaoSemestralValorText: conversaoSemestralValorText
    22. property alias conversaoAnualValorText: conversaoAnualValorText
    23.  
    24. color: "#ffffff"
    25.  
    26. Rectangle {
    27. id: tituloRectangle
    28.  
    29. anchors.horizontalCenter: parent.horizontalCenter
    30. y: parent.y
    31.  
    32. width: parent.width
    33. height: parent.height * 0.10
    34. gradient: Gradient {
    35. GradientStop {
    36. position: 0
    37. color: "#fe3001"
    38. }
    39.  
    40. GradientStop {
    41. position: 1
    42. color: "#fe8548"
    43. }
    44. }
    45. Image {
    46. antialiasing: false
    47. source: "Imagens/InterestC-Mobile-Text.png"
    48.  
    49. anchors.horizontalCenter: parent.horizontalCenter
    50. anchors.verticalCenter: parent.verticalCenter
    51. }
    52. }
    53.  
    54. Label {
    55. id: taxaJurosLabel
    56.  
    57. anchors.horizontalCenter: parent.horizontalCenter
    58. y: parent.y + tituloRectangle.height * 1.3
    59.  
    60. text: qsTr("Taxa de juros") + " (%)"
    61. font.pointSize: 18
    62. }
    63.  
    64. Rectangle {
    65. id: taxaJurosInputRectangle
    66.  
    67. width: parent.width * 0.85
    68. height: parent.height * 0.10
    69.  
    70. anchors.horizontalCenter: parent.horizontalCenter
    71. y: parent.y + tituloRectangle.height * 1.7
    72.  
    73. SpinBox {
    74. id: taxaJurosSpinBox
    75.  
    76. anchors.verticalCenter: parent.verticalCenter
    77. anchors.left: parent.left
    78.  
    79. width: parent.width * 0.47
    80. height: parent.height * 0.6
    81.  
    82. font.pointSize: 16
    83.  
    84. horizontalAlignment: Text.AlignHCenter
    85.  
    86. decimals: 2
    87.  
    88. minimumValue: 0
    89. maximumValue: 100
    90. }
    91.  
    92. ComboBox {
    93. id: periodoJurosComboBox
    94.  
    95. width: parent.width * 0.47
    96. height: parent.height * 0.6
    97.  
    98. anchors.verticalCenter: parent.verticalCenter
    99. anchors.right: parent.right
    100.  
    101. model: [qsTr("Diária"), qsTr("Mensal"), qsTr("Bimestral"), qsTr("Trimestral"), qsTr("Semestral"), qsTr("Anual")]
    102. }
    103. }
    104.  
    105. Button {
    106. id: calcularButton
    107.  
    108. anchors.horizontalCenter: parent.horizontalCenter
    109. y: 1.03 * (taxaJurosInputRectangle.y + taxaJurosInputRectangle.height)
    110.  
    111. width: parent.width * 0.85
    112. height: taxaJurosInputRectangle.height * 0.6
    113.  
    114. text: qsTr("Calcular")
    115. }
    116. Rectangle {
    117. id: conversoesRectangle
    118.  
    119. width: parent.width * 0.9
    120. height: parent.height * 0.61
    121.  
    122. anchors.horizontalCenter: parent.horizontalCenter
    123. y: 1.05 * (calcularButton.y + calcularButton.height)
    124.  
    125. //property variant espacamentoConversoes: 1.03
    126.  
    127. Text {
    128. id: conversaoTituloText
    129.  
    130. anchors.horizontalCenter: parent.horizontalCenter
    131. anchors.top: parent.top
    132.  
    133. text: qsTr("Conversões (%) ")
    134.  
    135. font.bold: true
    136. font.pixelSize: 25
    137. }
    138.  
    139. Text {
    140. id: conversaoDiariaText
    141.  
    142. anchors.left: parent.left
    143. y: parent.height / 7
    144.  
    145. text: qsTr("Ao dia: ")
    146.  
    147. font.bold: true
    148. font.pixelSize: 20
    149. }
    150.  
    151. Text {
    152. id: conversaoDiariaValorText
    153.  
    154. anchors.right: parent.right
    155. y: conversaoDiariaText.y
    156.  
    157. font.bold: true
    158. font.pixelSize: 20
    159.  
    160. width: parent.width * 0.2
    161. height: parent.height * 0.1
    162.  
    163. horizontalAlignment: Text.AlignRight
    164. }
    165.  
    166. Text {
    167. id: conversaoMensalText
    168.  
    169. anchors.left: parent.left
    170. y: parent.height / 7 * 2
    171.  
    172. text: qsTr("Ao mês: ")
    173.  
    174. font.bold: true
    175. font.pixelSize: 20
    176. }
    177.  
    178. Text {
    179. id: conversaoMensalValorText
    180.  
    181. anchors.right: parent.right
    182. y: conversaoMensalText.y
    183.  
    184. font.bold: true
    185. font.pixelSize: 20
    186.  
    187. width: parent.width * 0.2
    188. height: parent.height * 0.1
    189.  
    190. horizontalAlignment: Text.AlignRight
    191. }
    192.  
    193. Text {
    194. id: conversaoBimestralText
    195.  
    196. anchors.left: parent.left
    197. y: parent.height / 7 * 3
    198.  
    199. text: qsTr("Ao bimestre: ")
    200.  
    201. font.bold: true
    202. font.pixelSize: 20
    203. }
    204.  
    205. Text {
    206. id: conversaoBimestralValorText
    207.  
    208. anchors.right: parent.right
    209. y: conversaoBimestralText.y
    210.  
    211. font.bold: true
    212. font.pixelSize: 20
    213.  
    214. width: parent.width * 0.2
    215. height: parent.height * 0.1
    216.  
    217. horizontalAlignment: Text.AlignRight
    218. }
    219.  
    220. Text {
    221. id: conversaoTrimestralText
    222.  
    223. anchors.left: parent.left
    224. y: parent.height / 7 * 4
    225.  
    226. text: qsTr("Ao trimestre: ")
    227.  
    228. font.bold: true
    229. font.pixelSize: 20
    230. }
    231.  
    232. Text {
    233. id: conversaoTrimestralValorText
    234.  
    235. anchors.right: parent.right
    236. y: conversaoTrimestralText.y
    237.  
    238. font.bold: true
    239. font.pixelSize: 20
    240.  
    241. width: parent.width * 0.2
    242. height: parent.height * 0.1
    243.  
    244. horizontalAlignment: Text.AlignRight
    245. }
    246.  
    247. Text {
    248. id: conversaoSemestralText
    249.  
    250. anchors.left: parent.left
    251. y: parent.height / 7 * 5
    252.  
    253. text: qsTr("Ao semestre: ")
    254.  
    255. font.bold: true
    256. font.pixelSize: 20
    257. }
    258.  
    259. Text {
    260. id: conversaoSemestralValorText
    261.  
    262. anchors.right: parent.right
    263. y: conversaoSemestralText.y
    264.  
    265. font.bold: true
    266. font.pixelSize: 20
    267.  
    268. width: parent.width * 0.2
    269. height: parent.height * 0.1
    270.  
    271. horizontalAlignment: Text.AlignRight
    272. }
    273.  
    274. Text {
    275. id: conversaoAnualText
    276.  
    277. anchors.left: parent.left
    278. y: parent.height / 7 * 6
    279.  
    280. text: qsTr("Ao ano: ")
    281.  
    282. font.bold: true
    283. font.pixelSize: 20
    284. }
    285.  
    286. Text {
    287. id: conversaoAnualValorText
    288.  
    289. anchors.right: parent.right
    290. y: conversaoAnualText.y
    291.  
    292. font.bold: true
    293. font.pixelSize: 20
    294.  
    295. width: parent.width * 0.2
    296. height: parent.height * 0.1
    297.  
    298. horizontalAlignment: Text.AlignRight
    299. }
    300. }
    301. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 32 minutes:


    Wysota, thanks for the replies

    I have done some tests and I realized that the translation works with mail.qml but does not work with the MainForm.ui.qml

    Do you know why?

    Thank you
    Last edited by guidupas; 29th May 2015 at 20:50.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.