<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/written-r-exams-around-the-world/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exams.org/tutorials/nops_language/"> R/exams</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>How to internationalize exams2nops() by adding support for new natural languages in written R/exams (that can be automatically scanned and evaluated).</p>
<p><img alt="Written R/exams around the World" src="https://i0.wp.com/www.r-exams.org/images/nops.title.jpg?w=456" data-recalc-dims="1"></p>
<h2>Idea</h2>
<p>In addition to completely customizable PDF output, R/exams provides a standardized format called<br>
“NOPS” for <a rel="nofollow" href="http://www.r-exams.org/intro/written/" target="_blank">written exams</a> with multiple-choice<br>
(and/or single-choice) exercises that can be<br>
<a rel="nofollow" href="http://www.r-exams.org/tutorials/exams2nops/" target="_blank">automatically generated, scanned, and evaluated</a>.<br>
In order to assure that the automatic scanning works the title page has a fixed layout<br>
that cannot be modified by R/exams users. However, to internationalize the format there<br>
is a possibility for customizing the natural language support. A number of languages<br>
is already available but it is not difficult to add further languages or to tweak<br>
existing languages if desired.</p>
<h2>Example</h2>
<p>To illustrate how the language support works, once it has been fully incorporated into the<br>
<code>exams</code> package, we set up a short exam with three exercises:<br>
<a rel="nofollow" href="http://www.r-exams.org/templates/deriv2/" target="_blank">deriv2</a>, <a rel="nofollow" href="http://www.r-exams.org/templates/tstat2/" target="_blank">tstat2</a>,<br>
<a rel="nofollow" href="http://www.r-exams.org/templates/swisscapital/" target="_blank">swisscapital</a>. All of these are readily available<br>
in the package (and are actually in English).</p>
<pre><code>library(&quot;exams&quot;)
myexam &lt;- c(&quot;deriv2.Rnw&quot;, &quot;tstat2.Rnw&quot;, &quot;swisscapital.Rnw&quot;)</code></pre>
<p>Then we set up PDF output in English (en), German (de), and Spanish (es).<br>
By setting <code>language</code> most text on the title page is modified, only the name of the<br>
<code>institution</code> and the <code>title</code> of the exam have to be set separately. For the English<br>
example we produce <code>n = 1</code> PDF output file in the output directory <code>nops_pdf</code> (created<br>
automatically).</p>
<pre><code>set.seed(403)
exams2nops(myexam, n = 1, language = &quot;en&quot;,
  institution = &quot;R University&quot;, title = &quot;Exam&quot;,
  dir = &quot;nops_pdf&quot;, name = &quot;en&quot;, date = &quot;2018-01-08&quot;)</code></pre>
<p>Then we do the same for the other two languages.</p>
<pre><code>set.seed(403)
exams2nops(myexam, n = 1, language = &quot;de&quot;,
  institution = &quot;R Universit\\\&quot;at&quot;, title = &quot;Klausur&quot;,
  dir = &quot;nops_pdf&quot;, name = &quot;de&quot;, date = &quot;2018-01-08&quot;)
set.seed(403)
exams2nops(myexam, n = 1, language = &quot;es&quot;,
  institution = &quot;R Universidad&quot;, title = &quot;Examen&quot;,
  dir = &quot;nops_pdf&quot;, name = &quot;es&quot;, date = &quot;2018-01-08&quot;)</code></pre>
