Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 3943

qt-doc-4.8.5-10.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- linguist-manual.qdoc -->
  <title>Qt 4.8: Qt Linguist Manual: Programmers</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li>Qt Linguist Manual: Programmers</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
  <link rel="prev" href="linguist-translators.html" />
  <link rel="next" href="linguist-ts-file-format.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="linguist-translators.html">Qt Linguist Manual: Translators</a>
<a class="nextPage" href="linguist-ts-file-format.html">Qt Linguist Manual: TS File Format</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#making-the-application-translation-aware">Making the Application Translation-Aware</a></li>
<li class="level2"><a href="#creating-translation-files">Creating Translation Files</a></li>
<li class="level2"><a href="#loading-translations">Loading Translations</a></li>
<li class="level2"><a href="#making-the-application-translate-user-visible-strings">Making the Application Translate User-Visible Strings</a></li>
<li class="level2"><a href="#distinguishing-between-identical-translatable-strings">Distinguishing Between Identical Translatable Strings</a></li>
<li class="level2"><a href="#helping-the-translator-with-navigation-information">Helping the Translator with Navigation Information</a></li>
<li class="level2"><a href="#handling-plural-forms">Handling Plural Forms</a></li>
<li class="level2"><a href="#coping-with-c-namespaces">Coping With C++ Namespaces</a></li>
<li class="level2"><a href="#translating-text-that-is-outside-of-a-qobject-subclass">Translating Text That is Outside of a QObject Subclass</a></li>
<li class="level3"><a href="#using-qcoreapplication-translate">Using QCoreApplication::translate()</a></li>
<li class="level3"><a href="#using-qt-tr-noop-and-qt-translate-noop">Using QT_TR_NOOP() and QT_TRANSLATE_NOOP()</a></li>
<li class="level1"><a href="#tutorials">Tutorials</a></li>
</ul>
</div>
<h1 class="title">Qt Linguist Manual: Programmers</h1>
<span class="subtitle"></span>
<!-- $$$linguist-programmers.html-description -->
<div class="descr"> <a name="details"></a>
<p>Support for multiple languages is extremely simple in Qt applications, and adds little overhead to the programmer's workload.</p>
<p>Qt minimizes the performance cost of using translations by translating the phrases for each window as they are created. In most applications the main window is created just once. Dialogs are often created once and then shown and hidden as required. Once the initial translation has taken place there is no further runtime overhead for the translated windows. Only those windows that are created, destroyed and subsequently created will have a translation performance cost.</p>
<p>Creating applications that can switch language at runtime is possible with Qt, but requires a certain amount of programmer intervention and will of course incur some runtime performance cost.</p>
<a name="making-the-application-translation-aware"></a>
<h2>Making the Application Translation-Aware</h2>
<p>Programmers should make their application look for and load the appropriate translation file and mark user-visible text and Ctrl keyboard accelerators as targets for translation.</p>
<p>Each piece of text that requires translating requires context to help the translator identify where in the program the text occurs. In the case of multiple identical texts that require different translations, the translator also requires some information to disambiguate the source texts. Marking text for translation will automatically cause the class name to be used as basic context information. In some cases the programmer may be required to add additional information to help the translator.</p>
<a name="creating-translation-files"></a>
<h3>Creating Translation Files</h3>
<p>Translation files consist of all the user-visible text and Ctrl key accelerators in an application and translations of that text. Translation files are created as follows:</p>
<ol class="1">
<li>Run <a href="linguist-manager.html#lupdate">lupdate</a> initially to generate the first set of TS translation source files with all the user-visible text but no translations.</li>
<li>The TS files are given to the translator who adds translations using <i>Qt Linguist</i>. <i>Qt Linguist</i> takes care of any changed or deleted source text.</li>
<li>Run <a href="linguist-manager.html#lupdate">lupdate</a> to incorporate any new text added to the application. <a href="linguist-manager.html#lupdate">lupdate</a> synchronizes the user-visible text from the application with the translations; it does not destroy any data.</li>
<li>Steps 2 and 3 are repeated as often as necessary.</li>
<li>When a release of the application is needed <a href="linguist-manager.html#lrelease">lrelease</a> is run to read the TS files and produce the QM files used by the application at runtime.</li>
</ol>
<p>For <a href="linguist-manager.html#lupdate">lupdate</a> to work successfully, it must know which translation files to produce. The files are simply listed in the application's <tt>.pro</tt> Qt project file, for example:</p>
<pre class="cpp"> TRANSLATIONS = arrowpad_fr.ts \
                arrowpad_nl.ts</pre>
