静态lib中字符串的本地化 [英] Localization of strings in static lib

查看:126
本文介绍了静态lib中字符串的本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用静态库(SL)的项目。在那个SL中,有一些我想要本地化的字符串,项目包括所有的本地化文件。将所有文本翻译存储在同一文件中时,本地化工作正常。问题是我想将SL字符串与其他字符串分开。我试图将两个不同的* .strings文件(Localizable.strings和Localizable2.strings)放在感兴趣的语言文件夹中,但是没有用。我也尝试使用两个名称相同的* .strings文件(Localizable.strings),但路径不同。它也没用。似乎只支持一个本地化文件,对吧?有人能建议这样做的好方法吗?我正在使用SDK 3.2 beta 2.

I have a project that uses a static library (SL). In that SL, there are a couple of strings I'd like to localize and the project includes all of the localization files. The localization works just fine when storing all text translations in the same file. The thing is that I'd like to separate the SL strings from the other strings. I have tried to put two different *.strings files (Localizable.strings and Localizable2.strings) in the language folder of interest but that did not work. I have also tried to use two *.strings file with the same name (Localizable.strings) but with different paths. It didn't work either. It seems that only one localization file is supported, right? Could anyone suggest a good way of doing this? I'm using SDK 3.2 beta 2.

推荐答案

无法将其捆绑在静态库中,但您可以创建新的捆绑包如 MyStaticLibraryName.bundle ,放在所有本地化版本中并使用下面的代码 NSLocalizedString()。所有你需要做的:添加一个静态库和资源包。

It is not possible to bundle it in a static lib, but you can create new bundle like "MyStaticLibraryName.bundle", put inside all localizations and use the code below instead "NSLocalizedString()". All you need to do: add a static library and resource bundle.

NSString *MyLocalizedString(NSString* key, NSString* comment) {
static NSBundle* bundle = nil;
if (!bundle) {
    NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"MyStaticLibraryName.bundle"];
    bundle = [[NSBundle bundleWithPath:path] retain];
}

return [bundle localizedStringForKey:key value:key table:nil];
}

这篇关于静态lib中字符串的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