使用 InAppSettingsKit 本地化 Settings.bundle 中的字符串
我正在尝试使用 InAppSettingsKit 来管理我的设置。这将 Settings.bundle 与 .plist 文件和要翻译的每种语言的 .strings 文件一起使用。
我可以使用“设置”应用程序确认我的字符串翻译在应用程序之外正常工作。但是当我在我的应用程序中时,翻译没有发生。
我认为这可以归结为这样的代码,来自 InAppSettingsKit 类 IASKSettingsReader,其中有一些我认为有用的日志记录语句:
- (NSString*)titleForStringId:(NSString*)stringId {
NSLog(@"%@",[_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable]);
NSLog(@"%@",[_bundle localizedInfoDictionary]);
return [_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable];
}
如果我理解正确,这应该使用名为 self.localizationTable 作为翻译的来源。这个值就是“Root”。它不是所选语言中的
Root.strings
文件的路径,因此我猜测方法 localizedStringForKey:value:table:
必须使用某种全局系统引用指向正确的路径。
我已经确认字符串文件名都是“Root.strings”,带有大写 R,包括在 Root.plist 文件中。
[_bundle localizedInfoDictionary]
返回 (null);它针对英语和法语两种语言设置执行此操作。
我不知道如何调试这个。感谢您提供的任何帮助。
I am attempting to use InAppSettingsKit to manage my settings. This uses the Settings.bundle with a .plist file and the .strings files for each of the languages being translated.
I can confirm that the translation of my strings is working properly outside of my application, using the Setting application. But when I am in my application, the translation is not occurring.
I think it comes down to code like this, from the InAppSettingsKit class IASKSettingsReader, with a couple logging statements that I thought my be helpful:
- (NSString*)titleForStringId:(NSString*)stringId {
NSLog(@"%@",[_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable]);
NSLog(@"%@",[_bundle localizedInfoDictionary]);
return [_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable];
}
If I understand correctly, this should be using a table with the name self.localizationTable
as the source of the translation. This value is simply "Root". It's not a path to the Root.strings
file in the selected language, so I am guessing that the method localizedStringForKey:value:table:
must be using some global system reference that points to the correct path.
I have confirmed that the strings file name is "Root.strings" all around, with a capital R, including in the Root.plist file.
[_bundle localizedInfoDictionary]
returns (null); It is doing this for two language settings of English and French.
I'm not sure how to debug this. Thanks for any help you can give.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用 InAppSettingsKit 和本地化文本,没有任何问题。我能想到您可以检查的两件事:您的 Root.strings 文件是否位于 Settings.bundle 的正确子目录中(英语和法语为 en.lproj 和 fr.lproj?
您的根目录中是否有“Strings Filename”条目.plist?它应该只包含一个值为“Root”的字符串
I'm using InAppSettingsKit with localized text with no problems. Two things I can think of that you could check: are your Root.strings files located in the correct subdirectories of Settings.bundle (en.lproj and fr.lproj for English and French?
Is there a "Strings Filename" entry in your Root.plist? It should simply contain a string with value "Root"
我解决这个问题已经有一段时间了,当时我还没有完全理解它。但是,为了结束这个问题,我将指出以下文档以供将来参考:
NSBundle 类参考
引用以下内容:
资源编程指南
在第二个文档中,请参阅“字符串资源 -> 将字符串资源加载到您的代码中”部分,
该解决方案包含正确的配置好的 Root.strings 文件,它显示在文件列表中,如下所示:
It has been quite some time since I resolved this, and at the time, I didn't fully understand it. But, in the interest of closing out this question, I'll point to the following documentation for future reference:
NSBundle Class Reference
which refers to the following:
Resource Programming Guide
In the second document, refer to the section "String REsources -> Loading String Resources Into Your Code"
The solution contains a properly configured Root.strings file, which shows up in the file list like this: