简体   繁体   English

使用InAppSettingsKit从Settings.bundle本地化字符串

[英]Localizing strings from the Settings.bundle using InAppSettingsKit

I am attempting to use InAppSettingsKit to manage my settings. 我正在尝试使用InAppSettingsKit来管理我的设置。 This uses the Settings.bundle with a .plist file and the .strings files for each of the languages being translated. 这将使用带有.plist文件的Settings.bundle和要翻译的每种语言的.strings文件。

I can confirm that the translation of my strings is working properly outside of my application, using the Setting application. 我可以使用Setting应用程序确认我的字符串的翻译在我的应用程序之外正常工作。 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: 我认为它归结为这样的代码,来自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];
}

If I understand correctly, this should be using a table with the name self.localizationTable as the source of the translation. 如果我理解正确,这应该使用名为self.localizationTable的表作为翻译的来源。 This value is simply "Root". 这个值只是“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. 它不是所选语言中Root.strings文件的路径,因此我猜测方法localizedStringForKey:value:table:必须使用一些指向正确路径的全局系统引用。

I have confirmed that the strings file name is "Root.strings" all around, with a capital R, including in the Root.plist file. 我已经确认字符串文件名是“Root.strings”,大概是R,包括在Root.plist文件中。

[_bundle localizedInfoDictionary] returns (null); [_bundle localizedInfoDictionary]返回(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. 谢谢你提供的所有帮助。

I'm using InAppSettingsKit with localized text with no problems. 我正在使用InAppSettingsKit本地化文本没有问题。 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? 我能想到的两件事你可以检查:你的Root.strings文件是否位于Settings.bundle的正确子目录中(英语和法语的en.lproj和fr.lproj?

Is there a "Strings Filename" entry in your Root.plist? Root.plist中是否有“Strings Filename”条目? It should simply contain a string with value "Root" 它应该只包含一个值为“Root”的字符串

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 NSBundle类参考

which refers to the following: 指的是以下内容:

Resource Programming Guide 资源编程指南

In the second document, refer to the section "String REsources -> Loading String Resources Into Your Code" 在第二个文档中,请参阅“字符串REsources - >将字符串资源加载到代码中”部分

The solution contains a properly configured Root.strings file, which shows up in the file list like this: 该解决方案包含一个正确配置的Root.strings文件,该文件显示在文件列表中,如下所示:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM