Search code examples
angularinternationalizationangular8language-translationangular-i18n

Angular 2+ i18n dialects/accents


Let's say we set up and use the Angular i18n-tags similar to the documentation:

<div i18n>Hello World</div>

We generate our translations using ng xi18n --i18nFormat=xlf

So far so good, now we want to start generating specific translations for dialects/accents, e.g. de_AT (austrian german). In our application there are very few of those. Therefor to keep the translation files maintainable, we don't want to generate a whole new .xlf for every dialect, but use a basic messages.de.xlf and somehow divert the accents/dialects from there.

First thought for a first step was to generate a new messages.de_AT.xlf containing only those specific translation, e.g:

<trans-unit id="5d9f8[...]f66d3e" datatype="html" approved="yes">
  <source>Hello World</source>
  <target state="translated">Griasdi Welt</target>
  <context-group purpose="location">
    <context context-type="sourcefile">src/app/hello-world.component.ts</context>
    <context context-type="linenumber">16</context>
  </context-group>
</trans-unit>

But no idea how to do that and what to do then. So I am looking for some best practice tricks or example projects. Thanks in advance!


Solution

  • Angular needs a complete translation file to build the project in a given language.

    What you could do is create a messages.de_AT.xlf.partial file with only AT specific translations, then find/create some tool to merge your base German translations messages.de.xlf with messages.de_AT.xlf.partial, resulting in a complete messages.de_AT.xlf.

    I had a quick look and could not find any ready tool to do the merge, but since xlf files are actually XML files, you could probably write your own script that does that.