【问题标题】:Localization doesn't affect some .strings files本地化不会影响某些 .strings 文件
【发布时间】:2011-12-12 18:23:06
【问题描述】:

我在我的项目中使用 SORelativeDateTransformer。

我本地化了我的项目(翻译了故事板并创建了 Localizable.strings(我使用了 NSLocalizedString)),这部分翻译完美。

问题是 SORelativeDateTransformer 使用它自己的 SORelativeDateTransformer.strings(使用 NSLocalizedStringFromTable), 在演示中有效,但在我的项目中无效。

更新:还发现我翻译成挪威语本地化的一些标签保留了英文单词。啊!

有什么想法吗?

【问题讨论】:

  • 您找到解决方案了吗?
  • 感谢您回复我。您现在正在使用的任何其他库,我可以使用吗?
  • @saintjab 很抱歉没有提供帮助。不,我记得我只是将字符串从 SORelativeDateTransformer.strings 复制到 Localizable.strings 并用 NSLocalizedString 替换了该项目中的所有 NSLocalizedStringFromTable 调用。
  • 我刚刚根据我的做法发布了一个更新作为答案。感谢您的帮助。

标签: localization xcode4.2 nslocalizedstring localizable.strings


【解决方案1】:

我知道这个问题已经很老了,但这是我使用的解决方案。有一种方法可以强制 SORelativeDateTransformer 根据您的偏好加载特定的本地化字符串。如果您进行了手动安装而不是使用 pod,那么您可以根据自己的喜好编辑 .m。例如,这就是我在 + (NSBundle*) 捆绑方法中实现它的方式

+ (NSBundle *)bundle {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    NSString *systemLanguage = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];//you can use conditional statement after here to load a specific bundle since you now have you language codes here (e.g. 'en' for English, 'zh-Hans' for Chinese (Simplified) etc) 
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"SORelativeDateTransformer" withExtension:@"bundle"];
    bundle = [[NSBundle alloc] initWithURL:url];
    NSString *path = [bundle pathForResource:systemLanguage ofType:@"lproj"];
    bundle = [NSBundle bundleWithPath:path];
});
return bundle;
}

这应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2018-01-26
    • 2015-08-07
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多