Locale with moment
Hey!
Thanks for a great directive! Trying to get locale working here. After going through the docs, it seems that moment.js loads the English locale by default. I have moment.js included in my app, but the date formats that got output are still YYYY-MM-DD. Assuming that these are not the default English locales, how can I get this to work?
Thanks!
Hi,
How are you using pikaday-angular ? Bower? Browserify?
You can set locale by including the appropriate locale script globally. In plain html:
<script src="angular.js"></script>
<script src="moment.js"></script>
<script src="moment/locale/de.js"></script>
<script src="pikaday-angular.js"></script>
Using something like browserify:
// main.js
require('angular');
var moment = require('moment');
require('moment/locale/de');
require('pikaday-angular');
There's currently an issue upstream with Pikaday, in that it has moment as a dependency in it's package.json file. You need to delete the moment folder from node_modules for the global moment to be used properly. see https://github.com/dbushell/Pikaday/issues/299
Hey nverba! Thanks for the quick reaction! I used pikaday-angular through Bower and then include the js-files through Gulp. I have moment included from bower_components/moment/min/moment-with-locales.js. I am assuming that this workflow does not include the Pikaday moment dependency.
I first tried with only moment (as the docs there state that English is the default) and then also tried with the en-gb locale. Both still have the YYYY-MM-DD config on my side.
Using format obviously works, but that's not using the locale then...
if you use format="MMMM Do YYYY", does the month text show in the appropriate locale language?
Yup, confirmed. Had to call moment.locale('de') in order to test and add a full month format, but then it seems to work. 2 thoughts:
- Might be that moment.js is not picking up the default language because I include it through gulp in a minified js file? If I do not call it explicitely, I got funky 五月 30日 2015
- Not sure what the behaviour should be, but my expectation was that format is part of internationalization? So basically it should take care of showing dd/mm/yy or mm.dd.yy or whatever is used by default in a specific region?