SwiftUI not all strings are localized

Viewed 89

SwiftUI didn't translate the string in variable.

I have added:

"Name" = "姓名";

if I wrote:

Text("Name")

works good. I can see the label with 姓名.

If I define a variable like:

@State var title = "Name"
Text(title)

Then the localization doesn't work. Still in Chinese. Any tips?

1 Answers

You have to explicitly indicate that your title variable is a LocalizedStringKey, not a String.

@State var title: LocalizedStringKey = "Name"
Related