'SwiftUI Datepicker displaying language in English Only?

I am Japanese

I want to change the date selection language of the calendar to Japanese using DatePicker. I read the Document, but there was no such setting, so if you know anyone, I would like to know.

For example, in the image example, I want to convert February to Japanese.

DatePicker Image



Solution 1:[1]

.environment(\.locale, #YourLocale#)

You can use this method.

Solution 2:[2]

you can do this pt is for Portuguese:

DatePicker("Please enter date",selection: $wakeUp, in: Date()...)
            .labelsHidden()
            .environment(\.locale, Locale.init(identifier: "pt"))

Solution 3:[3]

struct DatePicker2: UIViewRepresentable {
    @Binding var date: Date

    private let datePicker = UIDatePicker()

    func makeUIView(context: Context) -> UIDatePicker {
//        datePicker.datePickerMode = .date
        let loc = Locale(identifier: "ja_JP")
        datePicker.locale = loc
        datePicker.addTarget(context.coordinator, action: #selector(Coordinator.changed(_:)), for: .valueChanged)
        return datePicker
    }

    func updateUIView(_ uiView: UIDatePicker, context: Context) {
        datePicker.date = date
    }

    func makeCoordinator() -> DatePicker2.Coordinator {
        Coordinator(date: $date)
    }

    class Coordinator: NSObject {
        private let date: Binding<Date>

        init(date: Binding<Date>) {
            self.date = date
        }

        @objc func changed(_ sender: UIDatePicker) {
            self.date.wrappedValue = sender.date
        }
    }
}

I modified this code from here :

SwiftUI: how to create custom UIDatePicker

Greetings from Uruguay!

Solution 4:[4]

Date Picker locale all language:

DatePicker("", selection: $selectedTime, in: Date()..., displayedComponents: [.date,.hourAndMinute]).environment(\.locale, Locale.init(identifier: String(Locale.preferredLanguages[0].prefix(2))))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Victor Zerefos
Solution 3 gexhange
Solution 4 Selçuk Aslanta?