我试图让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]]
我也需要在本机脚本中返回语言名称,任何想法如何?
谢谢: - )
答案 0 :(得分:1)
看来这有效:
NSLocale *localLocale = [NSLocale localeWithLocaleIdentifier:[test objectAtIndex:i]];
通过不使用当前或系统区域设置,而是使用有问题的语言,然后在脚本中返回其名称!