ios Localizable.strings - 无法读取数据,因为它的格式不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46924196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:35:39  来源:igfitidea点击:

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

iosxcodeios11localizable.strings

提问by Rashad

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.

如果我从 textedit 或 web 复制某些内容并将其粘贴到可本地化的文件中,则会显示此编译错误。如果我在可本地化的文件中输入它们,它不会显示任何错误。我向你保证我使用了正确的格式和“;” 在文件中。

"New" = "New";
"In Progress" = "In Progress";
"Waiting" = "Waiting";
"Closed" = "Closed";

采纳答案by Rashad

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.

似乎 SVN 对这个文件有一些问题。因为它认为它是一个二进制文件。它在每个字符之间插入了很多不可打印的字符。我仍然找不到合适的解决方案。只需更改生产 PC 中的 Localizable.string 文件即可避免任何问题。

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.

更新:将 SVN 客户端 (smartSVN) 更新到最新版本解决了该问题。似乎我的一位同事使用的是旧版本。当他提交对可本地化文件的更改时,它导致了错误。

回答by bat

  • Use plutilfrom the Terminal:
  • 从终端使用plutil

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

您必须为可本地化文件的每个版本运行它。例如

  1. cdinto your project root
  2. cd eb.lproj- you can replace this with any localisation you are working with.
  3. plutil -lint Localizable.strings
  1. cd进入你的项目根目录
  2. cd eb.lproj- 您可以将其替换为您正在使用的任何本地化。
  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

当您运行第 3 步时,您将看到一个错误,告诉您文件有什么问题。或者你会被告知文件没问题

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

请注意,plutil 输出很糟糕,它似乎总是说“第 1 行出现意外字符”,但在该输出之上,它会打印其他内容,例如第 121 行缺少分号,这才是真正的错误

回答by Ahmed Khalaf

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

对我来说,它缺少分号。如果您使用工具生成.strings文件,请确保没有可能“吃掉”分隔分号的未转义引号。

回答by Jerome

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

pl < Localizable.strings优于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}}

2019-08-14 16:39:34.066 pl[21007:428513] CFPropertyListCreateFromXMLData():旧式 plist 解析器:第 427 行字典中缺少分号。解析将被放弃。中断 _CFPropertyListMissingSemicolon 进行调试。2019-08-14 16:39:34.068 pl[21007:428513] CFPropertyListCreateFromXMLData():旧式 plist 解析器:第 427 行字典中缺少分号。解析将被放弃。中断 _CFPropertyListMissingSemicolon 进行调试。2019-08-14 16:39:34.071 pl[21007:428513] *** 解析 ASCII 属性列表的异常:NSParseErrorException Error Domain=NSCocoaErrorDomain Code=3840“意外字符/在第 1 行” UserInfo={NSDebugDescription character/atUnexpect第 1 行,kCFPropertyListOldStyleParsingError=错误域=NSCocoaErrorDomain 代码=3840 "缺少 ';' 在线 427" UserInfo={NSDebugDescription=缺少“;” 在线 427}}

回答by EsmaGo

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. :/

就我而言,我在字符串对之间缺少“=”。即使 plutil 也没有帮助我发现错误行。我手动检查了每个字符串对。:/

回答by Naishta

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

还要确保字符串文件名始终是 Localizable.strings

回答by Abid Mohamed Sadok

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

我遇到了同样的问题,我通过在Localizable.String文件中注释或删除未使用的字符串来解决它:)

回答by Rashwan L

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.

您的语法似乎很好,我能看到的唯一可以“破坏”您的文件并导致此错误的是引号字符。确保使用 reqular"而不是任何其他形式,例如。

回答by Mecki

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

我曾经遇到过类似的错误,结果发现文件中间有一个 URL,如下所示:

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

When calling plutil -linton that file the output was:

调用plutil -lint该文件时,输出为:

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.

嗯,第一个字符确实是/作为文件开头的注释,但在删除 URL 后问题解决了;或者把它变成一个它实际上应该是的评论。请注意,该 URL 并不靠近字符串文件的开头,它大约位于 6000 行字符串文件的中间。我只能通过浏览提交历史来找到它,并始终查看更改。

回答by prolfe

I ran into this issue, all my formatting was correct. Checking for illegal characters using plutil -lint Localizable.stringsand 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.

我遇到了这个问题,我所有的格式都是正确的。使用plutil -lint Localizable.strings和使用 ruby​​ 库检查非法字符"utf8_utils"也无法找到非法字符。但是当我在运行时将 Localizable.strings 内容粘贴到终端应用程序中时irb,它确实向我显示了奇怪的字符。

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

Pasted into irb:

粘贴到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

然后我所要做的就是用正则表达式替换来修复那些奇怪的空白字符: \U+FFC2\U+FFA0

回答by Thanushka

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

如果缺少“;” 在 Localizable.string 文件中所有行的末尾,可能会发生此错误。

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

例如:-“header_text”=“当前语言”;"change_language" = "更改语言";

"header_text" = "?????? ?????"; "change_language" = "????? ????? ?????";

"header_text" = "?????? ?????"; "change_language" = "????? ????? ?????";