Tat*_*eva 16 iphone localization nslocalizedstring ios
我需要向服务器发送特定字符串的本地化列表.
这意味着,如果我的应用程序有一个字符串Foo,其本地化为英语为@"Foo",俄语为@"Фу",我想向服务器发送如下列表:
我认为我需要做的是:
我该怎么做(1)我该怎么做(2)?
bdu*_*gan 33
您可以通过将English.lproj/Localizable.strings作为字典读取并获取其键来检索所有字符串键:
NSString *stringsPath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:stringsPath];
Run Code Online (Sandbox Code Playgroud)
要获得每种语言的翻译,您可以迭代每个英语键的语言并使用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));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10904 次 |
最近记录: |