Search code examples
angularinternationalizationlocaleangular8

Change default Locale in angular


I built an angular app in french, so now i want to use internationalization (i18n) to provide it in other languages like En, so the problem is the default locale for Angular is en-US and when i write this <span i18n>Mes endroits</span>,I have this

<file source-language= "en-US" datatype="plaintext" original="ng2.template">// source is English
    <body>
      <trans-unit id="4df6e2173dc9d9f8c60481273cf3371981e60fde" datatype="html">
        <source>Mes endroits</source> ... // but this is in french

and i want the source language to be fr and provide for example messages.en.xlf

so can I change the default locale to fr , or I have to rewrite my code in English and provide messages.fr.xlf


Solution

  • This could help you ngx-translate/ng2-translate, this library is very common in angular projects.

    Personaly I prefer to do translation this way.

    You will be able to use the translate pipe. like this

    <p>{{ 'myPlaces' | translate }}</p>
    

    And in a fr.json define :

    { 'myPlaces' : 'Mes endroits' }
    

    I let you check the documentation