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

大憨熊 提交于 2020-06-09 07:36:30

问题


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";

回答1:


  • 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




回答2:


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.




回答3:


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}}




回答4:


In my case, I was missing "=" between a string pair. Even plutil did not help me to spot the error line. I manually checked each string pair. :/




回答5:


I Had the same issue and i resolved it by commenting or removed unused strings in my Localizable.String file :)




回答6:


Also make sure the strings file name is always Localizable.strings




回答7:


Your syntax seems to be fine, the only thing that I can see can "break" your file and cause this error is the quote character. Make sure to use the reqular one " and not in any other form like for example.




回答8:


I once had a similar error and it turned out that there was an URL in the middle of the file, like this:

// Some Comment 1
"Some key 1" = "Some value 1";
http://...whatever...
// Some Comment 2
"Some key 2" = "Some value 2";

When calling plutil -lint on that file the output was:

Unexpected character / at line 1

Well, the first character indeed was / as the file started with a comment but the problem resolved after removing the URL; or turning it into a comment which it actually should have been. Note that the URL was nowhere near the beginning of the strings file, it was about in the middle of a 6000 lines string file. I was only able to find it by browsing through commit history and always look at the changes.




回答9:


It seems your info.plist is not in correct form . check it properly. I also had the same issue . I resolved it by modifying my info.plist.




回答10:


I was having the similar issue where i didn't escape the string value with backslash \ for one of my string's value.

Before:

"INVALID_NUMBER" = "It seems you're entering invalid number. Number should starts with "0" or "7"";

Updated:

"INVALID_NUMBER" = "It seems you're entering invalid number. Number should starts with \"0\" or \"7\"";

Backslashes are required when you want to display the quotation marks "

Please, have a quick look at here for How to include Quotation mark in strings




回答11:


I just had this experience:

  • external translator doing the work inside Visual Code or other text editors
  • Files not working and getting an error like this one: ( testing with plutil -lint )

    Localizable.strings: Unexpected character " at line 1 CardRatingView.strings: Unexpected character / at line 2

I just created a new file within XCode and copy pasted all the file content and suddenly everything was working properly.

I guess something can go wrong / corrupting the file itself while working with other text editors.




回答12:


I ran into this issue, all my formatting was correct. Checking for illegal characters using plutil -lint Localizable.strings and using ruby libraries like "utf8_utils" also didn't work at finding the illegal characters. BUT when I pasted the Localizable.strings contents into the Terminal app while running irb, it did show me the weird characters.

"PercentComplete" = "%d procent gennemført";

Pasted into irb:

"PercentComplete"\U+FFC2\U+FFA0= "%d procent gennemf\U+FFC3\U+FFB8rt";

Then all I had to do was a regex replace to fix those weird white space characters: \U+FFC2\U+FFA0




回答13:


if missing ";" at end of the all lines in Localizable.string file, this error can occur.

eg :- "header_text" = "Current Language"; "change_language" = "Change Language";

"header_text" = "වත්මන් භාෂාව"; "change_language" = "භාෂාව වෙනස් කරන්න";




回答14:


If showing something like Unexpected character " at line 1, and it is the first string like "app_name"="Any Name"

Check that the file is UTF16




回答15:


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.



来源:https://stackoverflow.com/questions/46924196/localizable-strings-the-data-couldn-t-be-read-because-it-isn-t-in-the-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!