Reputation: 332
This doesn't work:
.environment(\.locale, .init(identifier: "es"))
The preview canvas still shows the english values... Localization works properly if I run the app on the emulator and change the language in the device settings. But it does not work in the preview canvas.
Here is the code I'm using:
Text("SomeLocalizableStringKey")
...
static var previews: some View {
ForEach(["iPhone 8", "iPhone X", "iPhone XS Max"], id: \.self) { deviceName in
MainContentView()
.environment(\.locale, .init(identifier: "es")) // << this seems to be ignored by the preview
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
XCode 12.5.1
Upvotes: 18
Views: 2532
Reputation: 1024
This is how I got it working.
Edit Scheme -> Run -> Options -> Set the language you want under App language.
Clean Build Folder (Command + Shift + K)
Upvotes: 9