<?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 Sampo Kuokkanen on Medium]]></title>
        <description><![CDATA[Stories by Sampo Kuokkanen on Medium]]></description>
        <link>https://medium.com/@sampokuokkanen?source=rss-843a1cf383ef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*p_BSrmkidU0H7aDQ.</url>
            <title>Stories by Sampo Kuokkanen on Medium</title>
            <link>https://medium.com/@sampokuokkanen?source=rss-843a1cf383ef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:26:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sampokuokkanen/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[Add a translation feature to the String class in Ruby]]></title>
            <link>https://sampokuokkanen.medium.com/add-a-translation-feature-to-the-string-class-in-ruby-80ab5be4cbd5?source=rss-843a1cf383ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ab5be4cbd5</guid>
            <category><![CDATA[deepl]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Sampo Kuokkanen]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 08:41:28 GMT</pubDate>
            <atom:updated>2021-06-06T08:41:28.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*fZ3YX-XUAk4S05KR0hnuew.gif" /><figcaption>Using TranslateSelf with Rails using ActiveTranslateSelf</figcaption></figure><p>I want to translate strings without having to leave irb!</p><p>With the above in mind, I searched for a solution. In the end, I decided to add a translation function to the String class itself. This was coded purely for fun.</p><p>In terms of code, I could have gone with the following:</p><p><a href="https://gist.github.com/4a0681ed41b3034f88f34359aa8cc5f9">https://gist.github.com/4a0681ed41b3034f88f34359aa8cc5f9</a></p><p>First, open the class `String. After that include this weird translation class in it. And now the strings know how to translate themselves!</p><p>Now you can do something like this:</p><p>Now translating is easy! Get the API key for DeepL and run</p><p><a href="https://gist.github.com/1f22befb4aa6d0c0869a598338721eea">https://gist.github.com/1f22befb4aa6d0c0869a598338721eea</a></p><p>With just the above operations, the translation can be done by String itself.</p><p>This was a great chance to get to use define_method, so you can use translate_to_#{language} method call for all supported languages. The source code looks like this:</p><p><a href="https://gist.github.com/59eb0408287fb0fb689ebaefb6d4df94">https://gist.github.com/59eb0408287fb0fb689ebaefb6d4df94</a></p><p>It feels good to think that you could define 25 methods with just the above.</p><h3>Benchmark</h3><p>Maybe the performance isn’t so bad after all?</p><p><a href="https://gist.github.com/f9acf1cc212b3f1b0637cedce91a7a60">https://gist.github.com/f9acf1cc212b3f1b0637cedce91a7a60</a></p><p>The source can be found at the following link:</p><p><a href="https://github.com/sampokuokkanen/translate_self">https://github.com/sampokuokkanen/translate_self</a></p><p><em>Originally published at </em><a href="https://gist.github.com/4aa80563a1c535b44a8c6bb85e040a30"><em>http://github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ab5be4cbd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>