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. [solved] How to get the translated text without loading the translator file?
Forum Updated to NodeBB v4.3 + New Features

[solved] How to get the translated text without loading the translator file?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k 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.
  • K Offline
    K Offline
    kumararajas
    wrote on last edited by
    #1

    (Reposting in right place)

    Hello all,

    I have an interesting problem to solve.

    In my application, I want to get the translated text without loading the translator. Is that possible? If yes, Please let me know.

    For better explanation:
    I will have translator files (.ts & .qm).
    But I do not want to use QApplication::tr(”“); to do the translation.

    I want something like this:
    // translatedText = GetTranslatedText(“Hello”);
    // Use translatedText

    Appreciate your feedback..

    Thanks,
    Kumar

    --Kumar

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      sure...look at the QTranslator and/or QObject::tr() source code and copy the needed passages.

      But at the end i have to ask: why?!
      Why can't you just use QTranslator to "load":http://qt-project.org/doc/qt-4.8/qtranslator.html#load a qm-File and "translate":http://qt-project.org/doc/qt-4.8/qtranslator.html#translate it? You do not necessarily install the QTranslator in your application, just use it when needed.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

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

        Thanks for your response Raven.

        This is basically to "test" the translation..

        Am writing an API, which will take "language" and "text" as arguments and return the translated text.

        std::string translatedString = GetTranslatedString(language, string);

        I will have listed of translated string with me, and use this API and get translated string from Qt, and compare.

        The main expectation from this API is, it should not load the translator file to the "application".

        Your answer makes sense to me.

        I can write this API in this way:
        @
        std::string GetTranslatedString(int nLanguage, std::string &inputStr)
        {
        if (nLanguage == GERMAN)
        {
        QTranslator translator;
        translator.load("germantr_la");
        return translate(inputStr);
        }
        }
        @
        Basic idea is, for each language, get the string and verify.

        And, if there is any other better way where i can have some automated tests for translation, please suggest me.

        Thank you,
        Kumar

        --Kumar

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          don't you trust QTranslator implementation to be correct? ^^

          But yes, the code you've posted is basically the idea i was talking about.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

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

            Raven,

            I trust Qt :)

            But also I would like to have a test framework to verify it once...

            Thanks for clarifying me :)

            Thanks,
            Kumar

            --Kumar

            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