2

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 Answer 1

3

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

@State var title: LocalizedStringKey = "Name"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.