skip to Main Content

In the current XCode version (14.3), localized strings are not shown in preview, instead the key is shown. They show in Simulator and on device though. Can someone confirm this behaviour or am I missing a setting or so?

Example
Localized.strings (de): "price" = "Preis";

Code:

Text("price")

Preview*:
price

Simulator / device:
Preis

*) For the preview I am using:

ContentView()
        .environment(.locale, .init(identifier: "de"))

as described here: https://developer.apple.com/documentation/xcode/previewing-localizations

2

Answers


  1. extension String {
    func localized(with arg:[CVarArg] = [])->String{
            return String(format:NSLocalizedString(self, comment:""), arguments: arg)
        }
    }
    

    Try this extension for your string

    Login or Signup to reply.
  2. I got the same issue and I fixed it by cleaning the build folder. Command+Shift+K or via the menu bar: Product -> Clean Build Folder

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search