NSLocalizedString 返回未在任何地方定义的文本

发布于 2024-12-28 17:13:31 字数 661 浏览 2 评论 0原文

好吧,我真的很惊讶。我前段时间开始了一个IOS项目,一开始就在本地化方面做了一些调整,这变得有点混乱,因为我还不知道如何正确地做到这一点。

现在我决定从头开始本地化,因此丢弃了所有 .strings 文件,并创建了适当的多语言结构。我从空的 Localized.strings 文件开始,然后运行该应用程序以查看是否正确清理了所有内容。对于空的 Localized.string 文件,我假设我的“NSLocalizedString”调用只会以文本形式返回密钥。他们不这样做。他们仍然返回我在旧 .strings 文件中的旧文本。

为了确定起见,我在其中一个 NSLocalizedString 调用下放置了一条 NSLog 语句,如下所示:

NSString *text = NSLocalizedString( key, nil );
NSLog(@"key=%@ text=%@", key, text);

然后我在整个硬盘中搜索返回的文本。我的硬盘上没有文件包含 NSLocalizedString 返回的字符串。而且它是一个与 key 完全不同的字符串,所以它也不能用 NSLocalizedString 构造。

有人知道这是怎么发生的吗?旧信息是否被 XCode 缓存在某处?如何说服该工具使用新的 Localized.strings 文件?显然,我已经“清理”并重建了整个项目。

OK, I am officially flabbergasted. I started an IOS project some time ago, and juggled around with localization a bit at the start, which became a bit of a mess, because I did not know how to do that properly yet.

Now I have decided to do the localization from scratch, and therefore threw away all the .strings files, and created a proper multi-language structure. I started with empty Localizable.strings files, and run the app to see whether I cleaned up everything properly. With empty Localizable.string files, I assumed my "NSLocalizedString" calls would simply return the key as text. They don't. They still return the old text that I had in the old .strings files.

Just to be sure, I put an NSLog statement under one of the NSLocalizedString calls, as such:

NSString *text = NSLocalizedString( key, nil );
NSLog(@"key=%@ text=%@", key, text);

Then I search my whole harddisk for the text that was returned. No file on my harddisk contains the string that NSLocalizedString returns. And it is a completely different string than the key, so it cannot be constructed by NSLocalizedString either.

Anybody knows how this can happen? Is the old info cached somewhere by XCode? How can I persuade the tool to use the new Localizable.strings files? Obviously, I have already 'clean'ed and rebuilt the whole project.

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

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

发布评论

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

评论(3

做个少女永远怀春 2025-01-04 17:13:31

尝试从手机中删除该应用程序,然后清理您的项目并重新安装该应用程序。

如果它仍然不起作用,请检查您是否以某种方式弄乱了构建规则(Xcode 4 - >选择您的目标 - >选项卡“构建规则”)在那里,检查您是否没有太多“ CopyStringsFile”规则不使用“CopyStringsFile”。如果是这样,您可以将它们全部删除,只留下一个。

Try to delete the app from the phone, then clean your project and install the app afresh.

If it still doesn't work, check you haven't somehow messed up with the Build Rules (Xcode 4 -> select your target -> tab "Build Rules") There, check if you don't have too many "CopyStringsFile" rules that aren't using "CopyStringsFile". If so you can remove them all but one.

素食主义者 2025-01-04 17:13:31

如果您正在模拟器上进行测试,请尝试使用“iOS 模拟器”应用程序菜单中的“重置内容和设置...”选项来重置模拟器。

当您重新部署应用程序的新版本时,即使在干净的版本之后,它通常也不会清除先前构建版本的缓存内容。

If you are testing on the simulator, try resetting the simulator using the "Reset content and settings..." option in the "iOS Simulator" application menu.

When you redeploy a new build of the app, even after a clean build, it often doesn't clear out the cached content of the previously built version.

楠木可依 2025-01-04 17:13:31

您还清理了构建文件夹吗? command + option + shift + k 或转到产品,按选项,将会有一个干净的构建文件夹,通常,资源文件被缓存,任何资源文件替换(具有相同文件名但不同对象的文件)可能不会被XCode检测到

另外,删除应用程序/重置模拟器确实有帮助。重新部署时,删除的文件有时不会被删除。

Did you also clean build folder? command + option + shift + k or go to product, press option, there will be a clean build folder, usually, resources file are cached, any resources file replacement (file with same file name but different object) might not be detected by XCode

Also, deleting app / resetting simulator does help. Deleted files sometime don't get removed when you redeploy.

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