<p>The title pages of the resulting PDF files then have the desired languages.</p>
<p><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//en1.pdf" target="_blank"><img alt="en1.pdf" src="https://i0.wp.com/www.r-exams.org/assets/posts/2018-01-08-nops_language/en1.png?w=456" data-recalc-dims="1"></a><br>
<a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//de1.pdf" target="_blank"><img alt="de1.pdf" src="https://i1.wp.com/www.r-exams.org/assets/posts/2018-01-08-nops_language/de1.png?w=456" data-recalc-dims="1"></a><br>
<a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//es1.pdf" target="_blank"><img alt="es1.pdf" src="https://i2.wp.com/www.r-exams.org/assets/posts/2018-01-08-nops_language/es1.png?w=456" data-recalc-dims="1"></a></p>
<h2>Language specification</h2>
<p>To add a new language, essentially just a single text file (say <code>lang.dcf</code>) is needed containing<br>
suitable translations of all the phrases on the title page as well as a few additional phrases,<br>
e.g., occuring in the HTML evaluation reports etc.<br>
As an example, the first few phrases in English (<code>en.dcf</code>) are:</p>
<pre>
PersonalData: Personal Data
Name: Name
FamilyName: Family Name
GivenName: Given Name
Signature: Signature
RegistrationNumber: Registration Number
Checked: checked
NoChanges: In this section \textbf{no} changes or modifications must be made!
...
</pre>
<p>And the corresponding translations to German (<code>de.dcf</code>) are:</p>
<pre>
PersonalData: Pers{\&quot;o}nliche Daten
Name: Name
FamilyName: Nachname
GivenName: Vorname
Signature: Unterschrift
RegistrationNumber: Matrikelnummer
Checked: gepr{\&quot;u}ft
NoChanges: In diesem Feld d{\&quot;u}rfen \textbf{keine} Ver{\&quot;a}nderungen der Daten vorgenommen werden!
...
</pre>
<p>Note that here LaTeX markup is used for the German umlaute and for bold highlighting. Alternatively,<br>
special characters can be added in a suitable encoding (typically UTF-8) but then the encoding has<br>
to be declared when calling <code>exams2nops()</code> (e.g., <code>encoding = &quot;UTF-8&quot;</code>).</p>
<p>Most of the phrases required in the <code>.dcf</code> are very straightforward and only some are a bit technical.<br>
There are also a couple of coordinates (<code>MarkExample*</code>) necessary for aligning some text lines.<br>
If you have set up your own <code>lang.dcf</code> you can easily pass it to <code>exams2nops()</code> by setting<br>
<code>language = &quot;/path/to/lang.dcf&quot;</code>. The same has to be done for <code>nops_eval()</code> when evaluating the exam.</p>
<h2>Currently available languages</h2>
<p>Due to the kind support from friends and various dedicated R/exams users, there is already support<br>
for many important Western languages as well as a few other languages/countries. All of these<br>
are directly available in the R package (note that <code>&quot;tr&quot;</code> requires the current<br>
<a rel="nofollow" href="http://r-forge.r-project.org/R/?group_id=1337" target="_blank">development version from R-Forge</a>, though). But for convenience<br>
and manual inspection the <code>.dcf</code> files are also linked here.</p>
<table>
<thead>
<tr>
<th>File</th>
<th>Language</th>
<th>Contributor</th>
</tr>
</thead>
<tbody>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//de.dcf" target="_blank">de.dcf</a></td>
<td>German</td>
<td><a rel="nofollow" href="https://eeecon.uibk.ac.at/~zeileis/" target="_blank">Achim Zeileis</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//en.dcf" target="_blank">en.dcf</a></td>
<td>English</td>
<td><a rel="nofollow" href="https://eeecon.uibk.ac.at/~zeileis/" target="_blank">Achim Zeileis</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//es.dcf" target="_blank">es.dcf</a></td>
<td>Spanish</td>
<td><a rel="nofollow" href="http://www.broomcenter.ucsb.edu/people/maria-kogelnik" target="_blank">Maria Kogelnik</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//fi.dcf" target="_blank">fi.dcf</a></td>
<td>Finnish</td>
<td><a rel="nofollow" href="http://klausnordhausen.com/" target="_blank">Klaus Nordhausen</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//fr.dcf" target="_blank">fr.dcf</a></td>
<td>French</td>
<td><a rel="nofollow" href="https://github.com/aallignol" target="_blank">Arthur Allignol</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//hu.dcf" target="_blank">hu.dcf</a></td>
<td>Hungarian</td>
<td><a rel="nofollow" href="https://twitter.com/daroczig" target="_blank">Gergely Daróczi</a> &amp; Dénes Tóth</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//it.dcf" target="_blank">it.dcf</a></td>
<td>Italian</td>
<td><a rel="nofollow" href="https://domenicozambella.altervista.org/" target="_blank">Domenico Zambella</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//nl.dcf" target="_blank">nl.dcf</a></td>
<td>Dutch</td>
<td><a rel="nofollow" href="https://www.uva.nl/en/profile/s/m/n.smits/n.smits.html" target="_blank">Niels Smits</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//pt.dcf" target="_blank">pt.dcf</a></td>
<td>Portugese</td>
<td><a rel="nofollow" href="http://www.if.ufrj.br/~orca/" target="_blank">Mauricio Calvão</a> &amp; Fabian Petutschnig</td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//ro.dcf" target="_blank">ro.dcf</a></td>
<td>Romanian</td>
<td><a rel="nofollow" href="https://profs.info.uaic.ro/~cgatu/" target="_blank">Cristian Gatu</a></td>
</tr>
<tr>
<td><a rel="nofollow" href="http://www.r-exams.org/assets/posts/2018-01-08-nops_language//tr.dcf" target="_blank">tr.dcf</a></td>
<td>Turkish</td>
<td><a rel="nofollow" href="http://eremrah.com/" target="_blank">Emrah Er</a></td>
</tr>
</tbody>
</table>
<h2>Contributing new languages</h2>
<p>If you want to contribute a new language, simply set up a <code>.dcf</code> file starting out from one of the examples<br>
above and send the file or a link to<br>
<em></em>