Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Locale with moment #10

Open
philippeluickx opened this issue May 21, 2015 · 4 comments
Open

Locale with moment #10

philippeluickx opened this issue May 21, 2015 · 4 comments

Comments

@philippeluickx
Copy link

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!

@nverba
Copy link
Owner

nverba commented May 21, 2015

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 Pikaday/Pikaday#299

@philippeluickx
Copy link
Author

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...

@nverba
Copy link
Owner

nverba commented May 30, 2015

if you use format="MMMM Do YYYY", does the month text show in the appropriate locale language?

@philippeluickx
Copy link
Author

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:

  1. 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
  2. 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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants