Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the localized version of the months from angularjs?

How would I get a localized version of every month in angularjs in an array? I know how to localize a single date using the format options, but in this case I want all of the months. Basically, this is going to be bound to a select that the user can than choose a month.

like image 814
Jace Rhea Avatar asked Dec 08 '22 12:12

Jace Rhea


1 Answers

I m guessing that your page will be entirely localized in a given language and that you will add the proper angular-locale file as such :

<script src="http://.../angular-locale_xx-xx.js"></script> // ex: angular-locale_fr-fr.js

If this is the case you can simply access all the months as an array like that :

function Controller($scope, $locale) { //inject the $locale service
  var datetime = $locale.DATETIME_FORMATS; //get date and time formats 
  $scope.months = datetime.MONTH; //access localized months
}

You can see a working plunker here

like image 61
Nicolas ABRIC Avatar answered Feb 23 '23 13:02

Nicolas ABRIC