You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You might at a glance expect the date to be formatted using en_US formatting rules, but it is not. This is because date.formatted(date: .numeric, time: .omitted) is resolving a String using Locale.current prior to passing it into the LocalizedStringResource.
Without using XCStrings Tool, if we wanted to format this using the resource (or SwiftUI environment) locale, we'd have to do the following:
varresource:LocalizedStringResource="Today's date is \(date, format:.dateTime)"
resource.locale =Locale(identifier:"en_US")
\(date, format: .dateTime) is subtly different to date.formatted(.dateTime) because it uses a custom interpolation method:
It will hold the original value inside the resource alongside the FromatStyle and will only resolve it when required, using the locale information provided.
Because XCStrings Tool only generates methods with a String argument, we cannot benefit from this deferred formatting, which is unfortunate. It would be nice if we could.
The text was updated successfully, but these errors were encountered:
If we take the following example:
You might at a glance expect the date to be formatted using
en_US
formatting rules, but it is not. This is becausedate.formatted(date: .numeric, time: .omitted)
is resolving aString
usingLocale.current
prior to passing it into theLocalizedStringResource
.Without using XCStrings Tool, if we wanted to format this using the resource (or SwiftUI environment) locale, we'd have to do the following:
\(date, format: .dateTime)
is subtly different todate.formatted(.dateTime)
because it uses a custom interpolation method:https://developer.apple.com/documentation/swift/string/localizationvalue/stringinterpolation/appendinterpolation(_:format:)-5arer
It will hold the original value inside the resource alongside the
FromatStyle
and will only resolve it when required, using the locale information provided.Because XCStrings Tool only generates methods with a
String
argument, we cannot benefit from this deferred formatting, which is unfortunate. It would be nice if we could.The text was updated successfully, but these errors were encountered: