I'm running a node-app, this is all I have in app.js:
var moment = require('moment');
moment().locale('fr');
console.log(moment.locale())
I expect this to output 'fr' but it outputs 'en' instead, when I
runjs app.js
There is a fr-folder in node_modules/moment/locale.
Here are my packages:
{
"name": "zenqa",
"version": "1.0.0",
"description": "Faq for Zenconomy.se",
"main": "index.js",
"dependencies": {
"body-parser": "^1.14.2",
"concat-files": "^0.1.0",
"express": "^4.13.3",
"marked": "^0.3.5",
"moment": "^2.11.2",
"mustache-express": "^1.2.2",
"node-sass-middleware": "^0.9.7",
"php-unserialize": "0.0.1",
"requestify": "^0.1.17",
"validator": "^4.8.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Kristoffer Nolgren",
"license": "ISC",
"repository": {
"type": "git",
"url": "[email protected]:kristoffernolgren/ZenqaMiddleware.git"
}
}
I'm running a node-app, this is all I have in app.js:
var moment = require('moment');
moment().locale('fr');
console.log(moment.locale())
I expect this to output 'fr' but it outputs 'en' instead, when I
runjs app.js
There is a fr-folder in node_modules/moment/locale.
Here are my packages:
{
"name": "zenqa",
"version": "1.0.0",
"description": "Faq for Zenconomy.se",
"main": "index.js",
"dependencies": {
"body-parser": "^1.14.2",
"concat-files": "^0.1.0",
"express": "^4.13.3",
"marked": "^0.3.5",
"moment": "^2.11.2",
"mustache-express": "^1.2.2",
"node-sass-middleware": "^0.9.7",
"php-unserialize": "0.0.1",
"requestify": "^0.1.17",
"validator": "^4.8.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Kristoffer Nolgren",
"license": "ISC",
"repository": {
"type": "git",
"url": "[email protected]:kristoffernolgren/ZenqaMiddleware.git"
}
}
Share
Improve this question
edited Feb 19, 2016 at 19:42
baao
73.3k18 gold badges150 silver badges207 bronze badges
asked Feb 19, 2016 at 19:37
HimmatorsHimmators
15k39 gold badges136 silver badges231 bronze badges
6 Answers
Reset to default 10Spent hours on this just to realise I had to import the locale from /dist
dir instead. Maybe it's just caused by my setup but might help someone
import moment from 'moment';
import 'moment/dist/locale/fr';
moment.locale('fr');
Test
import fr1 from 'moment/dist/locale/fr';
import fr2 from 'moment/locale/fr';
console.log(fr1); // Locale {_calendar: {…}, ... }
console.log(fr2); // {}
According to the documentation there is a bug that prevents moment.locale from being loaded. So you can use the following code.
var moment = require('moment');
require('moment/locale/fr');
console.log(moment.locale());
You can use:
import moment from "moment";
import "moment/locale/es";
According to the current documentation it is possible:
var moment = require('moment');
moment.locale('fr');
console.log(moment().format());
For node you can use:
moment.updateLocale('es');
I have tested it.
Current document is not correct. In Node.JS you still use this code:
moment.lang('fr');