title: Dynamic Qt string translation
body: <p>If we wrap strings in tr() we can use the linguist  to translate qt apps. The following example is one way to dynamically load a language:</p>
  
  <pre><code>int main(int argc, char *argv[])
   {
       QApplication app(argc, argv);
  
       QTranslator translator;
       translator.load("hellotr_la");
       app.installTranslator(&amp;translator);
  
       QPushButton hello(QPushButton::tr("Hello world!"));
       hello.resize(100, 30);
       hello.show();
  
       return app.exec();
   }
  </code></pre>
  
  <p>What I would like to do is is translate to different languages based on say a user preference. The reason is that I'm having a server that needs to handle client requests that has different languages. Having the whole server / process change language via events per request does not feel right. Thus, I'm not interested in the <a href="https://doc.qt.io/qt-5/internationalization.html#dynamic-translation" rel="nofollow">dynamic translation</a> reacting to <code>QEvent::LanguageChange</code>.</p>
  
  <p>One thing that interested me thus is the following documentation for <a href="https://doc.qt.io/qt-5/qcoreapplication.html#installTranslator" rel="nofollow">QCoreApplication::installTranslator()</a> </p>
  
  <blockquote>
    <p>Multiple translation files can be installed. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched first and the first translation file installed is searched last. The search stops as soon as a translation containing a matching string is found.</p>
  </blockquote>
  
  <p>Thus, it seems possible to load multiple languages but my concern then is if I have multiple languages I can not specify which one will be the preferred language. If I have to express in code what I want is something like this:</p>
  
  <pre><code>QString MyApplicationServer::OnHandleRequest(MyRequest &amp;r)
  {
     //Get the language for this specific request
     //For example language can be “hellotr_la” or “hellotr_fr” 
     // Or another way: "lat", "fra", "enu", "esn" ...
     QString language = getLanguageForRequest(r);
  
     //How do I dynamically use language or translate to language?
     // This would be the preferred solution.
     return tr("Not Implemented", language);
  }
  </code></pre>
  
  <p>If I have to use some custom macros, then so mote it be!</p>
  
  <p><strong>Edit:</strong> Basically I would like to get my hands on a specific translated string from the translators.</p>