0

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.

sidekickr
  • 384
  • 3
  • 8
  • 1
    Does your app include French localizations? If not then probably a duplicate of https://stackoverflow.com/questions/46205763/nsdateformatter-and-current-language-in-ios11 – rmaddy Nov 04 '19 at 19:10
  • yeah, this is a duplicate of that. I hadn't realized that the date component formatters would only do languages you selected. It works differently than region formatting which works regardless of the apps localizations. – sidekickr Nov 04 '19 at 19:46

2 Answers2

0

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.

0

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

sidekickr
  • 384
  • 3
  • 8