<p>If your sources contain genuine non-Latin1 strings, <a href="linguist-manager.html#lupdate">lupdate</a> needs to be told about it in the <tt>.pro</tt> file by using, for example, the following line:</p>
<pre class="cpp"> CODECFORTR <span class="operator">=</span> UTF<span class="operator">-</span><span class="number">8</span></pre>
<p>See the <a href="linguist-manager.html#lupdate">lupdate</a> and <a href="linguist-manager.html#lrelease">lrelease</a> sections.</p>
<a name="loading-translations"></a>
<h3>Loading Translations</h3>
<pre class="cpp"> <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
 {
     <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);</pre>
<p>This is how a simple <tt>main()</tt> function of a Qt application begins.</p>
<pre class="cpp"> <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
 {
     <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);

     <span class="type"><a href="qtranslator.html">QTranslator</a></span> translator;
     translator<span class="operator">.</span>load(<span class="string">&quot;hellotr_la&quot;</span>);
     app<span class="operator">.</span>installTranslator(<span class="operator">&amp;</span>translator);</pre>
<p>For a translation-aware application a translator object is created, a translation is loaded and the translator object installed into the application.</p>
<pre class="cpp"> <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
 {
     <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);

     <span class="type"><a href="qstring.html">QString</a></span> locale <span class="operator">=</span> <span class="type"><a href="qlocale.html">QLocale</a></span><span class="operator">::</span>system()<span class="operator">.</span>name();

     <span class="type"><a href="qtranslator.html">QTranslator</a></span> translator;
     translator<span class="operator">.</span>load(<span class="type"><a href="qstring.html">QString</a></span>(<span class="string">&quot;arrowpad_&quot;</span>) <span class="operator">+</span> locale);
     app<span class="operator">.</span>installTranslator(<span class="operator">&amp;</span>translator);</pre>
<p>For non-Latin1 strings in the sources you will also need for example:</p>
<pre class="cpp">     <span class="type"><a href="qtextcodec.html">QTextCodec</a></span><span class="operator">::</span>setCodecForTr(<span class="type"><a href="qtextcodec.html">QTextCodec</a></span><span class="operator">::</span>codecForName(<span class="string">&quot;utf8&quot;</span>));</pre>
<p>In production applications a more flexible approach, for example, loading translations according to locale, might be more appropriate. If the TS files are all named according to a convention such as <i>appname_locale</i>, e.g&#x2e; <tt>tt2_fr</tt>, <tt>tt2_de</tt> etc, then the code above will load the current locale's translation at runtime.</p>
<p>If there is no translation file for the current locale the application will fall back to using the original source text.</p>
<p>Note that if you need to programmatically add translations at runtime, you can reimplement <a href="qtranslator.html#translate">QTranslator::translate</a>().</p>
<a name="making-the-application-translate-user-visible-strings"></a>
<h3>Making the Application Translate User-Visible Strings</h3>
<p>User-visible strings are marked as translation targets by wrapping them in a <tt>tr()</tt> call, for example:</p>
<pre class="cpp"> button <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(<span class="string">&quot;&amp;Quit&quot;</span><span class="operator">,</span> <span class="keyword">this</span>);</pre>
<p>would become</p>
<pre class="cpp"> button <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;&amp;Quit&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);</pre>
<p>All <a href="qobject.html">QObject</a> subclasses that use the <tt>Q_OBJECT</tt> macro implement the <tt>tr()</tt> function.</p>
<p>Although the <tt>tr()</tt> call is normally made directly since it is usually called as a member function of a <a href="qobject.html">QObject</a> subclass, in other cases an explicit class name can be supplied, for example:</p>
<pre class="cpp"> <span class="type"><a href="qpushbutton.html">QPushButton</a></span><span class="operator">::</span>tr(<span class="string">&quot;&amp;Quit&quot;</span>)</pre>
<p>or</p>
<pre class="cpp"> <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">::</span>tr(<span class="string">&quot;&amp;Quit&quot;</span>)</pre>
<a name="distinguishing-between-identical-translatable-strings"></a>
<h3>Distinguishing Between Identical Translatable Strings</h3>
<p>The <a href="linguist-manager.html#lupdate">lupdate</a> program automatically provides a <i>context</i> for every source text. This context is the class name of the class that contains the <tt>tr()</tt> call. This is sufficient in the vast majority of cases. Sometimes however, the translator will need further information to uniquely identify a source text; for example, a dialog that contained two separate frames, each of which contained an &quot;Enabled&quot; option would need each identified because in some languages the translation would differ between the two. This is easily achieved using the two argument form of the <tt>tr()</tt> call, e.g&#x2e;</p>
<pre class="cpp"> rbc <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Enabled&quot;</span><span class="operator">,</span> <span class="string">&quot;Color frame&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);</pre>
<p>and</p>
<pre class="cpp"> rbh <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Enabled&quot;</span><span class="operator">,</span> <span class="string">&quot;Hue frame&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);</pre>
<p>Ctrl key accelerators are also translatable:</p>
<pre class="cpp">     exitAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;E&amp;xit&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
     exitAct<span class="operator">-</span><span class="operator">&gt;</span>setShortcut(tr(<span class="string">&quot;Ctrl+Q&quot;</span><span class="operator">,</span> <span class="string">&quot;Quit&quot;</span>));</pre>
