<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mostovenko Alexander on Medium]]></title>
        <description><![CDATA[Stories by Mostovenko Alexander on Medium]]></description>
        <link>https://medium.com/@MostovenkoA?source=rss-fea251fc9ccb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_7PfzmEYa3IFerAO.jpg</url>
            <title>Stories by Mostovenko Alexander on Medium</title>
            <link>https://medium.com/@MostovenkoA?source=rss-fea251fc9ccb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:49:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@MostovenkoA/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simple i18n for Create React App with ttag]]></title>
            <link>https://medium.com/hackernoon/simple-i18n-for-create-react-app-with-ttag-4c2892343201?source=rss-fea251fc9ccb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c2892343201</guid>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[i18n]]></category>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mostovenko Alexander]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 23:32:48 GMT</pubDate>
            <atom:updated>2019-05-21T20:45:59.094Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will describe how you can set up the translation process for <strong>Create React App</strong> with <a href="https://ttag.js.org/">ttag</a> in a few minutes with 5 simple steps.</p><p>First of all, there are at least 4 reasons why you should choose ttag with <a href="https://hackernoon.com/tagged/cra">CRA</a>:</p><ul><li><strong>Doesn’t require to execute eject</strong>.</li><li>ttag is the <strong>framework agnostic solution</strong> that works everywhere where <a href="https://hackernoon.com/tagged/javascript">javascript</a> and babel works. Supports <strong>jsx</strong> out of the box.</li><li>ttag works with <em>gettext</em> standard, that is very common to translators and <strong>can be integrated with any workflow and translation services</strong> like transifex, weblate e.t.c</li><li>ttag does not require you to use some ‘alien’ formatting rules like sprintf. You just simply use <strong>native javascript template literals</strong> for formatting like:</li></ul><pre>t`Hello ${ name }`</pre><p>At the end of this tutorial, we will setup <strong>i18n</strong> for <strong>CRA</strong> starter page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMnabttiOByRCMLPPVOX8w.jpeg" /></figure><blockquote>Demo site — <a href="https://ttag-org.github.io/CRA-runtime-example/">https://ttag-org.github.io/CRA-runtime-example/</a></blockquote><blockquote>Repository — <a href="https://github.com/ttag-org/CRA-runtime-example">https://github.com/ttag-org/CRA-runtime-example</a></blockquote><h3>Step 1. Installation</h3><p>On this step, we will simply set up new CRA and install ttag:</p><pre>npx create-react-app ttag-app<br>cd ttag-app<br>npm i ttag<br>npm i -D ttag-cli</pre><h3>Step 2. Create .po file for translations</h3><blockquote>You can read more about gettext and .po files format <a href="https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html">here</a></blockquote><p>According to gettext, we need to create a separate .po file for each language that we want to translate to. We can use ttag-cli to create this file:</p><pre>mkdir i18n <br>npx ttag init uk i18n/uk.po</pre><p>ttag init uk i18n/uk.po will create po file for the Ukrainian language (uk is the language code).</p><blockquote>You can find the list of all available language codes here — <a href="https://www.w3.org/International/O-charset-lang.html">https://www.w3.org/International/O-charset-lang.html</a></blockquote><h3>Step 3. Wrapping strings with tags</h3><p>To make strings translatable you should mark them with tags. Let’s open App.js file and make phrase Learn React translatable:</p><pre>import { t } from &#39;ttag&#39;</pre><pre>// Change &#39;Learn React&#39; to <br>t`Learn React`</pre><blockquote><a href="https://ttag.js.org/docs/jsx-gettext.html">There is also </a><a href="https://ttag.js.org/docs/jsx-gettext.html"><em>jt</em> tag that can contain nested jsx elements</a></blockquote><h3>Step 4. Updating translations file</h3><p>To make strings to appear in the .po file we can use update command from ttag-cli</p><pre>npx ttag update i18n/uk.po src/</pre><p>And we should see that our phrase Learn React was added to the uk.po file:</p><pre>msgid &quot;Learn React&quot; <br>msgstr &quot;&quot;</pre><p>msgstr is the place where translation must be added:</p><pre>msgid &quot;Learn React&quot;<br>msgstr &quot;Вивчити React&quot;</pre><h3>Step 5. Loading translations</h3><p>On this final step, we should load and apply translations from the .po file. To be able to load po file let’s convert it to json format with ttag-cli:</p><pre>npx ttag po2json i18n/uk.po &gt; i18n/uk.po.json</pre><p>Now we can load uk.po.json file with a simple import or require.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e412e33a9b0c789aa2e920102cb98f9d/href">https://medium.com/media/e412e33a9b0c789aa2e920102cb98f9d/href</a></iframe><p>The implementation of getLocale function depends on your requirements. You can choose to store locale in url, cookies, localStorage or some other place. Something like:</p><pre>function getLocale() {  <br>    return cookie.get(LOCALE_COOKIE) || &#39;en&#39;;<br>}</pre><blockquote><a href="https://github.com/ttag-org/CRA-runtime-example/blob/master/app/src/i18nInit.js">Here is my example of </a><a href="https://github.com/ttag-org/CRA-runtime-example/blob/master/app/src/i18nInit.js"><em>i18nInit</em></a><em>.js</em></blockquote><p>I would recommend to move i18n setup to a separate module and import it before any other imports at the top of the entry point of your app (somewhere in <a href="https://github.com/ttag-org/CRA-runtime-example/blob/master/app/src/index.js">src/index.js</a>)</p><h3>And that’s it!</h3><p>In the end, you should also set up some languages switch logic. You can refer to the example <a href="https://github.com/ttag-org/CRA-runtime-example/blob/master/app/src/App.js">repository</a> for the details on how to do that. As a bonus, ttag also allows you to precompile translations on a build step. You can read about how to do that in the <a href="https://ttag.js.org/docs/create-react-app.html#precompiled-translations">doc</a>.</p><p>Hope this will help someone to setup translation workflow with CRA. Any feedback is appreciated. Feel free to create <a href="https://github.com/ttag-org/ttag">issues</a> and leave comments.</p><p>Happy coding!</p><h4>Links:</h4><ul><li>The official doc for ttag and CRA — <a href="https://ttag.js.org/docs/create-react-app.html">https://ttag.js.org/docs/create-react-app.html</a></li><li>ttag lib — <a href="https://github.com/ttag-org/ttag">https://github.com/ttag-org/ttag</a></li><li>babel-plugin-ttag — <a href="https://github.com/ttag-org/babel-plugin-ttag">https://github.com/ttag-org/babel-plugin-ttag</a></li><li>ttag-cli — <a href="https://github.com/ttag-org/ttag-cli">https://github.com/ttag-org/ttag-cli</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c2892343201" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/simple-i18n-for-create-react-app-with-ttag-4c2892343201">Simple i18n for Create React App with ttag</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localization in javascript with c-3po]]></title>
            <link>https://medium.com/hackernoon/localization-in-javascript-with-c-3po-7bb5b96a4e01?source=rss-fea251fc9ccb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bb5b96a4e01</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mostovenko Alexander]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 16:00:46 GMT</pubDate>
            <atom:updated>2019-05-07T04:39:49.344Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Project was renamed to <strong>ttag</strong>. Follow the new doc — <a href="https://ttag.js.org/">https://ttag.js.org/</a>. The name was changed due to the possible legal infringement. (look at this <a href="https://github.com/ttag-org/ttag/issues/104">issue</a> for the details)</blockquote><p>Hi everyone!</p><p>This article is about new <strong>javascript localization</strong> tool — <a href="https://c-3po.js.org/"><strong>c-3po</strong></a>. We have been using c-3po for nearly a year in production and are happy with it. <strong>c-3po</strong> was designed to provide an intelligent and reliable translation workflow on top of <strong>GNU gettext</strong> format. In general, c-3po is a library plus a set of <a href="https://hackernoon.com/tagged/tools">tools</a> that will allow you to localize your project with minimal effort.</p><p>Fear question: “<strong>Why</strong> <strong>yet another one localization library</strong>?”. There are a couple of mature solutions for the localization that you can be happy with, but the main reasons why we decided to build our own were:</p><ul><li>We didn’t want to use <a href="https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm"><strong>sprintf</strong></a> formatting for strings. <strong>es6</strong> introduced <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"><strong>template strings</strong></a>, we just wanted to use them for the string formatting.</li><li>We were looking for the intelligent tool that can extract translation strings from the sources (js, jsx) and will be able to add some kind of validation for the extracted strings.</li><li>We were searching for the solution that will allow us to precompile translations on a build step and on script execution also.</li><li>Framework agnostic solution, that can be integrated almost in any <a href="https://hackernoon.com/tagged/javascript">javascript</a> framework and can be used with any build tool.</li><li>Wanted to ensure that all strings are translated during CI builds.</li></ul><h3>Welcome, c-3po!</h3><p>Here are some examples of how this library can be used:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df73474bd32b05f408054795ccf3d5c0/href">https://medium.com/media/df73474bd32b05f408054795ccf3d5c0/href</a></iframe><p>Plural forms support:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76963558b897531e488cb8fec5398ae3/href">https://medium.com/media/76963558b897531e488cb8fec5398ae3/href</a></iframe><blockquote>More details about why we should use the t tag for the first argument with <strong>msgid</strong> are <a href="https://c-3po.js.org/why-use-msgid-for-ngettext.html">here</a>.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e412e33a9b0c789aa2e920102cb98f9d/href">https://medium.com/media/e412e33a9b0c789aa2e920102cb98f9d/href</a></iframe><p>Contexts support:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/409f4fab3da70301565cd8ddf4ae1caa/href">https://medium.com/media/409f4fab3da70301565cd8ddf4ae1caa/href</a></iframe><h3>.po files</h3><p>According to the <strong>GNU gettext</strong> format, all translations are placed inside <strong>.po </strong>files. Each locale has it’s separate <strong>.po</strong> file and all translations are added there. The <strong>c-3po</strong> ecosystem provides reliable toolset that can create and update those <strong>.po</strong> files.</p><p>So, somehow we must parse our source code and extract all strings that are wrapped with c-3po tags and functions. For that purpose, we created <a href="https://github.com/c-3po-org/babel-plugin-c-3po"><strong>babel-plugin-c-3po</strong></a> that works well with javascript AST. As a result, it can be used everywhere where babel works (jsx, ts, tsx, React Native e.t.c). There is a separate documentation page for the plugin options <a href="https://c-3po.js.org/configuration.html">here</a>. Just to reduce some boilerplate work we created <a href="https://github.com/c-3po-org/c-3po-cli"><strong>c-3po-cli</strong></a>, that works on top of that plugin.</p><blockquote>npm install -g c-3po will add the c-3po command to your environment, which will be used in the examples below.</blockquote><h3>.po files creation</h3><p>Let’s imagine that we have hello.js file and want to localize it to the Ukrainian language.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11860ac761cb4af8c0062cf9aa1e039a/href">https://medium.com/media/11860ac761cb4af8c0062cf9aa1e039a/href</a></iframe><p>To get started, you need to setup <strong>.po</strong> file for the Ukrainian language.</p><pre>c-3po init uk uk.po</pre><blockquote><strong>uk</strong> is the ISO code for the Ukrainian language. (all supported codes can be found <a href="http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html">here</a>)</blockquote><p>init command will create empty po file with the minimal set of the required headers.</p><h3>Extracting and updating translations to the .po file</h3><p>To extract all tagged strings you need to execute one simple command:</p><pre>c-3po update uk.po hello.js</pre><p>After that our Hello ${ name } string must appear in the <strong>uk.po</strong> file:</p><pre>#: hello.js:3<br>msgid &quot;Hello ${ name }&quot;<br>msgstr &quot;</pre><blockquote><strong>update</strong> command will add new strings and will delete those that are not present in the sources. If your workflow requires <strong>.pot</strong> files — you can use extract and merge commands.</blockquote><h3>Building localized files</h3><p>If you can afford to build a separate bundle for every language, it is recommended to do so, as it will increase client performance (no extra parsing and replacing on a client + smaller bundles).</p><pre>c-3po replace uk.po hello-uk.js hello.js</pre><p>This command will create a localized version of the original file hello-uk.js with all translations applied from uk.po.</p><h3>Applying translations at runtime</h3><p>Another option is that you can apply appropriate <strong>.po</strong> file on a script execution.</p><p>Here is how you can achieve this for our simple hello.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cf39d94211a89a09535ffa675bbc4b0/href">https://medium.com/media/3cf39d94211a89a09535ffa675bbc4b0/href</a></iframe><p>You can also build your workflow with webpack and <a href="https://github.com/cah4a/po-gettext-loader">po-gettext-loader</a> and import appropriate .po with dynamic imports.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ecdcf47572d6a55c4d9cb8d6a2d8945/href">https://medium.com/media/4ecdcf47572d6a55c4d9cb8d6a2d8945/href</a></iframe><p>With this setup, every change in a .po file will trigger the webpack build. You can read more about different setups with webpack <a href="https://c-3po.js.org/localization-with-webpack-and-c-3po.html">here</a>.</p><h3>Translations validation and CI</h3><p>This command will throw if there are some untranslated strings or some invalid translations wrapped with tags:</p><pre>c-3po check uk.po hello.js</pre><p>More details on <strong>validation</strong> — <a href="https://c-3po.js.org/validation.html">https://c-3po.js.org/validation.html</a></p><h3>What’s next?</h3><p>Still, we are working on improving translation process and going to add new features to the library and tools.</p><ul><li>Simplify webpack integration.</li><li>Simplify translations setup.</li><li>Typescript.</li><li>More docs and examples.</li></ul><p>Current translation process requires quite a bit of boilerplate that we can reduce, and we are going to fix that. Any feedback will be appreciated, PR’s are welcome!</p><h3>More links</h3><ul><li>Docs and examples — <a href="https://c-3po.js.org/">https://c-3po.js.org/</a></li><li>c-3po library — <a href="https://github.com/c-3po-org/c-3po">https://github.com/c-3po-org/c-3po</a></li><li>babel-plugin-c-3po — <a href="https://github.com/c-3po-org/babel-plugin-c-3po">https://github.com/c-3po-org/babel-plugin-c-3po</a></li><li>c-3po-cli — <a href="https://github.com/c-3po-org/c-3po-cli">https://github.com/c-3po-org/c-3po-cli</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bb5b96a4e01" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/localization-in-javascript-with-c-3po-7bb5b96a4e01">Localization in javascript with c-3po</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit testing for async logic with Rxjs]]></title>
            <link>https://medium.com/@MostovenkoA/unit-testing-for-async-logic-with-rxjs-b1782dc65831?source=rss-fea251fc9ccb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1782dc65831</guid>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mostovenko Alexander]]></dc:creator>
            <pubDate>Sat, 21 May 2016 00:00:00 GMT</pubDate>
            <atom:updated>2016-06-18T13:48:34.030Z</atom:updated>
            <content:encoded><![CDATA[<p>There are a lot of approaches for writing async logic in javascript nowadays. This article does not aim to convince you that rxjs is the only right way, it will just show one of the features that it gives you almost for free. This feature is the possibility to mock time in your tests.</p><h3>Mock time? Something like having a time travel machine?</h3><p>Not actually, there is no special magic and this feature is available due to Schedulers (more about schedulers <a href="https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/schedulers.md">here</a>). Shortly speaking, it is an abstraction on top of coordinating and executing time dependent operations such as delay, throttle, debounce, timeout e.t.c</p><h3>Little example</h3><p>Let’s assume we have a stream of messages, and for some reason, we need to add delay logic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/035584735bb7d3d61c58b2fe47b2f30a/href">https://medium.com/media/035584735bb7d3d61c58b2fe47b2f30a/href</a></iframe><p>Rxjs allows you to test that delay logic with a simple unit test. And the pretty part is that you don’t need actually to wait for 100ms in test, you can just mock that thing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f2e9885ab8d76643e5895a346465cbb/href">https://medium.com/media/2f2e9885ab8d76643e5895a346465cbb/href</a></iframe><blockquote><em>Useful helper for asserting observables — </em><a href="https://github.com/AlexMost/chai-rx-assert"><em>chai-rx-assert</em></a></blockquote><p>If you will follow the comments above you will see how we are setting up incoming messages times and values and comparing them with output results. So, all our async logic is now pure and can be covered with unit tests. It acts like a state machine, so we can specify different sequences of inputs and compare with outputs in tests. Our <em>getDelayedMessages</em> function from example can be a function that returns our application state stream, and we can check how it changes depending on input messages, their order, and time when they occur.</p><p>Modern UI’s are tend to be expressed as a changing state container that is binded to view (see <a href="http://cycle.js.org/">Cycle.js</a>, <a href="https://github.com/reactjs/redux">Redux</a>, <a href="https://github.com/evancz/elm-architecture-tutorial">Elm-architecture</a>). All our application can be expressed as a stream of states. That’s why the possibility to have such tests is just awesome and seems like will have a great value for building reliable and robust asynchronous applications in future.</p><p><em>Originally published at </em><a href="http://www.mostovenko.com/posts/2016-05-21-testing-with-rxjs.html"><em>www.mostovenko.com</em></a><em> on May 21, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1782dc65831" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>