Localization : feature?
See original GitHub issueDescription of the Issue and Steps to Reproduce:
Did you search for duplicate issue? [Yes / No]
Please describe the issue and steps to reproduce, preferably with a code sample / plunker: I guess this is more of a question than an issue, but I haven’t found any info on this anywhere. Terribly sorry if this is the wrong place to post. But here goes:
Is there any way to localize the output of moment using this module? I know moment has the .locale() function, but I haven’t gotten that to work, and I can’t see any functions in this library where I could set the locale either. My goal is to allow for swedish translations as well as english, but I’ve had no luck. Any help would be very much appreciated.
Thank you
Ensure your issue is isolated to angular2-moment. Issues involving third party tools will be closed unless submitted by the tool’s author/maintainer.
Environment:
Please answer the following questions:
- Angular version? final ^2.0.0
- TypeScript version? ^2.0.3
moment
version? ^2.15.2- Are you using
moment-timezone
? no - Are you using the angular-cli? Not sure? Probably
- Using Rollup/Webpack/System.js/Ionic/similar? Ionic 2, with rollup.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11
Top GitHub Comments
For someone trying to use locales in ionic 2 app, I just included lang module as instructed by @Alx101 in app.module.ts after including angular2-moment like this and that automatically pulled spanish language
dp
I solved this now by using the moment package directly and setting locale there. I will post a snippet in case anyone else needs it. But it would still be nice to have locales included in this module and functions for switching them. All credit goes to the user reedrichards over at the ionic forums (github is @peterpeterparker, again thank you) , who posted this excellent solution:
sudo npm install moment --save
sudo npm install --save-dev @types/moment
import moment from 'moment';
moment().locale('sv');
4.a Remember to import the locale as described in the P.S
import 'moment/src/locale/sv';
moment(new Date()).format('LLL');
moment(new Date()).add(5, 'd').toDate()
P.S.: If the locales doesn’t work, you may need to include explicitly the locales you want to use. For me it’s the case. It works when I debug but when I test on my real phone it doesn’t work (just tested right now). Therefore import it like following (I’m not sure if its needed or not…):
import 'moment/src/locale/sv';