Reputation: 20496
I'm trying to work on setting up my Xcode project to generate I believe a XLIFF for each language I want to translate into to send to a translating service to have my app translated. I'm trying to follow this tutorial but I'm still struggling with it.
When adding a language to translate into my storyboard's created a .strings file and took all of my text from my storyboard's and put it into the .strings file and did it all automatically.
Now I'm trying to get it to work for strings in my Swift files. For example I changed "Error"
to be NSLocalizedString("error", tableName: nil, bundle: Bundle.main, value: "Error", comment: "Error Alert Controller Title")
in my code.
Problem is it doesn't create any .strings
file like it did for the storyboard. So when it try to go to Editor > Export For Localization
it gives me an error saying Localization failed to read a strings file
.
Any ideas on how to fix this? I'm assuming I can manually create .strings
files but this seems like a huge pain and seems like there should be an easier way.
Upvotes: 0
Views: 2193
Reputation: 241
Yes, there is a way to generate strings file.
Open your Mac’s Terminal app, then change into the directory where your project’s ViewController.swift
file is.
Now run this command:
genstrings -o en.lproj *.swift
This means: read all Swift files for localized strings, then write them out to the localized strings file for the English project.
It will list out all the strings that you wrote in your code using NSLocalizedString
.
Upvotes: 5