Is there a way to change the MUI DatePicker language to Japanese?
When I wrote a code similar to the one below, I got the error TypeError: Cannot read properties of undefined (reading 'date')
in my browser.
Delete locale="ja"
to display DatePicker but in English.
/*eslint-disable react/react-in-jsx-scope -- Unaware of jsxImportSource*/
/** @jsxImportSource @emotion/react*/
import {memo, VFC, useState} from "react";
import LocalizationProvider from "@mui/lab/LocalizationProvider";
import DatePicker from "@mui/lab/DatePicker";
import AdapterDateFns from "@mui/lab/AdapterDateFns";
import TextField from "@mui/material/TextField";
export const TestPicker: VFC=memo()=>{
const [value, setValue] = useState<Date|null>(null);
return(
<LocalizationProvider dateAdapter={AdapterDateFns} locale="ja">
<DatePicker
value = {value}
onChange={(newValue)=>{
setValue(newValue);
}}
renderInput={(params)=><TextField{...params}/>}
/>
</LocalizationProvider>
);
});
The versions of each package are as follows:
----@emotion/[email protected]
├-- @emotion/[email protected]
├-- @mui/icons-material @5.0.1
├-- @mui/lab @5.0.0 - alpha.48
├-- @mui/material @5.0.1
├-- @types/[email protected]
├-- @types/react-dom @17.0.9
├-- @types/[email protected]
├-- [email protected]
├-- [email protected]
├-- [email protected]
├-- [email protected]
├-- [email protected]
・
・
・
If you use date-fns locale, it will be in Japanese.
import ja from "date-fns/locale/ja";
<LocalizationProvider dateAdapter={AdapterDateFns} locale={ja}>
© 2024 OneMinuteCode. All rights reserved.