Search code examples
angularjsangular-moment

Translations for AngularJS module angularMoment


I use angularMoment module in my app to display post creation time like few seconds ago, 2 hours ago and so on. The problem is that my app supports multiple languages. How do I make translations for it?

I used this tutorial to implement angularMoment https://scotch.io/tutorials/display-time-relatively-in-angular


Solution

  • As stated in angularMoment documentation you can do:

    If you need internationalization support, load specified moment.js locale file first:

    <script src="components/moment/locale/de.js"></script> Then call the amMoment.changeLocale() method (e.g. inside your app's run() callback):

    The changeLocale function changes the local for moment.js and updates all the am-time-ago directive instances. This function accepts two arguments locale and an object with overrides. The locale is a string of the Locale code eg. en, es, ru etc.