Dutch locale not set.
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I'm trying to set the global locale to 'nl'. Every DayJS instance should have the Dutch locale, instead of the default 'en'. However, regardless of setting it, the default is still returning English:
```
el: M {
'$L': 'en',
'$u': undefined,
'$d': 2023-09-10T13:00:00.000Z,
'$x': {},
'$y': 2023,
'$M': 8,
'$D': 10,
'$W': 0,
'$H': 15,
'$m': 0,
'$s': 0,
'$ms': 0
}
```
**Expected behavior**
I expect $L to be 'nl', not 'en'.
**Information**
My package.json:
```
{
"name": "nuxt-app",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxtjs/tailwindcss": "^6.6.7",
"@types/node": "^18",
"@types/rss": "^0.0.30",
"@vite-pwa/nuxt": "0.0.7",
"nuxt": "^3.4.3",
"nuxt-icon": "^0.4.0",
"prisma": "^4.14.0"
},
"dependencies": {
"@nuxtjs/google-fonts": "^3.0.0",
"@pinia/nuxt": "^0.4.9",
"@prisma/client": "^5.0.0",
"@sendgrid/mail": "^7.7.0",
"@vuepic/vue-datepicker": "^6.0.2",
"crypto-js": "^4.1.1",
"dayjs": "^1.11.9",
"firebase": "^9.21.0",
"firebase-admin": "^11.8.0",
"ical-generator": "^5.0.0",
"nuxt-snackbar": "^1.0.3",
"pinia": "^2.0.35",
"rss": "^1.2.2",
"uuid": "^9.0.0",
"vite": "^4.3.5",
"vue-content-loading": "^1.6.0",
"vue-dragscroll": "^4.0.5",
"vuedraggable": "^4.1.0"
}
}
```
**My code:**
````
import dayjs from "dayjs";
import "dayjs/locale/nl";
dayjs.locale("nl");
export default defineEventHandler(async (event) => {
const body = await readBody(event);
let response = (async (result) => {
try {
const datum = "2023-09-10";
const tijd = "15:00";
const el = dayjs(`${datum} ${tijd}`).locale("nl");
console.log("el: ", el);
return {
body: JSON.stringify({
snackbar: {
type: "success", //success || error || warning || info
title: "Succes",
text: "De wijzigingen zijn opgeslagen.",
},
}),
};
} catch (error) {
console.log(error);
return {
body: JSON.stringify({
snackbar: {
type: "error", //success || error || warning || info
title: "---",
text: "De wijzigingen konden niet worden opgeslagen.",
},
}),
};
}
})();
return response;
});
Contributor guide
Research direction
Start by reproducing the reported behavior with the shown import, dayjs.locale("nl"), and locale("nl") calls inside the Nuxt event handler. Compare the resulting $L value with the expected "nl" value and determine whether the behavior is specific to this server-side setup. Done means the reported locale is applied consistently in the demonstrated case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nuxt
- Domain
- backend, internationalization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100