我试图让Xcode以多种格式返回一个iOS语言名称列表。在下面的代码中,我创建了一个字典,返回可以从NSLocale返回的各种字符串。
NSArray *test = [NSLocale availableLocaleIdentifiers]; NSMutableArray *toBeReturned = [[NSMutableArray alloc] init];
for (int i = 0; i < [test count]; i++) {
NSDictionary *languageDictionary = @{
@"langInUsersLang" :
[[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:[test objectAtIndex:i]],
@"langInLang" :
[[NSLocale systemLocale] displayNameForKey:NSLocaleLanguageCode value:[test objectAtIndex:i]],
@"regLangInUsersLang" :
[[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[test objectAtIndex:i]],
@"regLangInLang" :
[[NSLocale systemLocale] displayNameForKey:NSLocaleIdentifier value:[test objectAtIndex:i]],
};
[toBeReturned addObject:languageDictionary];
}
return toBeReturned;上面我也调用了以下内容,但是它似乎返回与上面相同的内容,尽管顺序相反。
@"regLangInUsersLang" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[localIdentifiers objectAtIndex:i]],
@"regLangInLang" : [[NSLocale systemLocale] displayNameForKey:NSLocaleIdentifier value:[localIdentifiers objectAtIndex:i]]我需要返回本地脚本中的语言名称,有什么想法吗?
谢谢:-)
发布于 2015-03-10 08:57:53
啊,看来是这样的:
NSLocale *localLocale = [NSLocale localeWithLocaleIdentifier:[test objectAtIndex:i]];通过不使用当前或系统区域设置,而是使用所讨论的语言,然后在脚本中返回其名称!
https://stackoverflow.com/questions/28959308
复制相似问题