This file is indexed.

/usr/share/qt5/doc/qtlinguist/qtlinguist-arrowpad-example.html is in qttools5-doc-html 5.9.5-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- arrowpad.qdoc -->
  <title>Arrow Pad Example | Qt Linguist Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtlinguist-index.html">Qt Linguist Manual</a></td><td ><a href="examples-linguist.html">Qt Linguist Examples</a></td><td >Arrow Pad Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#line-by-line-walkthrough">Line by Line Walkthrough</a></li>
<li class="level1"><a href="#translating-to-french-and-dutch">Translating to French and Dutch</a></li>
<li class="level1"><a href="#exercises">Exercises</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Arrow Pad Example</h1>
<span class="subtitle"></span>
<!-- $$$arrowpad-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/linguist-arrowpad_en.png" alt="" /></p><p>We will use two translations, French and Dutch, although there is no effective limit on the number of possible translations that can be used with an application. The relevant lines of <code>arrowpad.pro</code> are</p>
<pre class="cpp">

  HEADERS      = arrowpad.h \
                 mainwindow.h
  SOURCES      = arrowpad.cpp \
                 main.cpp \
                 mainwindow.cpp

  TRANSLATIONS = arrowpad_fr.ts \
                 arrowpad_nl.ts

</pre>
<p>Run <code>lupdate</code>; it should produce two identical message files <code>arrowpad_fr.ts</code> and <code>arrowpad_nl.ts</code>. These files will contain all the source texts marked for translation with <code>tr()</code> calls and their contexts.</p>
<p>See the <a href="qtlinguist-index.html">Qt Linguist Manual</a> for more information about translating Qt application.</p>
<a name="line-by-line-walkthrough"></a>
<h2 id="line-by-line-walkthrough">Line by Line Walkthrough</h2>
<p>In <code>arrowpad.h</code> we define the <code>ArrowPad</code> subclass which is a subclass of QWidget. In the screenshot above, the central widget with the four buttons is an <code>ArrowPad</code>.</p>
<pre class="cpp">

  <span class="keyword">class</span> ArrowPad : <span class="keyword">public</span> <span class="type">QWidget</span>
  {
      Q_OBJECT

</pre>
<p>When <code>lupdate</code> is run it not only extracts the source texts but it also groups them into contexts. A context is the name of the class in which the source text appears. Thus, in this example, &quot;ArrowPad&quot; is a context: it is the context of the texts in the <code>ArrowPad</code> class. The <code>Q_OBJECT</code> macro defines <code>tr(x)</code> in <code>ArrowPad</code> like this:</p>
<pre class="cpp">

  qApp<span class="operator">-</span><span class="operator">&gt;</span>translate(<span class="string">&quot;ArrowPad&quot;</span><span class="operator">,</span> x)

</pre>
<p>Knowing which class each source text appears in enables <i>Qt Linguist</i> to group texts that are logically related together, e.g&#x2e; all the text in a dialog will have the context of the dialog's class name and will be shown together. This provides useful information for the translator since the context in which text appears may influence how it should be translated. For some translations keyboard accelerators may need to be changed and having all the source texts in a particular context (class) grouped together makes it easier for the translator to perform any accelerator changes without introducing conflicts.</p>
<p>In <code>arrowpad.cpp</code> we implement the <code>ArrowPad</code> class.</p>
<pre class="cpp">

      upButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QPushButton</span>(tr(<span class="string">&quot;&amp;Up&quot;</span>));
      downButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QPushButton</span>(tr(<span class="string">&quot;&amp;Down&quot;</span>));
      leftButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QPushButton</span>(tr(<span class="string">&quot;&amp;Left&quot;</span>));
      rightButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QPushButton</span>(tr(<span class="string">&quot;&amp;Right&quot;</span>));

</pre>
<p>We call <code>ArrowPad::tr()</code> for each button's label since the labels are user-visible text.</p>
<p class="centerAlign"><img src="images/linguist-arrowpad_en.png" alt="" /></p><pre class="cpp">

  <span class="keyword">class</span> MainWindow : <span class="keyword">public</span> <span class="type">QMainWindow</span>
  {
      Q_OBJECT

</pre>
<p>In the screenshot above, the whole window is a <code>MainWindow</code>. This is defined in the <code>mainwindow.h</code> header file. Here too, we use <code>Q_OBJECT</code>, so that <code>MainWindow</code> will become a context in <i>Qt Linguist</i>.</p>
<pre class="cpp">

      arrowPad <span class="operator">=</span> <span class="keyword">new</span> ArrowPad;

</pre>
<p>In the implementation of <code>MainWindow</code>, <code>mainwindow.cpp</code>, we create an instance of our <code>ArrowPad</code> class.</p>
<pre class="cpp">

      exitAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QAction</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>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Quit);
      connect(exitAct<span class="operator">,</span> SIGNAL(triggered())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(close()));

</pre>
<p>We also call <code>MainWindow::tr()</code> twice, once for the action and once for the shortcut.</p>
<p>Note the use of <code>tr()</code> to support different keys in other languages. &quot;Ctrl+Q&quot; is a good choice for Quit in English, but a Dutch translator might want to use &quot;Ctrl+A&quot; (for Afsluiten) and a German translator &quot;Strg+E&quot; (for Beenden). When using <code>tr()</code> for <b>Ctrl</b> key accelerators, the two argument form should be used with the second argument describing the function that the accelerator performs.</p>
<p>Our <code>main()</code> function is defined in <code>main.cpp</code> as usual.</p>
<pre class="cpp">

      <span class="type"><a href="../qtcore/qtranslator.html">QTranslator</a></span> translator;
      translator<span class="operator">.</span>load(<span class="type"><a href="../qtcore/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>We choose which translation to use according to the current locale. <a href="../qtcore/qlocale.html#system">QLocale::system</a>() can be influenced by setting the <code>LANG</code> environment variable, for example. Notice that the use of a naming convention that incorporates the locale for <code>.qm</code> message files, (and TS files), makes it easy to implement choosing the translation file according to locale.</p>
<p>If there is no QM message file for the locale chosen the original source text will be used and no error raised.</p>
<a name="translating-to-french-and-dutch"></a>
<h2 id="translating-to-french-and-dutch">Translating to French and Dutch</h2>
<p>We'll begin by translating the example application into French. Start <i>Qt Linguist</i> with <code>arrowpad_fr.ts</code>. You should get the seven source texts (&quot;&amp;Up&quot;, &quot;&amp;Left&quot;, etc.) grouped in two contexts (&quot;ArrowPad&quot; and &quot;MainWindow&quot;).</p>
<p>Now, enter the following translations:</p>
<ul>
<li><code>ArrowPad</code><ul>
<li>&amp;Up - &amp;Haut</li>
<li>&amp;Left - &amp;Gauche</li>
<li>&amp;Right - &amp;Droite</li>
<li>&amp;Down - &amp;Bas</li>
</ul>
</li>
<li><code>MainWindow</code><ul>
<li>E&amp;xit - &amp;Quitter</li>
<li>Ctrl+Q - Ctrl+Q</li>
<li>&amp;File - &amp;Fichier</li>
</ul>
</li>
</ul>
<p>It's quickest to press <b>Alt+D</b> (which clicks the <b>Done &amp; Next</b> button) after typing each translation, since this marks the translation as done and moves on to the next source text.</p>
<p>Save the file and do the same for Dutch working with <code>arrowpad_nl.ts</code>:</p>
<ul>
<li><code>ArrowPad</code><ul>
<li>&amp;Up - &amp;Omhoog</li>
<li>&amp;Left - &amp;Links</li>
<li>&amp;Right - &amp;Rechts</li>
<li>&amp;Down - Omlaa&amp;g</li>
</ul>
</li>
<li><code>MainWindow</code><ul>
<li>E&amp;xit - &amp;Afsluiten</li>
<li>Ctrl+Q - Ctrl+A</li>
<li>File - &amp;Bestand</li>
</ul>
</li>
</ul>
<p>We have to convert the <code>tt1_fr.ts</code> and <code>tt1_nl.ts</code> translation source files into QM files. We could use <i>Qt Linguist</i> as we've done before; however using the command line tool <code>lrelease</code> ensures that <i>all</i> the QM files for the application are created without us having to remember to load and <b>File|Release</b> each one individually from <i>Qt Linguist</i>.</p>
<p>Type</p>
<pre class="cpp">

  lrelease arrowpad<span class="operator">.</span>pro

</pre>
<p>This should create both <code>arrowpad_fr.qm</code> and <code>arrowpad_nl.qm</code>. Set the <code>LANG</code> environment variable to <code>fr</code>. In Unix, one of the two following commands should work</p>
<pre class="cpp">

  <span class="keyword">export</span> LANG<span class="operator">=</span>fr
  setenv LANG fr

</pre>
<p>In Windows, either modify <code>autoexec.bat</code> or run</p>
<pre class="cpp">

  set LANG<span class="operator">=</span>fr

</pre>
<p>When you run the program, you should now see the French version:</p>
<p class="centerAlign"><img src="images/linguist-arrowpad_fr.png" alt="" /></p><p>Try the same with Dutch, by setting <code>LANG=nl</code>. Now the Dutch version should appear:</p>
<p class="centerAlign"><img src="images/linguist-arrowpad_nl.png" alt="" /></p><a name="exercises"></a>
<h2 id="exercises">Exercises</h2>
<p>Mark one of the translations in <i>Qt Linguist</i> as not done, i.e&#x2e; by unchecking the &quot;done&quot; checkbox; run <code>lupdate</code>, then <code>lrelease</code>, then the example. What effect did this change have?</p>
<p>Set <code>LANG=fr_CA</code> (French Canada) and run the example program again. Explain why the result is the same as with <code>LANG=fr</code>.</p>
<p>Change one of the accelerators in the Dutch translation to eliminate the conflict between <i>&amp;Bestand</i> and <i>&amp;Boven</i>.</p>
<p>Files:</p>
<ul>
<li><a href="qtlinguist-arrowpad-arrowpad-cpp.html">arrowpad/arrowpad.cpp</a></li>
<li><a href="qtlinguist-arrowpad-arrowpad-h.html">arrowpad/arrowpad.h</a></li>
<li><a href="qtlinguist-arrowpad-mainwindow-cpp.html">arrowpad/mainwindow.cpp</a></li>
<li><a href="qtlinguist-arrowpad-mainwindow-h.html">arrowpad/mainwindow.h</a></li>
<li><a href="qtlinguist-arrowpad-main-cpp.html">arrowpad/main.cpp</a></li>
<li><a href="qtlinguist-arrowpad-arrowpad-pro.html">arrowpad/arrowpad.pro</a></li>
</ul>
</div>
<!-- @@@arrowpad -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    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.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>