<?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 Cristian Bote on Medium]]></title>
        <description><![CDATA[Stories by Cristian Bote on Medium]]></description>
        <link>https://medium.com/@cristianbote?source=rss-60fab58aeec2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Zj4Al9hJ_zoggrey3LH8Kw.jpeg</url>
            <title>Stories by Cristian Bote on Medium</title>
            <link>https://medium.com/@cristianbote?source=rss-60fab58aeec2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:49:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cristianbote/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[Let react speak your language]]></title>
            <link>https://medium.com/@cristianbote/let-react-speak-your-language-3ea1508efe20?source=rss-60fab58aeec2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ea1508efe20</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[translate]]></category>
            <dc:creator><![CDATA[Cristian Bote]]></dc:creator>
            <pubDate>Tue, 28 Nov 2017 21:29:07 GMT</pubDate>
            <atom:updated>2017-11-28T21:33:51.532Z</atom:updated>
            <content:encoded><![CDATA[<p>Making your website speak to your users, in their language is no easy task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZ_FBBzP9xsr8HB3vVxBLg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/BVyNlchWqzs?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Amador Loureiro</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Some do underestimate it, even though there’s not much to be done there: grab the user locale/preferred language, fetch the file with your translation and do the parsing and setting.<br>It sounds straight forward and it is. In today’s world of view libraries, full blown frameworks, a handy tool to help out it’s something that really boost up your experience.</p><p><a href="https://github.com/cristianbote/react-translate-json">https://github.com/cristianbote/react-translate-json</a></p><h3>‘This site needs to be translated’</h3><p>My first encounter with ‘this site needs to be translated’ requirement, was back, a few years ago, when working on an AngularJS website. I stumbled upon Pascal’s angular-translate package, during my googling and it was an eye opener: simple, straight API and really well documented.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d5e694745e8b3cba5cbed5ca62e2b47/href">https://medium.com/media/8d5e694745e8b3cba5cbed5ca62e2b47/href</a></iframe><p>You could not ask for more than this. You got your keys, you got your locale set and you can straight forward use it via pipes or simple directives.</p><h3><strong>My version</strong></h3><p>Using it in AngularJS was fine, because there wasn’t anything that I found more useful than what it offered, but moving away from AngularJS left a gap in my day-to-day translation needs. Therefore, I tried to recreate it, whenever I needed this paradigm; hence in react.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5d7e8386c44e5f6bf4ff93265fc1637/href">https://medium.com/media/c5d7e8386c44e5f6bf4ff93265fc1637/href</a></iframe><p>So let’s talk a bit about what really happens here.</p><p>First, import the needed function and component. Call the setConfig with the pathPrefix to your folder with translations. By default, this is looking for .json files, but you could specify the extension if this is not a JSON. Let’s say you’re serving all your static resources from a CDN, then you could easily have this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51fa05f8b3c32a9cdc95e4e822d4b946/href">https://medium.com/media/51fa05f8b3c32a9cdc95e4e822d4b946/href</a></iframe><p>Anything goes here, really, as long as the browser can request it.</p><p>Secondly, you need to use the &lt;TranslateComponent /&gt; to actually grab the value. This is a proxy component, which does not have any footprint on the DOM, and can be used either via the render prop or just simply let it render the text inside a span.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c25d3ca5c3a67ac4f989dd7d5ba79c7c/href">https://medium.com/media/c25d3ca5c3a67ac4f989dd7d5ba79c7c/href</a></iframe><h3><strong>Okay, but I need the values to be parametrized</strong></h3><p>I totally understand. Who has static translations? Nobody, that’s who. Just like Pascal’s, you can use handlebars, {{myProp}}, inside your values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ea9a2f9f32a1c15602ca9079bbe28e2/href">https://medium.com/media/0ea9a2f9f32a1c15602ca9079bbe28e2/href</a></iframe><p>Any questions?</p><h3>Advanced usages</h3><p>Ok, so you might have some setup, where let’s say, your translations are dynamically generated via a more complex call. It could happen. As long as the output is a object, which has keys and values, you’re fine. You could do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/594a9772044e180ce4f4be48972851e1/href">https://medium.com/media/594a9772044e180ce4f4be48972851e1/href</a></iframe><p>Basically, you do not need any locale notation, or static files. The setConfig method, all it does, it makes sure there’s a call-able endpoint that can/should return some JSON.</p><p>Another usage, you might find it useful, is via the `translate` method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7498fc2cbc61a69cacd9db05abf1cd0a/href">https://medium.com/media/7498fc2cbc61a69cacd9db05abf1cd0a/href</a></iframe><h3>Ending</h3><p>Bottom line is that this package is for react, but could be used in any other framework or context.</p><p>So, hopefully, this caught your attention and you’re giving it a chance. You can find the code up on github, npm and yarn. If you have any improvements, I’m more than happy to see them coming.</p><p><a href="https://github.com/cristianbote/react-translate-json">https://github.com/cristianbote/react-translate-json</a></p><p>Let me know what you think and give it a clap, is it?</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ea1508efe20" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>