<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/internationalization-of-shiny-apps-has-never-been-easier/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://appsilondatascience.com/internationalization-of-shiny-apps-i18n/"> r – Appsilon Data Science | We Provide EndÂ­ toÂ­ End Data Science Solutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h1>Why?</h1>
<p>Have you ever created a multilingual Shiny app? It is very likely that the answer isÂ <strong>no</strong>, because Shiny just doesn't have any good tools for that. InÂ <a rel="nofollow" href="https://appsilon.com/" target="_blank">Appsilon</a>Â we came across the internationalization problem many times, so we decided to make a tool which makes a live easier when it comes to mulitlingual.Â <code>shiny.i18n</code>Â is the new kid on the block and still under rapid development, but theÂ <code>0.1.0</code>Â version is already ready to go.</p>
<blockquote>
<p><strong><em>NOTE:</em></strong><em>shiny.i18n</em><em>Â usage is not limited to Shiny apps. You can use it as standalone R package for generating multilingual reports or visualizations. We decided on this name because Shiny is the most common and obvious use-case scenario.</em></p>
</blockquote>
<h1>Where?</h1>
<p>The latest version the package (0.1.0) has been released recently to CRAN, so you can simply get it like this:</p>
<figure>
<pre><code data-lang="r"><span>install.packages</span><span>(&quot;</span><span>shiny.i18n&quot;</span><span>)</span></code></pre>
</figure>
<p>To install the development version always check theÂ <a rel="nofollow" href="https://github.com/Appsilon/shiny.i18n" target="_blank">GitHub project</a>Â first.</p>
<figure>
<pre><code data-lang="r"><span>devtools</span><span>::</span><span>install_github</span><span>(</span><span>&quot;Appsilon/shiny.i18n&quot;</span><span>)</span></code></pre>
</figure>
<p>In the GitHub page, you can also find more examples, read the documentation, post some issues or your own contributions.</p>
<h1>How?</h1>
<p>Now it's time to learn more about how to useÂ shiny.i18n. The package utilizes specific translation file data formats. Currently two approaches are supported.</p>
<h2><strong>JSON translation format</strong></h2>
<p>Example of a JSON translation file for English and polish language you can find below:</p>
<figure>
<pre><code data-lang="r">
<span>{</span>
  <span>&quot;languages&quot;</span><span>:</span> <span>[</span><span>&quot;en&quot;</span><span>,</span> <span>&quot;pl&quot;</span><span>],</span>
  <span>&quot;translation&quot;</span><span>:</span> <span>[</span>
      <span>{</span><span>&quot;en&quot;</span><span>:</span> <span>&quot;Hello Shiny!&quot;</span><span>,</span> <span>&quot;pl&quot;</span><span>:</span> <span>&quot;Witaj Shiny!&quot;</span><span>},</span>
      <span>{</span><span>&quot;en&quot;</span><span>:</span> <span>&quot;Number of bins:&quot;</span><span>,</span> <span>&quot;pl&quot;</span><span>:</span> <span>&quot;Liczba podziaÅ‚ek&quot;</span><span>},</span>
      <span>{</span>
        <span>&quot;en&quot;</span><span>:</span> <span>&quot;This is description of the plot.&quot;</span><span>,</span>
        <span>&quot;pl&quot;</span><span>:</span> <span>&quot;To jest opis obrazka.&quot;</span>
      <span>},</span>
      <span>{</span>
        <span>&quot;en&quot;</span><span>:</span> <span>&quot;Histogram of x&quot;</span><span>,</span>
        <span>&quot;pl&quot;</span><span>:</span> <span>&quot;Histogram x&quot;</span>
      <span>},</span>
      <span>{</span>
        <span>&quot;en&quot;</span><span>:</span> <span>&quot;Frequency&quot;</span><span>,</span>
        <span>&quot;pl&quot;</span><span>:</span> <span>&quot;CzÄ™stotliwoÅ›Ä‡&quot;</span>
      <span>}</span>
    <span>]</span>
<span>}</span>
</code></pre>
</figure>
<p>It consists of a single fileÂ translation.jsonÂ with two mandatory fields:</p>
<ul>
<li>“languages”with a list of all language codes;</li>
<li>“translation”with a list of dictionaries assigning translation to a language code.</li>
</ul>
<p>Other fields (such asÂ cultural_date_format) are optional and if missing will be read fromÂ <a rel="nofollow" href="https://github.com/Appsilon/shiny.i18n/blob/master/inst/config.yaml" target="_blank">default config</a>Â yamlÂ file.</p>
<h2><strong>CSV translation format</strong></h2>
<p>Another approach is to use a CSV format. The main idea behind it is to support distributed translation tasks among many translators. Instead of having to concatenate results of work from many translators together, we can just store them in a common folder with the specific name of the file:Â translation_