sidekickr
sidekickr

Reputation: 382

DateComponentFormatter Translation

When using a DateComponentFormatter like this

let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full
formatter.includesApproximationPhrase = false
formatter.includesTimeRemainingPhrase = false
formatter.allowedUnits = [.hour]

var components = DateComponents()
components.hour = 4

let outputString = formatter.string(from: components)

The output is '4 hours' when my language/region is English/US. When changing the language/region to French/France I had expected the output to be '4 heures`, but it still comes out as '4 hours'. Any suggestions on how to get the DateComponentFormatter to do translations?

Changing the language/region on the phone seems to have no effect.

Upvotes: 0

Views: 183

Answers (2)

sidekickr
sidekickr

Reputation: 382

Per above, the underlying reason is that Apple changed the behavior of the formatters in iOS11 and I hadn't caught that. This question was answered by NSDateFormatter and current language in iOS11

Upvotes: 0

Pavan Gudur
Pavan Gudur

Reputation: 37

May be, Your app is not localized to other languages. I followed https://www.raywenderlich.com/250-internationalizing-your-ios-app-getting-started for adding localization in my app.

Upvotes: 0

Related Questions