问题
I can't export for localization, I just get a "Localization failed to read a strings file" error.
The system log says:
2015-06-07 01:41:48,305 Xcode[1914]: [MT] DVTAssertions: Warning in /SourceCache/IDEFrameworks/IDEFrameworks-7718/IDEFoundation/Localization/IDELocalizationWork.m:434
Details: Failed to read strings file "/var/folders/vh/z7jrdtc16mv_ml4rdf3c_yf40000gn/T/Xcode3SourceStringsAdaptor-8B1BF14F-E8BF-4354-9FB6-BFF843BD6623/Localizable.strings", underlying error:
The data couldn’t be read because it isn’t in the correct format.
Object: <IDELocalizationWork>
Method: +readStringsWorkForContext:
Thread: <NSThread: 0x7fa8a250a200>{number = 1, name = main}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
But I have no idea what file "Localizable.strings" is. These steps didn't work:
- Found "Localizable.strings" in Base.lproj and deleted it. It was completely empty.
- Deleted the whole folder specified in the log message.
- Clean and Clean build folder.
- Running
genstrings
first to generate missing .strings-files.genstrings
complained and said my strings weren't literals in the calls toNSLocalizedString
. Uhh... they all look like this:private let ALERT_REMINDER_FIRED_TITLE = NSLocalizedString("ALERT_REMINDER_FIRED_TITLE", tableName:"ReminderHandler", comment:"my comment")
I figure that Localizable.strings
is supposed to contain someting, like /** no localizable strings **/
or something. The problem with that is that my project doesn't even contain the file, it's being generated as completely empty.
回答1:
Seems that unfinished and commented out calls to NSLocalizedString
interfere with export for localization.
回答2:
For me it was like key = "your string"; that worked in swift 3. No quotes for key. Semicolons at the end.
回答3:
I had the same problem when tried to use NSLocalizedString
with own NSBundle
specified. Seems Xcode won't work if you use localization macros with different form than NSLocalizedString("Some key", comment: "Some comment")
. I have fixed this by just redefining the NSLocalizedString
function like that:
public func NSLocalizedString(key: String, tableName: String? = nil, bundle: NSBundle = NSBundle.mainBundle(), value: String = "", comment: String) -> String
{
return yourBundleHere.localizedStringForKey(key, value: value, table: tableName)
}
Replace yourBundleHere
with NSBundle.mainBundle()
or what ever you want.
回答4:
Check if there are redundant double quotation marks in your Localizable.strings file, then remove them.
回答5:
The problem for me was that I had completely empty xx.strings files - I'd manually cleared them out.
Add this line at the top of any empty xx.strings files, and the export works again:
/* No Localized Strings */
回答6:
Had the same issue.
In my case it was caused by an NSLocalizedString
that used a variable passed from the server as the key instead of actual strings. The system still scans commented code so anything short of deleting the lines of code will not work.
来源:https://stackoverflow.com/questions/30688768/localization-failed-to-read-a-strings-file-xcode-6-3-2