为什么文件在 iPhone 模拟器中显示为本地化,但在设备上却不然?
我有一个令我困惑的 iPhone 本地化问题。我正在本地化我的应用程序,英语、简体中文和繁体中文都可以正常工作。我有两个文件,Localized.strings 和 Sounds.plist,它们已经本地化。这两个文件中的字符串在设备和模拟器上正确显示。
昨天我添加了西班牙语、意大利语和德语。当我在模拟器中测试时,一切都显示正确。但是,当我部署到设备时,Localized.strings 中包含的字符串正确显示,但 Sounds.plist 中包含的字符串始终以英语显示。甚至中文字符串也无法正确显示。
我尝试清理构建,将翻译后的文本复制回 sound.plist 文件,甚至删除文件,删除 lproj 文件夹,删除本地化并重新开始。
我在 XCode 中设置了一个断点,似乎对于这个文件,它没有检测到 loc 文件夹。从sounds.plist加载字符串的代码是:
+ (NSDictionary*) getSounds
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sounds" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
return dict;
}
我已经验证文件名是sounds.plist,全部小写。此时,我不知所措。有人经历过这样的事情吗?有人对如何修复有建议吗?
谢谢!
更新:我在模拟器和设备上比较了以下行的结果:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sounds" ofType:@"plist"];
在模拟器上,路径正确报告为/Users/Steve/.../de .lproj/sounds.plist。 在设备上,路径报告为 /var/mobile/.../sounds.plist。 请注意,de.lproj 不在路径中。因此它从根目录加载 sound.plist,这解释了为什么文本未显示本地化。现在我的问题是为什么代码没有获取本地化文件夹中文件的路径?
I have an iPhone localization problem that has me perplexed. I was localizing my app and had English as well as simplified and traditional Chinese working fine. I have two files, Localizable.strings and sounds.plist which have been localized. Strings in both files appeared correctly on the device and emulator.
Now yesterday I am adding Spanish, Italian and German. When I test in the emulator, everything displays correctly. But when I deploy to the device, the strings contained in Localizable.strings display correctly, but the strings contained in sounds.plist always display in English. Even the Chinese strings stopped appearing correctly.
I've tried cleaning the builds, copying the translated text back into the sounds.plist files, and even nuking the files, deleting the lproj folders, removing the localizations and starting over.
I set a breakpoint in XCode and it seems like for this file, it is not detecting the loc folder. The code that loads the strings from sounds.plist is:
+ (NSDictionary*) getSounds
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sounds" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
return dict;
}
I have verified that the file name is sounds.plist, all in lower case. At this point, I'm at a loss. Has anyone experienced anything like this? Does anyone have suggestions on how to fix?
Thanks!
UPDATE: I have compared the results of the following line on the simulator as well as the device:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sounds" ofType:@"plist"];
On the simulator, the path is correctly reported as /Users/Steve/.../de.lproj/sounds.plist.
On the device, the path is reported as /var/mobile/.../sounds.plist. Note that de.lproj is not in the path. So it's loading sounds.plist from the root, which explains why the text doesn't appear localized. Now my question is why doesn't the code get the path to the file in the localized folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Xcode 中的 sound.plist 文件旁边是否有一个检查?您处于调试模式还是发布模式?
Is there a check next to the sounds.plist file in Xcode? Are you in debug or release mode?
问题是设备上出现了一些问题。我使用 Organizer 从设备上卸载了该应用程序,然后通过 XCode 重新安装。现在一切都运转良好。
The problem was something was messed up on the device. I uninstalled the app from the device using the Organizer, and then re-installed via XCode. Everything is working nicely now.