本地化无法读取字符串文件 (Xcode 6.3.2)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30688768/
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
Localization failed to read a strings file (Xcode 6.3.2)
提问by Andreas
I can't export for localization, I just get a "Localization failed to read a strings file" error.
我无法导出以进行本地化,我只是收到“本地化无法读取字符串文件”错误。
The system log says:
系统日志说:
2015-06-07 01:41:48,305 Xcode[1914]: [MT] DVTAssertions: Warning in /SourceCache/IDEFrameworks/IDEFrameworks-7718/IDEFoundation/Localization/IDELocalizationWork.m:434
Details: Failed to read strings file "/var/folders/vh/z7jrdtc16mv_ml4rdf3c_yf40000gn/T/Xcode3SourceStringsAdaptor-8B1BF14F-E8BF-4354-9FB6-BFF843BD6623/Localizable.strings", underlying error:
The data couldn't be read because it isn't in the correct format.
Object: <IDELocalizationWork>
Method: +readStringsWorkForContext:
Thread: <NSThread: 0x7fa8a250a200>{number = 1, name = main}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
But I have no idea what file "Localizable.strings" is. These steps didn't work:
但我不知道“Localizable.strings”是什么文件。这些步骤不起作用:
- Found "Localizable.strings" in Base.lproj and deleted it. It was completely empty.
- Deleted the whole folder specified in the log message.
- Clean and Clean build folder.
- Running
genstrings
first to generate missing .strings-files.genstrings
complained and said my strings weren't literals in the calls toNSLocalizedString
. Uhh... they all look like this:private let ALERT_REMINDER_FIRED_TITLE = NSLocalizedString("ALERT_REMINDER_FIRED_TITLE", tableName:"ReminderHandler", comment:"my comment")
- 在 Base.lproj 中找到“Localizable.strings”并将其删除。它完全是空的。
- 删除了日志消息中指定的整个文件夹。
- 清理和清理构建文件夹。
genstrings
首先运行以生成丢失的 .strings 文件。genstrings
抱怨并说我的字符串在调用NSLocalizedString
. 呃……他们都是这样的:private let ALERT_REMINDER_FIRED_TITLE = NSLocalizedString("ALERT_REMINDER_FIRED_TITLE", tableName:"ReminderHandler", comment:"my comment")
I figure that Localizable.strings
is supposed to contain someting, like /** no localizable strings **/
or something. The problem with that is that my project doesn't even contain the file, it's being generated as completely empty.
我想这Localizable.strings
应该包含/** no localizable strings **/
一些东西,比如什么。问题是我的项目甚至不包含该文件,它被生成为完全空的。
回答by Andreas
Seems that unfinished and commented out calls to NSLocalizedString
interfere with export for localization.
似乎未完成并注释掉了NSLocalizedString
干扰导出以进行本地化的调用。
回答by Thomas
For me it was like key = "your string"; that worked in swift 3. No quotes for key. Semicolons at the end.
对我来说就像 key = "your string"; 在 swift 3 中有效。没有引号的关键。以分号结尾。
回答by MuHAOS
I had the same problem when tried to use NSLocalizedString
with own NSBundle
specified. Seems Xcode won't work if you use localization macros with different form than NSLocalizedString("Some key", comment: "Some comment")
. I have fixed this by just redefining the NSLocalizedString
function like that:
尝试使用NSLocalizedString
自己NSBundle
指定的时,我遇到了同样的问题。如果您使用与NSLocalizedString("Some key", comment: "Some comment")
. 我通过重新定义这样的NSLocalizedString
函数来解决这个问题:
public func NSLocalizedString(key: String, tableName: String? = nil, bundle: NSBundle = NSBundle.mainBundle(), value: String = "", comment: String) -> String
{
return yourBundleHere.localizedStringForKey(key, value: value, table: tableName)
}
Replace yourBundleHere
with NSBundle.mainBundle()
or what ever you want.
替换yourBundleHere
为NSBundle.mainBundle()
或任何你想要的。
回答by yuchen
Check if there are redundant double quotation marks in your Localizable.strings file, then remove them.
检查 Localizable.strings 文件中是否有多余的双引号,然后将其删除。
回答by Jim Keir
The problem for me was that I had completely empty xx.strings files - I'd manually cleared them out.
我的问题是我有完全空的 xx.strings 文件 - 我手动清除了它们。
Add this line at the top of any empty xx.strings files, and the export works again:
在任何空的 xx.strings 文件的顶部添加这一行,导出再次工作:
/* No Localized Strings */
回答by xemacobra
Had the same issue.
In my case it was caused by an NSLocalizedString
that used a variablepassed from the server as the key instead of actual strings. The system still scans commented code so anything short of deleting the lines of codewill not work.
有同样的问题。在我的情况下,它是由一个导致NSLocalizedString
该使用的变量从服务器传递的关键,而不是实际的字符串。系统仍会扫描注释代码,因此除了删除代码行之外的任何操作都将不起作用。