WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Genstring command not working in terminal !!

Forums > SwiftUI

I am trying to generate Localizable strings using genstrings -SwiftUI *.swift command, but terminal is not able to find it. I tried checking solution online where it's suggested to use find ./ -name "*.swift" -print0 | xargs -0 genstrings -a -SwiftUI -o en.lproj, but i am not sure what i should replace en.lproj with, or is it even mandatory?

If i execute above command withou -o, it's generating the Localizable strings in project, but they are greyed out. So, i tried checking error by executing pl < Localizable.strings in terminal, in my project directory. Below is the output-:

*** Exception parsing ASCII property list: NSParseErrorException Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected character / at line 1" UserInfo={NSDebugDescription=Unexpected character / at line 1, kCFPropertyListOldStyleParsingError=Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected character '0x0' at line 9" UserInfo={NSDebugDescription=Unexpected character '0x0' at line 9}}

Xcode error -:

no --inputencoding specified and could not detect encoding from input file

I have checked line 1 there is no such / unexpected character.Can anyone suggest what's going wrong?

Thank you in advance.

1      

I'm stuck as well. genstrings successfully made a Localizable.strigns file for me but I get the error "could not decode input file using specified encoding: Unicode (UTF-8), and the file contents appear to be encoded in Unicode (UTF-16)" on the first line and I don't know where the error is.

Also, it strangely made this line:

"%@:\n%@" = "%1$@:\n%2$@";

1      

Update (hopefully this helps somebody else):

In my Localizable.strings file I changed my Text encoding to UTF-16. (It's default was at UTF-8.) This text encoding parameter can be found at File Inspector > Text Settings > Text Encoding. When you switch to UTF-16, Xcode will ask your if you want to Convert it or Reinterpret it. I honestly don't know. I just tried Reinterpret since it seemed less scary. It compiled now and I think it's working fine so far. We'll see.

I believe this issue might have happened because Swift 5 switched from UTF-16 to UTF-8 and I guess Localizable.strings is expecting UTF-16. Idk.

1      

I had the same problem, and realized my problem was:

All my views swift files were under another folder called Views.

1      

It was resolved for me with this command

genstrings -SwiftUI

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.