我需要向服务器发送一个特定字符串的本地化列表。
这意味着,如果我的应用程序有一个字符串Foo,它在英语中本地化为@Foo,在俄语中为@Фу,我想向服务器发送如下列表:
"Фу":
我认为我需要做的是:
获取本地化的Foo版本。
我怎么做(1)和如何做(2)?
发布于 2011-06-24 06:10:41
您可以通过以英语阅读. string /Localizable.string作为字典并获取它的键来检索所有的字符串键:
NSString *stringsPath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:stringsPath];
要获得每种语言的翻译,您可以迭代每个英语键的语言并使用NSLocalizedStringFromTableInBundle
for (NSString *language in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]) {
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]];
NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"Testing", @"Localizable", bundle, nil));
}
https://stackoverflow.com/questions/6310487
复制