How do you change language for DatePick in DateInlineRow? I want the pop out DatePick to use native language instead of English.
You can access the datePicker using row.inlineRow?.cell.datePicker.
Then you should be able to customise the picker. I would do it in cellSetup
my code:
<<
$0.value = NSDate()
}.cellSetup{ (cell, row) in
row.inlineRow?.cell.datePicker.locale = NSLocale(localeIdentifier: "jp_JP")
}
It doesn't work.
DateRow has the same problem... My app is using de_DE locale as default and date picker has english translations of months but 'Done' button is translated correctly.
The problem with Eureka framework localization is when an application have another locale then system, for example in my application I have only German (de_DE) locale and I want use just right this one. I have seen that DateFieldRow sets .currentLocale() for UI components, what is wrong in my opinion because I have German navigation buttons etc... but in date picker I have system locale. I think it should be used for example NSLocale.applicationLocale() extension instead of .currentLocale(), like below:
extension NSLocale {
class func applicationLocale() -> NSLocale {
guard let localeIdentifier = NSBundle.mainBundle().preferredLocalizations.first else {
fatalError("Application Locale Error!")
}
let locale = NSLocale(localeIdentifier: localeIdentifier)
return locale
}
}
I'm not sure if it is the best way of resolving problem, but it works. Create an extension below:
extension NSLocale {
class func applicationLocale() -> NSLocale {
guard let localeIdentifier = NSBundle.mainBundle().preferredLocalizations.first else {
return .currentLocale()
}
let locale = NSLocale(localeIdentifier: localeIdentifier)
return locale
}
private static var swizzledLocale = NSLocale.currentLocale()
class func swizzledCurrentLocale() -> NSLocale {
return swizzledLocale
}
private static var token: dispatch_once_t = 0
class func setCurrentLocale(locale: NSLocale) {
swizzledLocale = locale
dispatch_once(&token) {
let originalSelector = #selector(NSLocale.currentLocale)
let swizzledSelector = #selector(NSLocale.swizzledCurrentLocale)
if let klass: AnyClass = object_getClass(self) {
let originalMethod = class_getClassMethod(klass, originalSelector)
let swizzledMethod = class_getClassMethod(klass, swizzledSelector)
let didAddMethod = class_addMethod(klass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
if didAddMethod {
class_replaceMethod(klass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
}
else {
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
}
}
}
and than, in your AppDelegate (or another place you want) add:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
NSLocale.setCurrentLocale(NSLocale.applicationLocale())
return true
}
Very Easy
DateInlineRow.InlineRow.defaultCellSetup = { cell,row in
cell.datePicker.locale = NSLocale(localeIdentifier: "jp_JP")
}
No need to write whole bunch of code :)
Most helpful comment
Very Easy
No need to write whole bunch of code :)