<?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 Tsvetomir Tsonev on Medium]]></title>
        <description><![CDATA[Stories by Tsvetomir Tsonev on Medium]]></description>
        <link>https://medium.com/@t_tsonev?source=rss-fdc000f664c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Q0SpuFU9tKLgDg5m.png</url>
            <title>Stories by Tsvetomir Tsonev on Medium</title>
            <link>https://medium.com/@t_tsonev?source=rss-fdc000f664c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:08:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@t_tsonev/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[Making Sense of Angular Internationalization (i18n)]]></title>
            <link>https://medium.com/@t_tsonev/making-sense-of-angular-internationalization-i18n-e7b26fb9c587?source=rss-fdc000f664c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7b26fb9c587</guid>
            <category><![CDATA[i18n]]></category>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Tsvetomir Tsonev]]></dc:creator>
            <pubDate>Mon, 10 Apr 2017 18:59:38 GMT</pubDate>
            <atom:updated>2017-04-10T18:59:38.158Z</atom:updated>
            <content:encoded><![CDATA[<p>The Angular approach to i18n is surprisingly complex. Don’t take my word for it, go ahead and read the <a href="https://angular.io/docs/ts/latest/cookbook/i18n.html">cookbook</a>.</p><p>To recap it for you:</p><ul><li>Messages are stored in XML files, of all things</li><li>Modifying the application invalidates existing message files</li><li>Translations are baked into the application during compilation</li></ul><p>At this point I can make an educated guess that it isn’t going to sail everyones boat. Luckily, run-time solutions such as <a href="https://github.com/ngx-translate/core">@ngx-translate</a> can do the job as good as ever.</p><p>Still, the framework solution has its upsides:</p><ul><li>There’s no runtime overhead, regardless of the size of your application</li><li>The XLIFF and XMB file formats are widely recognized in the translator community</li><li>Tooling support is supposedly good. This includes GUI editors and servers for sharing translations</li></ul><p>This will all start to make sense as the applications grows in scale. But before that we need to figure out how to start using the framework on the small scale. We want the banana, but not the Gorilla and the jungle.</p><h3>Small-scale Localization</h3><p>Let’s start with what we have. Angular asks from us to extract strings from the application using <a href="https://angular.io/docs/ts/latest/cookbook/i18n.html#!#ng-xi18n">ng-xi18n</a> <em>every time the application changes</em>. We then have to <a href="https://angular.io/docs/ts/latest/cookbook/i18n.html#!#maintenance">figure out what changed</a> and update all our existing translations.</p><p>What we need is a single source of truth to rely on. Something that won’t be overwritten accidentally by a build script.</p><p>This reference storage for the messages can be something as simple as a YAML file, indexed by message key. At this point, you’re thinking…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*9nMBMt-OugnruBr_M-WuEQ.png" /></figure><p>Well, it turns out there’s already a <a href="https://github.com/translate/translate/blob/e1487c4e33ed4a244f89e25c54ab11228fca6e56/docs/formats/yaml.rst">14th standard</a> that is supported by the swiss-army knife <a href="https://github.com/translate/translate">Translate Toolkit</a>. Hey, don’t blame it on me!</p><p>The suggested workflow is:</p><ul><li>Assign translations an unique, hierarchical key</li><li>Use the <em>meaning</em> field to “smuggle” our key in the message file</li></ul><pre>&lt;span i18n=&quot;<strong>profile.greeting</strong>|Greeting for the user in the Profile page&quot;&gt;Hello, dear user!&lt;/span&gt;</pre><ul><li>Write down translations in a human-writable YAML file.</li></ul><pre><strong>profile</strong>:<br>  # Greeting for the user in the Profile page<br>  <strong>greeting</strong>: Hello, dear user!</pre><ul><li>Automatically fill message files, using the YAML files</li></ul><h3>Tooling</h3><p>The first problem is seeding the YAML files with default translations. The <a href="https://www.npmjs.com/package/xlf-extract">xlf-extract</a> tool can save us a few keystrokes. Given an XLIFF message file, it will populate an YAML file with the messages and their default values.</p><pre>xlf-extract --lang-file lang/en.yml messages.xlf</pre><p>The second problem is getting the translations back in the newly generated XLIFF file. The <a href="https://www.npmjs.com/package/xlf-translate">xlf-translate</a> tool takes an YAML file and translate any matching messages in a given XLIFF file.</p><pre>xlf-translate --lang-file lang/fr.yml messages.fr.xlf</pre><p>The tool will not overwrite existing translations unless you use the “force” flag. This makes it safe to run xlf-translate on the same XLIFF file multiple times and to modify translations manually.</p><h3>Building and Deploying</h3><p>We have our message files all lined up. So far, so good. But we now need to build the application(s) out of them.</p><p>Check out the <a href="https://medium.com/@feloy/deploying-an-i18n-angular-app-with-angular-cli-fc788f17e358">excellent post</a> by Philippe Martin for a primer on how to do that. I’ve <a href="https://github.com/tsvetomir/angular-cli-i18n-sample">forked</a> his sample application to include the tools outlined above.</p><p>Does all of this make sense? Let me know what you think in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7b26fb9c587" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>