Localizable.strings - The data couldn’t be read because it isn’t in the correct format

40,961

Solution 1

It seems like SVN is having some issue with this file. As it consider it to be a binary file. It is inserting a lot of non printable characters between each characters. I still couldn't find a proper solution. Just changing the Localizable.string files from production PC for avoiding any issue with it.

Update: Updating the SVN client (smartSVN) to the latest version solved the issue. It seems one of my colleague was using a older version. When he commited the change to localizable file it caused the error.

Solution 2

  • Use plutil from the Terminal:

you have to run it for each version of the localizable file. E.g

  1. cd into your project root
  2. cd eb.lproj - you can replace this with any localisation you are working with.
  3. plutil -lint Localizable.strings

When you run step 3, you will either be shown an error, telling you what is wrong with your file. Or you will be told the file is OK

Note that plutil output is bad, it seems it always says "Unexpected character at line 1" but above that output, it prints other stuff like missing semicolon on line 121, and that is the real error

Solution 3

For me, it was missing semi-colons. If you use a tool to generate .strings file, make sure there are no un-escaped quotes that may 'eat' the delimiting semi-colons.

Solution 4

pl < Localizable.strings is better than plutil -lint Localizable.strings

Log will show something like this

2019-08-14 16:39:34.066 pl[21007:428513] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 427. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. 2019-08-14 16:39:34.068 pl[21007:428513] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 427. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. 2019-08-14 16:39:34.071 pl[21007:428513] *** 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 "Missing ';' on line 427" UserInfo={NSDebugDescription=Missing ';' on line 427}}

Solution 5

Fastest way to detect the line with the issued string is to :

  • right click the strings file and
  • then Open as/ASCII property list.

Xcode will immediately tell you in what line there's an error.

Share:
40,961

Related videos on Youtube

Rashad
Author by

Rashad

Always wanted to learn new things and be updated with current situations. StackOverflow showed me you don't only learn from answers, questions are the best way of learning. I got a lot of help from StackOverflow. Just trying to payback.. :) #SOreadytohelp

Updated on October 22, 2021

Comments

  • Rashad
    Rashad over 2 years

    If I copy something from textedit or web and paste it to localizable file it shows this compilation error. If I type those in localizable file it does not show any error. I am assuring you that I using the correct format and ';' in the file.

    "New" = "New";
    "In Progress" = "In Progress";
    "Waiting" = "Waiting";
    "Closed" = "Closed";
    
  • Rashad
    Rashad over 6 years
    No it's not the case. There are some non printable character in the strings! May be its related to xocde update or something!
  • Rashwan L
    Rashwan L over 6 years
    You can post it in your answer and we can analyze it. Hard to say what’s not working with the little info you’ve provided so far.
  • Rashad
    Rashad over 6 years
    My SVN is considering the .string file as binary file. Are you sure you ran into something like this?
  • Alexander Tumanin
    Alexander Tumanin about 6 years
    It shows me Unexpected character " at line 1, and it is the first string like "app_name"="Any Name"
  • Mecki
    Mecki about 5 years
    Why? String files are allowed to be UTF-8 as well. All my string files are always UTF-8 and that has never been a problem. Actually there is an Xcode setting that allows you to choose which files Xcode shall write on output when copying string files and even that setting allows you to choose UTF-8, UTF-16 or binary.
  • Alexandre G
    Alexandre G about 5 years
    Hey yeah, I've realized later what you are describing. I think the error is due to Xcode thinking the file is in one encoding, while factually it's in another.
  • Mecki
    Mecki about 5 years
    UTF-16 files require a BOM. If there is no BOM, macOS usually assumes UTF-8. But if you want to use UTF-8 in a place where UTF-16 is expected, this often works as well if you place an UTF-8 BOM (BOMs are optional for UTF-8 but macOS usually recognizes them). de.wikipedia.org/wiki/Byte_Order_Mark
  • Omar N Shamali
    Omar N Shamali about 5 years
    the semicolon thing is my problem since i switched to swift
  • BjornW
    BjornW about 5 years
    Note that plutil output is bad, it seems it always says "Unexpected character at line 1" but above that output, it prints other stuff like missing semicolon on line 121, and that is the real error...
  • Oleh Veheria
    Oleh Veheria over 4 years
    This is the best solution and it resolved my problem. "plutil" shows an error on the 1st symbol, but "pl < Localizable.strings" is really better and it show the proper number of line where you have a problem with *.plist
  • BB193DEV
    BB193DEV over 4 years
    Definitely the better solution. It gives you more information and the line number for the issue, rather than a generic output.
  • KZoNE
    KZoNE over 3 years
    Great, Thanks bro, Saved my day (Y)
  • DiscDev
    DiscDev over 3 years
    Same problem here. Thank you!
  • Chanchal Raj
    Chanchal Raj over 3 years
    For me plutil was showing the same error at line 1, although there wasn't any. But pl < Localizable.strings worked for me.
  • Sergio
    Sergio about 3 years
    Where can we read the docs for this pl command? Can't find the < anywhere; anyway this should be part of Xcode and tell us where exactly is the problem instead of telling us to go find a wrong char in a file with hundreds of thousands of chars! stupid... open as ASCII Property List is not working here.
  • Shawn Frank
    Shawn Frank almost 3 years
    this answer is the real GOAT, would never have figured this out as XCode gives a very unhelpful error ...
  • Eyzuky
    Eyzuky almost 3 years
    this helped me easily find the root cause
  • Adnan
    Adnan almost 3 years
    this is the second time I have this problem because of missing Semi-colon. I had a very long error log but they could not bother to mention a missing Semi-colon
  • Abdou Sarr
    Abdou Sarr over 2 years
    this answer was a lifesaver. thank you :)
  • RyanG
    RyanG over 2 years
    @ChanchalRaj you just saved me sooooo much time ty! That commend worked
  • RyanG
    RyanG over 2 years
    This is the best solution!
  • iOS Lifee
    iOS Lifee about 2 years
    Superb solution
  • xgqfrms
    xgqfrms about 2 years
    It's a very clear and simple solution, thanks a lot!