xcode 本地化字符串未加载

发布于 2024-11-25 00:59:51 字数 196 浏览 1 评论 0原文

我在本地化字符串方面遇到了一个奇怪的问题。我的“en.lproj”文件夹中只有一个“Localized.strings”,它工作正常。所有字符串都显示在设备上。但下次我编译并运行它时,它只显示字符串的 ID。即使我什么都不做,只点击构建和调试。下次它会再次正常工作,并且下次会再次显示 ID。

那么有人知道为什么会发生这种情况吗?我总是需要构建两次,这有点烦人。

I have met a strange problem with the localized strings. I have only a 'Localizable.strings' in my 'en.lproj' folder and it works fine. all the strings are shown on device. but the next time i compile it and run, it shows only the ID of the strings. even if i change nothing and only click on build&debug. and the next time it works fine again and next time again shown with IDs.

so does anyone knows why this is happening? it's kind of annoying that i always need to build twice.

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

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

发布评论

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

评论(2

攒眉千度 2024-12-02 00:59:51

我的解决方案在底部:

我遇到了同样的问题:交替运行产生正确的翻译,然后产生错误的翻译(尽管仅适用于英语)。

添加“-NSShowNonLocalizedStrings YES”作为应用程序的参数会产生:

Localizable string "MyKey" not found in strings table "Localizable" of bundle CFBundle

因此,我尝试直接从捆绑包中将密钥文件作为字符串加载并转储它。好吧,有时它无法正常工作,它会显示一堆内置的 iOS 消息。因此,我转到构建的 APP 文件,打开包内容,然后查看 en.lproj/Localizes.strings 文件...瞧!该文件已填充 Apple iOS 键/值对。在下一个版本中,它按预期被填满。

当然,这与文件的编码(应该是UTF-16)无关。我无法找到任何提到这个具体问题的内容。

我的解决方案:

我将合法的英文 Localized.strings 文件的内容从应用程序包(不是来自我的源)复制到 XML 文件中(编译时,.strings 文件将转换为 XML)并且添加到我的项目中。然后,我在启动时将此文件加载到字典中,如果对 NSLocalizedString 的调用返回键而不是值,我会对加载的字典进行查找。理论上,您可以对所有语言执行此操作,但我只遇到英语问题。

是的,这不是问题的答案,但它是一种解决方法。

My SOLUTION is at bottom:

I've been running into the same problem: Alternating runs yield correct, then incorrect translations (only for English though).

Adding "-NSShowNonLocalizedStrings YES" as an argument to the app yielded:

Localizable string "MyKey" not found in strings table "Localizable" of bundle CFBundle

So, I tried loading the key file directly from the bundle as a string and dumping it. Well, the times it did NOT work correctly, it was displaying a bunch of built-in iOS messages. So, I went to the APP file that was built, opened the package contents, and viewed the en.lproj/Localizable.strings file...and voila!!! The file had been filled with Apple iOS key/value pairs. On the next build, it was filled as expected.

Of course, this has nothing to do with the encoding of the files (which should be UTF-16). I have not been able to locate anything with mention of this specific problem.

MY SOLUTION:

I copied the contents of the legitimate english Localizable.strings file FROM THE APP PACKAGE (not from my source) into an XML file (when compiled, the .strings file are converted into XML) and added to my project. I then loaded this file into a dictionary at startup, and if the call to NSLocalizedString returned the key instead of the value, I did a lookup on the dictionary I loaded. In theory, you could do this for all languages, but I was only having the problem with english.

Yes, it's not the answer to the problem, but it's a workaround.

南笙 2024-12-02 00:59:51

检查您的项目中是否有多个 Localized.strings。将它们合并为一个为我解决了这个问题。 (检查您使用的任何外部代码,例如 ShareKit)

Check if you have more than one Localizable.strings in your project. Merging them into one solved it for me. (Check any external code you use e.g. ShareKit)

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