Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. read translation text from excel sheet into QTranslator at runtime
Forum Updated to NodeBB v4.3 + New Features

read translation text from excel sheet into QTranslator at runtime

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 882 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.
  • V Offline
    V Offline
    Vijay R. Gawade
    wrote on last edited by
    #1

    I want to load translation text for all available strings in qml from the excel sheet, where the user can modify translation text for language as per his requirement which can also be affected in the application on reload button and user can see the changed transition on UI

    Excel Sheet format be like this LangTransation.JPG image url)

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vijay R. Gawade
      wrote on last edited by
      #8

      Finally, I have implemented this using QXlsx https://github.com/QtExcel/QXlsx library for reading MS Xlsx file and store it in the below DS to load data mentioned in post image above:
      QMap<QString, QMap<QString, QString>> m_langTransMap;
      QMap<Input String,QMap<LangName,TranslatedText>>

      Use of Own Translator:
      QML:
      Text{
      text: myTranslator.getTranslatedText(
      "Main Controller") + myTranslator.emptyString]
      }

      class TranslationHandler : public QObject {
      Q_OBJECT
      Q_PROPERTY(QString emptyString READ getEmptyString NOTIFY languageChanged)

      public:
      void TranslationHandler::loadTranslationData() {
      /// Read Excel Data
      /// load it into QMap
      emit languageChanged();
      }

      Reference Link:

      • https://wiki.qt.io/How_to_do_dynamic_translation_in_QML

      • https://www.kdab.com/wp-content/uploads/stories/QmlComponentDesign-TwoWayBindingProblem-AndreSomers.pdf
        Read Cell Data:

      • https://github.com/QtExcel/QXlsx/blob/master/TestExcel/extractdata.cpp

      • https://github.com/QtExcel/QXlsx/blob/master/TestExcel/hello.cpp

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        If you want to use QTranslator, you would need to write your own data extractor, create the translation files and then call lconvert to regenerate the final files to be loaded.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        V 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          If you want to use QTranslator, you would need to write your own data extractor, create the translation files and then call lconvert to regenerate the final files to be loaded.

          V Offline
          V Offline
          Vijay R. Gawade
          wrote on last edited by
          #3

          @SGaist But looking at lconvert tool is used to merge ts file while deploying, we want to change transition text while running app(Deployed App at customer PC)

          And how to read excel(xlsx) file with above format in Qt? any idea

          J.HilkJ 1 Reply Last reply
          0
          • V Vijay R. Gawade

            @SGaist But looking at lconvert tool is used to merge ts file while deploying, we want to change transition text while running app(Deployed App at customer PC)

            And how to read excel(xlsx) file with above format in Qt? any idea

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @Vijay-R-Gawade if its a true excel file and not just a CSV:
            https://wiki.qt.io/Handling_Microsoft_Excel_file_format


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            3
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              In that case you will have to implement your own translation handling.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              V 1 Reply Last reply
              2
              • SGaistS SGaist

                In that case you will have to implement your own translation handling.

                V Offline
                V Offline
                Vijay R. Gawade
                wrote on last edited by
                #6

                @SGaist Thanks for the suggestion. So I need to write my own function which will return the translation text for the input string according to define in excel & can be maintained in some DS like QMAP and used it in QML/C++ instead of qsTr() & tr() calls.

                I will try this & update here

                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #7

                  In addition to what @SGaist suggested, better to define the your own ID for each string & use them inside your application. Read the excel(better to make it csv) & keep the mapping of ID to different languages. Keep this in seperate model object. Based on the selection, your model object should return different strings.

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Vijay R. Gawade
                    wrote on last edited by
                    #8

                    Finally, I have implemented this using QXlsx https://github.com/QtExcel/QXlsx library for reading MS Xlsx file and store it in the below DS to load data mentioned in post image above:
                    QMap<QString, QMap<QString, QString>> m_langTransMap;
                    QMap<Input String,QMap<LangName,TranslatedText>>

                    Use of Own Translator:
                    QML:
                    Text{
                    text: myTranslator.getTranslatedText(
                    "Main Controller") + myTranslator.emptyString]
                    }

                    class TranslationHandler : public QObject {
                    Q_OBJECT
                    Q_PROPERTY(QString emptyString READ getEmptyString NOTIFY languageChanged)

                    public:
                    void TranslationHandler::loadTranslationData() {
                    /// Read Excel Data
                    /// load it into QMap
                    emit languageChanged();
                    }

                    Reference Link:

                    • https://wiki.qt.io/How_to_do_dynamic_translation_in_QML

                    • https://www.kdab.com/wp-content/uploads/stories/QmlComponentDesign-TwoWayBindingProblem-AndreSomers.pdf
                      Read Cell Data:

                    • https://github.com/QtExcel/QXlsx/blob/master/TestExcel/extractdata.cpp

                    • https://github.com/QtExcel/QXlsx/blob/master/TestExcel/hello.cpp

                    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