<p>It is strongly recommended that the two argument form of <tt>tr()</tt> is used for Ctrl key accelerators. The second argument is the only clue the translator has as to the function performed by the accelerator.</p>
<a name="helping-the-translator-with-navigation-information"></a>
<h3>Helping the Translator with Navigation Information</h3>
<p>In large complex applications it may be difficult for the translator to see where a particular source text comes from. This problem can be solved by adding a comment using the keyword <i>TRANSLATOR</i> which describes the navigation steps to reach the text in question; e.g&#x2e;</p>
<pre class="cpp"> <span class="comment">/*
     TRANSLATOR FindDialog

     Choose Edit|Find from the menu bar or press Ctrl+F to pop up the
     Find dialog.

     ...
 */</span></pre>
<p>These comments are particularly useful for widget classes.</p>
<a name="handling-plural-forms"></a>
<h3>Handling Plural Forms</h3>
<p>Qt includes a <tt>tr()</tt> overload that will make it very easy to write &quot;plural-aware&quot; internationalized applications. This overload has the following signature:</p>
<pre class="cpp"> <span class="type"><a href="qstring.html">QString</a></span> tr(<span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>text<span class="operator">,</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>comment<span class="operator">,</span> <span class="type">int</span> n);</pre>
<p>Depending on the value of <tt>n</tt>, the <tt>tr()</tt> function will return a different translation, with the correct grammatical number for the target language. Also, any occurrence of <tt>%n</tt> is replaced with <tt>n</tt>'s value. For example:</p>
<pre class="cpp"> tr(<span class="string">&quot;%n item(s) replaced&quot;</span><span class="operator">,</span> <span class="string">&quot;&quot;</span><span class="operator">,</span> count);</pre>
<p>If a French translation is loaded, this will expand to &quot;0 item remplacé&quot;, &quot;1 item remplacé&quot;, &quot;2 items remplacés&quot;, etc., depending on <tt>n</tt>'s value. And if no translation is loaded, the original string is used, with <tt>%n</tt> replaced with count's value (e.g&#x2e;, &quot;6 item(s) replaced&quot;).</p>
<p>To handle plural forms in the native language, you need to load a translation file for this language, too. <a href="linguist-manager.html#lupdate">lupdate</a> has the <tt>-pluralonly</tt> command line option, which allows the creation of TS files containing only entries with plural forms.</p>
<p>See the <a href="http://doc.qt.nokia.com/qq/">Qt Quarterly</a> Article <a href="http://doc.qt.nokia.com/qq/qq19-plurals.html">Plural Forms in Translations</a> for further details on this issue.</p>
<a name="coping-with-c-namespaces"></a>
<h3>Coping With C++ Namespaces</h3>
<p>C++ namespaces and the <tt>using namespace</tt> statement can confuse <a href="linguist-manager.html#lupdate">lupdate</a>. It will interpret <tt>MyClass::tr()</tt> as meaning just that, not as <tt>MyNamespace::MyClass::tr()</tt>, even if <tt>MyClass</tt> is defined in the <tt>MyNamespace</tt> namespace. Runtime translation of these strings will fail because of that.</p>
<p>You can work around this limitation by putting a <i>TRANSLATOR</i> comment at the beginning of the source files that use <tt>MyClass::tr()</tt>:</p>
<pre class="cpp"> <span class="comment">/*
     TRANSLATOR MyNamespace::MyClass

     Necessary for lupdate.

     ...
 */</span></pre>
<p>After the comment, all references to <tt>MyClass::tr()</tt> will be understood as meaning <tt>MyNamespace::MyClass::tr()</tt>.</p>
<a name="translating-text-that-is-outside-of-a-qobject-subclass"></a>
<h3>Translating Text That is Outside of a QObject Subclass</h3>
<a name="using-qcoreapplication-translate"></a>
<h4>Using QCoreApplication::translate()</h4>
<p>If the quoted text is not in a member function of a <a href="qobject.html">QObject</a> subclass, use either the tr() function of an appropriate class, or the <a href="qcoreapplication.html#translate">QCoreApplication::translate</a>() function directly:</p>
<pre class="cpp"> <span class="type">void</span> some_global_function(LoginWidget <span class="operator">*</span>logwid)
 {
     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>label <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(
             LoginWidget<span class="operator">::</span>tr(<span class="string">&quot;Password:&quot;</span>)<span class="operator">,</span> logwid);
 }

 <span class="type">void</span> same_global_function(LoginWidget <span class="operator">*</span>logwid)
 {
     <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>label <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(
             qApp<span class="operator">-</span><span class="operator">&gt;</span>translate(<span class="string">&quot;LoginWidget&quot;</span><span class="operator">,</span> <span class="string">&quot;Password:&quot;</span>)<span class="operator">,</span>
             logwid);
 }</pre>
<a name="using-qt-tr-noop-and-qt-translate-noop"></a>
<h4>Using QT_TR_NOOP() and QT_TRANSLATE_NOOP()</h4>
<p>If you need to have translatable text completely outside a function, there are two macros to help: <a href="qtglobal.html#QT_TR_NOOP">QT_TR_NOOP</a>() and <a href="qtglobal.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>(). These macros merely mark the text for extraction by <a href="linguist-manager.html#lupdate">lupdate</a>. The macros expand to just the text (without the context).</p>
<p>Example of <a href="qtglobal.html#QT_TR_NOOP">QT_TR_NOOP</a>():</p>
<pre class="cpp"> <span class="type"><a href="qstring.html">QString</a></span> FriendlyConversation<span class="operator">::</span>greeting(<span class="type">int</span> greet_type)
 {
     <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span><span class="operator">*</span> greeting_strings<span class="operator">[</span><span class="operator">]</span> <span class="operator">=</span> {
         QT_TR_NOOP(<span class="string">&quot;Hello&quot;</span>)<span class="operator">,</span>
         QT_TR_NOOP(<span class="string">&quot;Goodbye&quot;</span>)
     };
     <span class="keyword">return</span> tr(greeting_strings<span class="operator">[</span>greet_type<span class="operator">]</span>);
 }</pre>
<p>Example of <a href="qtglobal.html#QT_TRANSLATE_NOOP">QT_TRANSLATE_NOOP</a>():</p>
<pre class="cpp"> <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span><span class="operator">*</span> greeting_strings<span class="operator">[</span><span class="operator">]</span> <span class="operator">=</span> {
     QT_TRANSLATE_NOOP(<span class="string">&quot;FriendlyConversation&quot;</span><span class="operator">,</span> <span class="string">&quot;Hello&quot;</span>)<span class="operator">,</span>
     QT_TRANSLATE_NOOP(<span class="string">&quot;FriendlyConversation&quot;</span><span class="operator">,</span> <span class="string">&quot;Goodbye&quot;</span>)
 };

 <span class="type"><a href="qstring.html">QString</a></span> FriendlyConversation<span class="operator">::</span>greeting(<span class="type">int</span> greet_type)
 {
     <span class="keyword">return</span> tr(greeting_strings<span class="operator">[</span>greet_type<span class="operator">]</span>);
 }

 <span class="type"><a href="qstring.html">QString</a></span> global_greeting(<span class="type">int</span> greet_type)
 {
     <span class="keyword">return</span> qApp<span class="operator">-</span><span class="operator">&gt;</span>translate(<span class="string">&quot;FriendlyConversation&quot;</span><span class="operator">,</span>
                             greeting_strings<span class="operator">[</span>greet_type<span class="operator">]</span>);
 }</pre>
<a name="tutorials"></a>
<h2>Tutorials</h2>
<p>Three tutorials are presented:</p>
<ol class="1">
<li><a href="linguist-hellotr.html">Hello tr()</a> demonstrates the creation of a <a href="qtranslator.html">QTranslator</a> object. It also shows the simplest use of the <tt>tr()</tt> function to mark user-visible source text for translation.</li>
<li><a href="linguist-arrowpad.html">Arrow Pad</a> explains how to make the application load the translation file applicable to the current locale. It also shows the use of the two-argument form of <tt>tr()</tt> which provides additional information to the translator.</li>
<li><a href="linguist-trollprint.html">Troll Print</a> explains how identical source texts can be distinguished even when they occur in the same context. This tutorial also discusses how the translation tools help minimize the translator's work when an application is upgraded.</li>
</ol>
<p>These tutorials cover all that you need to know to prepare your Qt applications for translation.</p>
<p>At the beginning of a project add the translation source files to be used to the project file and add calls to <a href="linguist-manager.html#lupdate">lupdate</a> and <a href="linguist-manager.html#lrelease">lrelease</a> to the Makefile.</p>
<p>During the project all the programmer must do is wrap any user-visible text in <tt>tr()</tt> calls. They should also use the two argument form for Ctrl key accelerators, or when asked by the translator for the cases where the same text translates into two different forms in the same context. The programmer should also include <tt>TRANSLATION</tt> comments to help the translator navigate the application.</p>
</div>
<!-- @@@linguist-programmers.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="linguist-translators.html">Qt Linguist Manual: Translators</a>
<a class="nextPage" href="linguist-ts-file-format.html">Qt Linguist Manual: TS File Format</a>
</p>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>