2

I have been working with xcode 12 and swiftui. In my app I have textFiel with a localizable placeholder in Spanish and English, I switch to xcode 13 and it doesn't show me my localizable placeholder

enter image description here

this only happens in TextField, with SecureField it does not happen even with Text

this is my code

struct ContentView: View {
  @State var email:String = ""
    
    var body: some View {
        VStack () {
           TextField("login5", text: self.$email)
                    .autocapitalization(.none)
                    .padding()
                    .background(RoundedRectangle(cornerRadius: 50).stroke(Color("grayColor")))
        }.padding(.horizontal, 20)
    }
}
                 

Localizable.strings

"login5" = "Correo eléctronico";
4
  • can you show a complete example of the text code (not a picture of bits of code) that you are using and the Localizable.strings file. Commented Sep 24, 2021 at 2:19
  • @workingdog I updated my code Commented Sep 25, 2021 at 21:03
  • this is not a complete example of code that can be use to test your particular issue. Include the file name you use for the localizable strings. Commented Sep 25, 2021 at 23:18
  • I cannot replicate your problem on my setup macos12, xcode 13-beta5 (not release), target ios15. However, I've update my answer with a possible approach. If that still does not work, try using xcode 13-beta5 instead of xcode 13 release, works well for me. Commented Sep 26, 2021 at 23:13

3 Answers 3

3

with SecureField in ios15, you can use the prompt parameter to get your localized string:

SecureField("purpose", text: $password, prompt: Text("login6"))

or using the label:

 SecureField(text: $password) {
     Text("login6")
 }

EDIT1:

This is the test code I'm using to show a working localized TextField and SecureField.

import SwiftUI

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    @State var email = ""
    @State var password = ""
    @State var isVisible = false
    
    var body: some View {
        VStack (spacing: 55) {
            Button(action: { isVisible.toggle() }) {
                Text("Toggle isVisible")
            }
            TextField("login5", text: $email).border(.black)
            if isVisible {
                TextField("login6", text: $password).border(.green)
            } else {
                SecureField("password", text: $password, prompt: Text("login6")).border(.red)
            }
        }.padding(.horizontal, 20)
    }
}

Test Localizable.strings file.

"login5" = "hola login5";
"login6" = "contraseña";

EDIT2: alternative approach of manually using LocalizedStringKey,

TextField(LocalizedStringKey("login5"), text: $email)
Sign up to request clarification or add additional context in comments.

7 Comments

In SecureField I haven´t problem, is in TextField
Its not working with your textfield? And the textfield is only showing when visible is set on true?
I've updated my answer with the code I use for testing. Does this work for you?
@workingdog I do, but nothing only appear "login5"
what system and target are you using? I'm using macos 12, xcode 13-beta (not RC), target ios15, macCatalyst and macos 12. Tested on real devices and simulator.
|
0

Your main Problem is, like workingdog already said, you need to use text: $variable. That means for you declare your variable as @State var password = "" and use it like this..

struct ContentView: View {
    @State var password = ""
    ...
    if self.visible{
        TextField("login6", text: $password)
        ....
    } else {
        SecureField("login6", text: $password)
        ....
    }
}

Btw. next time post your code as code not as picture. Its easier to help you :) Hope I understand your problem correctly and this will be your solution.

1 Comment

the problem is only with TextField TextField("fe8Sub", text: $caesareanFem)
0

I've had the exact same problem, going from Xcode 12 to 13. All of a sudden some (not all) of my text fields no longer show localized string. I was able to fix the problem by forcing:

TextField(LocalizedString("usernameLabel"), text: $username)

Instead of

Textfield("usernameLabel", text: $username)

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.