How do I change the language of moment.js?

前端 未结 20 1547
别那么骄傲
别那么骄傲 2020-11-29 16:27

I am trying to change the language of the date which is being set by moment.js. The default one is English, but I want to set the German language. These is what I tried:

20条回答
  •  广开言路
    2020-11-29 17:02

    As I was using webpack with gulp and friends (this generator set up everything for me) I had to make a change to the bower.json file. I had to override the default import for the moment package and select the file that comes with all the languages:

    "overrides": {
      "moment": {
        "main": [
            "min/moment-with-locales.min.js"
        ]
      }
    }
    

    This is my full bower.json file:

    {
      "name": "html5",
      "version": "0.0.0",
      "dependencies": {
        "angular-animate": "~1.4.2",
        "angular-cookies": "~1.4.2",
        "angular-touch": "~1.4.2",
        "angular-sanitize": "~1.4.2",
        "angular-messages": "~1.4.2",
        "angular-ui-router": "~0.2.15",
        "bootstrap-sass": "~3.3.5",
        "angular-bootstrap": "~0.13.4",
        "malarkey": "yuanqing/malarkey#~1.3.1",
        "angular-toastr": "~1.5.0",
        "moment": "~2.10.6",
        "animate.css": "~3.4.0",
        "angular": "~1.4.2",
        "lodash": "^4.13.1",
        "angular-moment": "^0.10.3",
        "angularLocalStorage": "ngStorage#^0.3.2",
        "ngstorage": "^0.3.10"
      },
      "devDependencies": {
        "angular-mocks": "~1.4.2"
      },
      "overrides": {
        "bootstrap-sass": {
          "main": [
            "assets/stylesheets/_bootstrap.scss",
            "assets/fonts/bootstrap/glyphicons-halflings-regular.eot",
            "assets/fonts/bootstrap/glyphicons-halflings-regular.svg",
            "assets/fonts/bootstrap/glyphicons-halflings-regular.ttf",
            "assets/fonts/bootstrap/glyphicons-halflings-regular.woff",
            "assets/fonts/bootstrap/glyphicons-halflings-regular.woff2"
          ]
        },
        "moment": {
          "main": [
              "min/moment-with-locales.min.js"
          ]
        }
      },
      "resolutions": {
        "angular": "~1.4.2"
      }
    }
    

提交回复
热议问题