简体   繁体   English

如何在 Xcode 中验证 Localizable.strings 文件?

[英]How can I validate Localizable.strings file in Xcode?

How can I check if there are any errors in the file and where I am getting these errors?如何检查文件中是否有任何错误以及我在哪里收到这些错误? In the other words, How can I debug Localizable.strings file in Xcode ?换句话说,如何在 Xcode 中调试 Localizable.strings 文件?

Unfortunately, Xcode dosesn't show line with error.不幸的是,Xcode 不显示错误行。 If you or another developer was changing Localisable.strings recently, probably one of added / changed lines is missing semicolon at end (see answer under this question: Localizable.strings corrupted? ).如果您或其他开发人员最近正在更改 Localisable.strings,则添加/更改的行之一可能在末尾缺少分号(请参阅此问题下的答案: Localizable.strings 损坏? )。 If file is big and / or error is not easy to see probably lucianoenrico answer will be helpful.如果文件很大和/或错误不容易看到,lucianoenrico 的回答可能会有所帮助。 I will quote it now:我现在引用它:

To get more detailed informations you can use the Property List utility from the command line:要获取更详细的信息,您可以从命令行使用属性列表实用程序:

plutil -lint <your_strings_file>.strings

the -lint switch is for checking the syntax. -lint开关用于检查语法。 If you have an error you'll get line number and more informations, and in general better directions on how to fix the issue.如果您有错误,您将获得行号和更多信息,以及关于如何解决问题的更好的指导。

If it is a semicolon issue you can also open corrupted file, search for ";"如果是分号问题,您也可以打开损坏的文件,搜索“;” and look for line without highlighted ";"并寻找没有突出显示“;”的行at end.最后。 Also look for block comments without closing "*/" and unescaped or incorrect quotation marks (need \\"). This last issue is visible because part of string changes color.还要查找没有关闭“*/”和未转义或不正确的引号(需要 \\”)的块注释。最后一个问题是可见的,因为部分字符串更改了颜色。

I'd suggest using a tool like https://github.com/SwiftGen/SwiftGen , which will fail to compile if a file contains an error.我建议使用像https://github.com/SwiftGen/SwiftGen这样的工具,如果文件包含错误,它将无法编译。 You then get compile time errors if the file is invalid as well as if you accidentally remove a key that you are using in your app.如果文件无效以及不小心删除了在应用程序中使用的密钥,则会出现编译时错误。

I recently released an open source tool, Locheck , that does exactly what you're asking for.我最近发布了一个开源工具Locheck ,它完全符合您的要求。 It validates your .strings and .stringsdict files (and Android strings.xml files as well) for common errors.它会验证您的 .strings 和 .stringsdict 文件(以及 Android strings.xml 文件)是否存在常见错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM