dillidon / alerts-and-pickers

Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
MIT License
5.65k stars 700 forks source link

Support for L10n #117

Open geclick opened 2 years ago

geclick commented 2 years ago

I needed to change de default locale to spanish in a DatePicker and I found no way to do this using alert.addDatePicker. I thought changing the device language it will work, but at least in simulator it didn't work. I didn't install the library with Cocoapods, so I added a modification to DatePickerViewController init

`required public init(mode: UIDatePicker.Mode, date: Date? = nil, minimumDate: Date? = nil, maximumDate: Date? = nil, action: Action?) { super.init(nibName: nil, bundle: nil) datePicker.datePickerMode = mode

    //changing to spanish only for date selection
   //so September 13, 2021 becomes 13 Septiembre 2021 
    if mode == .date{
        datePicker.locale = Locale(identifier: "es_ES")
    }

    datePicker.date = date ?? Date()
    datePicker.minimumDate = minimumDate
    datePicker.maximumDate = maximumDate
    self.action = action
}`

It would be nice if there were an option to set the locale of the picker