AngularJS translate: Format dynamic dates -


using angularjs , angular-translate trying insert date parameter in translated text.

the basic task documented translate package:

<p>{{ 'mytext' | translate:{mydate:somecontrollerdate} }}</p> 

with in localized json-file:

(english)'mytext': 'this date: {{mydate}}.' (danish) 'mytext': 'dette {{mydate}} er datoen.' 

this gives me:

(english) date: 2015-04-29t00:00:00.

(danish) dette 2015-04-29t00:00:00 er datoen.

the problem: format date match language (or culture, language enough).

the desired result is:

(english) date: 04-29-2015.

(danish) dette 29-04-2015 er datoen.

i hoping syntax along these lines:

(english)'mytext': 'this date: {{mydate:mm-dd-yyyy}}.' (danish) 'mytext': dette {{mydate:dd-mm-yyyy}} er datoen.' 

or perhaps:

<p>{{ 'mytext' | translate:{{mydate:somecontrollerdate | translate:'mydateformat'}} }}</p> 

with

(english)'mydateformat': 'mm-dd-yyyy' (danish) 'mydateformat': 'dd-mm-yyyy' 

is there way achieve desired result, preferably without having format date inside controller (keeping logic , view separated)?

assuming have following angular-translate translations definitions:

//de     "with_date": "german: {{date|date:'short'}}"  //en     "with_date": "english: {{date|date:'medium'}}" 

then inside view can do:

<h1>{{ 'with_date'|translate:{date:today} }}</h1> 

where today defined in controller i.e.:

$scope.today = new date(); 

assuming you've loaded angular-locale_* correct locale dates formatted in language/country specific way.

here's demo.

having said localization mechanism built angular (nglocale) limited , when comes dates can accomplish wonders moment.js


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -