2

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 to NSLocalizedString. 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.

Andreas
  • 2,665
  • 2
  • 29
  • 38

6 Answers6

3

Seems that unfinished and commented out calls to NSLocalizedString interfere with export for localization.

Andreas
  • 2,665
  • 2
  • 29
  • 38
3

For me it was like key = "your string"; that worked in swift 3. No quotes for key. Semicolons at the end.

Thomas
  • 177
  • 2
  • 9
  • Edit this answer to clearly indicate that there should be semicolons at the end. I thought the answer suggests to remove semicolon. – Chanchal Raj Feb 25 '17 at 12:45
1

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.

MuHAOS
  • 1,108
  • 9
  • 8
1

Check if there are redundant double quotation marks in your Localizable.strings file, then remove them.

yuchen
  • 408
  • 3
  • 9
1

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 */
Jim Keir
  • 546
  • 5
  • 9
0

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.

xemacobra
  • 1,954
  • 2
  • 21
  • 21