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. Multiple language support from file
Forum Updated to NodeBB v4.3 + New Features

Multiple language support from file

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.8k Views 3 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.
  • D Offline
    D Offline
    dsrking
    wrote on last edited by
    #1

    Hi,

    I would like to provide a support to my desktop QT application with multiple language. My application has some button and text fields which needs to be changed based on the language selected from top of the application screen.

    I have used linguest to obtain the same but it needs to recompile the entire application whenever i need to change the button name for different language. Is it possible to give all the language text in a separate file and the application should read the file when we select the language in drop down box and display the proper name in button and text fields.

    Thanks in advance.

    K 1 Reply Last reply
    0
    • McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #2

      You can change the language on the fly while the application is running.
      Add the language files compiled by Linguist as resources and reimplement a changeEvent for the Language change. Something like this:

      void QTGUI_MainWindow::changeEvent(QEvent *e)
      {
      if(e->type()==QEvent::LanguageChange)
      ui->retranslateUi(this);
      }

      and use something like this to set/change the language:

      void setLanguage(QString language)
      {
      QLocale::setDefault(language);

      if(m_translator)
      {
          qApp->removeTranslator(m_translator);
          delete m_translator;
      }
      
      m_translator = new QTranslator;
      m_translator->load(QString(":/Languages/%1").arg(language));
      qApp->installTranslator(m_translator);
      

      }

      ot: can somebody tell me how to mark code segments in the new forum ?!?
      Sorry if this post looks strange.

      1 Reply Last reply
      1
      • D Offline
        D Offline
        dsrking
        wrote on last edited by
        #3

        Dear McLion,

        Thanks for your reply.

        If we add the linguist in resources, i would need to again create the linguist file once again if i changed any text (eg. in english, i created a linguist file for a button name "add" and later i would like to change this name to "sum". In this case, i would need to create a fresh linguist file and need to add it in resource. ).

        What i need is that i should be able to change the text in button in run time for same new language (not for other language).

        Is there any method to add all the new language text in button and the application can read this file and show it in button based on the user selection. so that, if i need to change the button name later for a same language, i can change it in the text file and i don't need to build the application.

        I hope i have explained my doubt clearly. If you did not understand, please inform me. Sorry for the confusion.

        Thanks in advance.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kumararajas
          wrote on last edited by
          #4

          Hi dsrking,

          The basic is, if you have translations for the strings in .ts file and .qm file is generated from .ts file and you are using tr() in the code, then change in language should work perfectly.

          In your example,
          First you have a button with the text "add". You must be having the translation for add in .ts file.
          And as per your example, in the runtime, the text of button will change to "sum". So, even for sum you should have translation in the .ts file.

          So for now, you will be having two strings in .ts file "add", "sum" and their translations.

          Then generate .qm files.

          Dynamic language change should work.

          Let me know if any of the step is unclear.

          Best Regards,
          Kumar

          --Kumar

          1 Reply Last reply
          0
          • D dsrking

            Hi,

            I would like to provide a support to my desktop QT application with multiple language. My application has some button and text fields which needs to be changed based on the language selected from top of the application screen.

            I have used linguest to obtain the same but it needs to recompile the entire application whenever i need to change the button name for different language. Is it possible to give all the language text in a separate file and the application should read the file when we select the language in drop down box and display the proper name in button and text fields.

            Thanks in advance.

            K Offline
            K Offline
            kumararajas
            wrote on last edited by kumararajas
            #5

            @dsrking said:

            Hi,

            I would like to provide a support to my desktop QT application with multiple language. My application has some button and text fields which needs to be changed based on the language selected from top of the application screen.

            I have used linguist to obtain the same but it needs to recompile the entire application whenever i need to change the button name for different language. Is it possible to give all the language text in a separate file and the application should read the file when we select the language in drop down box and display the proper name in button and text fields.

            Thanks in advance.

            And as a minor correction, its not QT. QT stands for QuickTime. Please correct as Qt :)

            --Kumar

            1 Reply Last reply
            0
            • McLionM Offline
              McLionM Offline
              McLion
              wrote on last edited by
              #6

              If you would like to change the text on the buttons or any other element, maybe not in a language context, you can simply do this in code if the changes are fix. If you need to do this dynamically, i.e. let the user name elements you may need to create something that is changing and reading the names for the elements from a file.
              To my knowledge, there is no such thing present in Qt and you need to do it on your own.

              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