{"id":573,"date":"2015-01-12T17:12:47","date_gmt":"2015-01-12T11:42:47","guid":{"rendered":"http:\/\/www.e-consystems.com\/blog\/linux-android\/?p=573"},"modified":"2023-08-15T12:33:58","modified_gmt":"2023-08-15T07:03:58","slug":"make-your-application-multilingual","status":"publish","type":"post","link":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/make-your-application-multilingual\/","title":{"rendered":"Make your application multilingual"},"content":{"rendered":"<h2>Abstract<\/h2>\n<p>This paper describes how to build a multi-lingual application using Qt framework. Qt provides a linguist tool chain for building and supporting applications for various regions of the world. The tool chain includes tools starting from Qt Creator, lupdate, lrelease. This article provides a detailed treatment on how to use these tools to build a multi-lingual dialog box.<\/p>\n<h2>Introduction<\/h2>\n<p>Qt provides QTranslator for developers to switch between language choices. QTranslator takes .qm files as input. Developers need to provide .qm files for each language that they plan to support.<\/p>\n<p>The following diagram details the steps for developers to generate .qm files. The .qm files could be packaged with the application as external or internal resources. The QTranslate load function loads a specific language resource for the application.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-576\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual-1-300x268.jpg\" alt=\"Make-your-application-multilingual-1\" width=\"300\" height=\"268\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual-1-300x268.jpg 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual-1.jpg 630w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h2>Implementation<\/h2>\n<p>Let\u2019s try to make the following user interface multi-lingual. We need to translate the following strings:<\/p>\n<ol>\n<li>TranslationApp<\/li>\n<li>Choose Language<\/li>\n<li>English<\/li>\n<li>Hindi<\/li>\n<li>French<\/li>\n<li>Welcome<\/li>\n<\/ol>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-587\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual7-300x246.png\" alt=\"Make-your-application-multilingual7\" width=\"300\" height=\"246\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual7-300x246.png 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual7.png 400w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Pre-Requirements:<\/p>\n<ol>\n<li>Qt Creator installation<\/li>\n<li>Qt Linguist installation<\/li>\n<li>User should have basic understanding of multilingual applications.<\/li>\n<li>Create a widget project with name <strong>translationExample<\/strong> and save to disk.<\/li>\n<\/ol>\n<p>Step 1- Add TRANLATIONS to application .pro file:<br \/>\nTRANSLATIONS += english.ts \\<br \/>\nhindi.ts \\<br \/>\nfrench.ts<\/p>\n<p>Step 2- Use lupdate command<br \/>\nRun <strong>lupdate<\/strong> tool on your project <strong>translationExample.pro.<\/strong><\/p>\n<p>Once this command is executed successfully all three <strong>.ts<\/strong> files (english, hindi, french) mentioned in the project file will be created on disk. Below is the sample output:<\/p>\n<p>Command:<\/p>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-579\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/3-300x16.png\" alt=\"3\" width=\"300\" height=\"16\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/3-300x16.png 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/3.png 505w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><br \/>\nOutput:<\/p>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-580\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/4-300x51.png\" alt=\"4\" width=\"300\" height=\"51\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/4-300x51.png 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/4.png 505w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Step 3 &#8211; QT Linguist:<\/p>\n<p>Open Qt linguist tool and choose the .ts file(s) from your disk, which you would like to translate. In the below image each entry is a string. The columns the three languages we choose to translate.<\/p>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-581\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual3.png\" alt=\"Make-your-application-multilingual3\" width=\"288\" height=\"169\" \/><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong><em>Above image shows the untranslated strings after opening the .ts files in the qt linguist tool.<\/em><\/strong><\/p>\n<p>Step 4 \u2013 Start Translating strings:<\/p>\n<p>Once each string is translated to the corresponding language the corresponding language column needs to be checked as shown below.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-582\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual4-258x300.png\" alt=\"Make-your-application-multilingual4\" width=\"258\" height=\"300\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual4-258x300.png 258w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual4.png 292w\" sizes=\"(max-width: 258px) 100vw, 258px\" \/><br \/>\nStep 5 \u2013 Once all the translations are complete, choose the <strong>Release All <\/strong>menu item under file menu.\u00a0 Release All command will create the .qm files as shown below.<\/p>\n<p align=\"center\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-585\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual5-300x81.png\" alt=\"Make-your-application-multilingual5\" width=\"300\" height=\"81\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual5-300x81.png 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual5.png 487w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Step 6 \u2013 Coding<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Add the Qtranslator header.<\/li>\n<li>Create an object for the Qtranslator class.<\/li>\n<li>To enable the translations, all the strings in the application, need to be inside tr() function or QcoreApplication::translate().<\/li>\n<li>Use the load function of the qtranslator class to load the language file.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>translator-&gt;load(&#8220;\/home\/French.qm&#8221;);<\/strong><\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>Appropriate fonts have to be set to the application for the proper display. Using QFont.<\/li>\n<li>Use the installTranslator() of the QCoreApplication class to install the translator.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>qApp-&gt;installTranslator(translator);<\/strong><\/p>\n<p>Sample Source code:<\/p>\n<p>Please download the source from the below link:<br \/>\nhttps:\/\/drive.google.com\/file\/d\/0B4LkGhFjozX3bHM1eXV2SFVieHc\/edit?usp=sharing<\/p>\n<p>Output Screenshots:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-586\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual6-300x110.png\" alt=\"Make-your-application-multilingual6\" width=\"300\" height=\"110\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual6-300x110.png 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual6-658x241.png 658w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual6.png 818w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-587\" src=\"https:\/\/www.e-consystems.com\/blog\/linux-android\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual7-300x246.png\" alt=\"Make-your-application-multilingual7\" width=\"300\" height=\"246\" srcset=\"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual7-300x246.png 300w, https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-content\/uploads\/2015\/01\/Make-your-application-multilingual7.png 400w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h2>Further reading recommendations:<\/h2>\n<p>Along with QTranslator, Qt provides QLocale which can be used to handle currencies, date and time representations.<\/p>\n<h2>References<\/h2>\n<p>1. <a href=\"http:\/\/doc.qt.io\/qt-4.8\/qtranslator.html\" rel=\"nofollow\">http:\/\/doc.qt.io\/qt-4.8\/qtranslator.html<\/a><br \/>\n2. <a href=\"http:\/\/doc.qt.io\/qt-4.8\/linguist-manual.html\" rel=\"nofollow\">http:\/\/doc.qt.io\/qt-4.8\/linguist-manual.html<\/a><\/p>\n<p>For any technical support or queries feel free to write to us at <a href=\"mailto:sales@e-consystems.com\" target=\"_blank\" rel=\"noopener noreferrer\">sales@e-consystems.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstract This paper describes how to build a multi-lingual application using Qt framework. Qt provides&#8230;<\/p>\n","protected":false},"author":17,"featured_media":574,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127],"tags":[126,125,124,123,207,129,121,120,122],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/573"}],"collection":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":17,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"predecessor-version":[{"id":2867,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/573\/revisions\/2867"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media\/574"}],"wp:attachment":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}