我已经为几种语言创建了自己的可本地化字符串文件 (XYZLocalized.strings
) 并将它们添加到 bundle 中。我可以使用以下行获取 UIViewController 类中的字符串:
NSLocalizedStringFromTableInBundle(@"xyz_plugin_title", @"XYZLocalized", [XYZPluginDelegate 包], nil);
但是如果我在 NSObject 类中添加这一行,整个构建就会失败:
@interface XYZStringResourceUtil : NSObject
+ (NSString *) getLocalizedString:(NSString *) stringKey;
.
.
@end
@implementation XYZStringResourceUtil
+ (NSString *) getLocalizedString:(NSString *) stringKey {
NSLocalizedStringFromTableInBundle(stringKey, @"XYZLocalizable", [XYZPluginDelegate bundle], nil);
}
.
.
@end
我得到的错误是:
../DerivedData/XXXXXX/Build/Intermediates.noindex/YYYY.build/Debug-iphonesimulator/ZZZZZ.build/Localization/en.lproj/XYZLocalizable.strings: Unexpected character ÿ at line 1
../DerivedData/XXXXXX/Build/Intermediates.noindex/YYYY.build/Debug-iphonesimulator/ZZZZZ.build/Localization/en.lproj/XYZLocalizable.strings: Property List error: Unexpected character ÿ at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.
奇怪的是,即使我从磁盘中删除 .strings
文件,错误也会弹出。仅当我从 NSObject 类中删除该行时,构建才会通过。
NSLocalizedStringFromTableInBundle
对使用位置有任何限制吗?
我已经浪费了好几天的时间试图找到此构建失败的根本原因并修复它。如果有人可以帮助解决这个问题,我将非常感激。
提前致谢。
最佳答案
我能够通过将包含不稳定代码的方法设置为静态方法而不是类方法来找到解决方法。
尽管目前还不清楚为什么类方法不起作用。
关于ios - NSLocalizedStringFromTableInBundle 在 NSObject 类中调用时给出属性列表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55064168/