Angular translation and date formatting: how to translate the name of the month?

In my application I use angular-translate

https://github.com/angular-translate/angular-translate

to translate my content.

And also, in my opinion, I have this date format:

 {{article.CreatedAt | date:'dd MMM yyyy':'UTC'}} 

but when I install polish, Russian (or any other language, not English) - the names of my months are still in English.

How can I translate them (it would be great if this is impossible without impulses and other plugins ...)?

+6
source share
2 answers

To change the dynamic language of the application, you need angular-dynamic-locale , and you also need other locale files (English comes with angular) from ngLocale .

This is where plunker works.

You need to catch the broadcast of events, because we want to change the language standard when changing the language. Therefore, for this purpose, I used the $translateChangeSuccess event to set the selected language as the new locale.

 $rootScope.$on('$translateChangeSuccess', function (event, data) { tmhDynamicLocale.set(data.language); }); 

Here is a list of all $ translate events .

+4
source

You do not need an external library, in angular, the date and number format is converted using angular -i18n: https://docs.angularjs.org/guide/i18n

For example, to get the date in Russian, simply include the locale file after angular:

 <script src="angular.js"></script> <script src="angular-locale_ru-ru.js"></script> 

Of course, this will not be dynamic, you can manage it on the server side or find another trick.

to get it from the gazebo use

 $ bower install angular-i18n 

see Where are the AngularJS I18n Files?

+1
source

All Articles