XCode 报告本地化 plist 已损坏

发布于 2024-11-30 05:43:03 字数 341 浏览 0 评论 0原文

我有一个在我的应用程序中使用的 plist 文件,我可以对其进行本地化,因此我在项目中得到两个条目,一个用于英语,一个用于西班牙语,当我编译运行该应用程序时,它可以工作,但当然在这个阶段,内容是完全相同的。

然后,我在 Finder 中将西班牙语 plist 替换为已为我翻译成西班牙语的 plist,这样我就可以在 XCode 编辑器中毫无问题地查看内容。

但是,当我尝试编译时,出现错误,指出:

.../en.lproj/myData.plist:0: 错误: 读取 plist: 无法读取数据,因为它已损坏。

但英文的还没碰过?

您确实可以通过这种方式将本地化文件复制到项目中吗?

I have a plist file that I used in my app that I can localize so I get two entries in my project, one for English and one for Spanish and when I compile an run the app it works but of course at this stage the contents are identical.

I then in Finder replace the Spanish plist with one that has been translated for me into Spanish and I can in the XCode editor view the content without problem.

However when I try to compile I get an error stating:

.../en.lproj/myData.plist:0: error: reading plist: The data couldn’t be read because it has been corrupted.

But the English one has not been touched?

Surely you can copy a localized file into the project in this manner?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

笙痞 2024-12-07 05:43:03
  1. 打开磁盘实用程序修复权限。

  2. 打开终端并运行以下命令:

    plutil -s /somewhere/yourfile1.plist

它会让你通过向您显示确切的错误和行来关注问题的所有细节。所以你必须去报告的路线&使用文本编辑器自行修复。

  1. open disk utility repair permissions.

  2. open terminal and run this command:

    plutil -s /somewhere/yourfile1.plist

It will make you focus with all details of the problem by showing you the exact error and line. So you'll have to go the reported line & fix it by yourself with a text editor.

旧话新听 2024-12-07 05:43:03

可能发生的一件事是有人弄乱了您的标签之一。

在 Xcode 中右键单击您的西班牙语 plist,选择 Open AS,然后选择 源代码

然后检查您的 plist 以确保所有开始和结束标记仍然存在,没有拼写错误,其中是否有任何垃圾字符,并且您没有尝试在整数中使用字符串等:

示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>1</key>
    <dict>
        <key>a</key>
        <string>a1</string>
        <key>b</key>
        <string>b1</string>
    </dict>
    <key>2</key>
    <dict>
        <key>a</key>
        <string>a2</string>
        <key>b</key>
        <string>b2</string>
    </dict>
    <key>3</key>
    <dict>
        <key>a</key>
        <string>a3</string>
        <key>b</key>
        <string>b3</string>
    </dict>
</dict>
</plist>

当我将某些内容从 PDF 复制并粘贴到 Xcode 时,我曾经遇到过一些问题(可能是某种不正确的符号? )并且当我刚刚重新进入时效果很好 它。此外,从文字处理器生成有效的 plist 通常很困难。

One thing that can happen is someone messed up one of your tags.

In Xcode right click on your Spanish plist, select Open AS then Source Code

Then check your plist to ensure all of your opening and closing tags are still there, there are no typos, are there any garbage characters in there, and that you are not trying to use a string in an integer etc:

Example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>1</key>
    <dict>
        <key>a</key>
        <string>a1</string>
        <key>b</key>
        <string>b1</string>
    </dict>
    <key>2</key>
    <dict>
        <key>a</key>
        <string>a2</string>
        <key>b</key>
        <string>b2</string>
    </dict>
    <key>3</key>
    <dict>
        <key>a</key>
        <string>a3</string>
        <key>b</key>
        <string>b3</string>
    </dict>
</dict>
</plist>

I once had some problems when something was copied and pasted into Xcode from a PDF (some kind of incorrect symbol maybe?) and it worked fine when I just re-entered it. Also its often difficult to generate a valid plist from a word processor.

醉酒的小男人 2024-12-07 05:43:03

如果您忘记了行末尾的分号,字符串文件也会发生这种情况。愚蠢的我。

That can also happen with strings file if you forget the semicolons at the end of the lines. Silly me.

绮烟 2024-12-07 05:43:03

如果字符串中有 & ,也会发生这种情况。

替换:

<string>SomeText & SomeMoreText</string>

为:

<string>SomeText & SomeMoreText </string>

This can also happen if you have an & within a string.

Replace:

<string>SomeText & SomeMoreText</string>

With:

<string>SomeText & SomeMoreText </string>
嗳卜坏 2024-12-07 05:43:03

为了任何遇到我的确切问题的人的利益:

我也遇到了损坏的 plist 问题。

我的 plist 是通过将 OpenOffice 中的电子表格导出为 CSV(UTF-8 格式)而生成的。然后,我使用我编写的简单 Python 脚本将 CSV 文件转换为 plist。我相信我的问题是我保存的电子表格中存在一些单元格引用错误(即单元格显示“Err:511”)。错误的存在导致 UTF-8 导出以某种方式失败,从而导致 plist 损坏。

我还没有完全验证上述情况,但我很确定这就是问题所在:在修复了 OpenOffice 中某些单元格中的错误后,我的 plist 再次工作。

这个答案演示了如何使用 iconv 命令来验证文件是否正确编码 - 可以在这种情况下很有用。

For benefit of anyone who had my exact problem:

I had the corrupt plist problem too.

My plist had been generated by exporting a spreadsheet in OpenOffice to CSV (in UTF-8 format). Then I'd convert the CSV file to a plist using a simple Python script I'd written. I believe my problem was that there were some cell reference errors in the spreadsheet I saved (i.e. the cells said "Err:511"). The existence of errors was causing the UTF-8 export to fail somehow, hence the corrupt plist.

I have not absolutely verified the above was the case, but I'm pretty sure that was the problem: after I fixed the errors in some cells in OpenOffice, my plist works again.

This answer demonstrates the use of the iconv command to verify a file is correctly encoded -- could be useful in cases like this.

迷离° 2024-12-07 05:43:03

这发生在我身上,因为我设法在我的 plist 中删除了一个随机引号 (")。将其删除并使其正常工作。

我在 TextWrangler 中打开文件,全部使用 Cmd-F 搜索任何可能导致攻击的字符。

This happened to me because I managed to drop a random quotation mark (") in my plist. Removed it and got it to work.

I opened the file in TextWrangler all used Cmd-F to search for any characters that might be causing the offence.

水染的天色ゝ 2024-12-07 05:43:03

对我来说,它是本地化字符串名称中的一个空格:

而不是 this_is_the_string_we_will_translate

我有 this_is_the string_we_will_translate

很难发现。

For me it was a space in the name of localized string:

Instead of this_is_the_string_we_will_translate

I had this_is_the string_we_will_translate.

Tricky one to spot.

赤濁 2024-12-07 05:43:03

开始调试 plist 的一个好地方是使用 XML 验证器,例如: http://www.w3schools .com/xml/xml_validator.asp

此功能也内置于大多数 Web 开发环境中。

A great place to start debugging plists is to use an XML validator such as: http://www.w3schools.com/xml/xml_validator.asp

This feature is also built into most web development environments.

指尖上得阳光 2024-12-07 05:43:03

发生在我身上,错过了0:
2012-12-9T06:00:00Z
应该是
2012-12-09T06:00:00Z

Happened to me, missed 0:
2012-12-9T06:00:00Z
should be
2012-12-09T06:00:00Z

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文