SwiftUI: Xcode fails to preview formatted strings

Originator:igorferreiracastanheda
Number:rdar://FB7543941 Date Originated:20/01/2020
Status:Open Resolved:
Product:Xcode Product Version:Xcode version 11.3.1 (11C504)
Classification:Incorrect/Unexpected Behavior Reproducible:Always
 
Please describe the issue:
When using formatted strings on a Text view, the preview fails to show the correct text. When running on simulator, or device, it is presented the right resolved string. But, for the preview inside Xcode, the text is never displayed correctly.

In the attached sample, I have 2 supported languages: English & Portuguese. And I created a simple text that shows a formatted string (receives 2 variables, and compose the full String).

When using "main.name \(user.firstName)\(user.secondName)" on a Text view, Xcode fails to show the value on preview. But, it succeeds when using a not-formatted like "main.welcome" key.

I attached as screenshot, the states of using the Text view:

- Simulator: Shows the app running, where the correct text is shown
- Preview: Shows that Xcode fails to render the content of the string, defaulting to the key
- Preview on simulator: Shows that Xcode fails to render the correct content of the string, even when trying to preview on "Live preview" mode, defaulting to the key


Please list the steps you took to reproduce the issue:
- Create a new project
- Configure localisation with (at least) 2 languages
- Create a view that display a Text
- Use the text as "My name is %@"
- Add this key to the Localizable.string files
- Create a Group as previews body of the PreviewProvider
- Create a View in the group with an .environment(\.locale, Locale(identifier: "pt_BR")) (or any other language configured in the project)

What did you expect to happen?
The Xcode preview should display the formatted string, the same way that the device & simulator shows when running the app.

What actually happened?
Xcode fails to resolve the string, and shows the value "My name is %@"

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!