我在应用商店中有一个应用程序,可让您以不同语言启动应用程序.你可以在这里看到截图:http://linguaswitch.com/
您无法在该屏幕截图中看到它,但应用程序使用NSBundle -localizations作为数组来填充弹出菜单.
Apple在Xcode的后续版本中从"英语"转移到了"en".NSBundle -localizations返回bundle中的任何内容.因此,如果应用程序已经过时(如iCal/Pages),那么您将获得"荷兰语","英语","pt","es","it",即根据添加本地化时间的混合.
Apple要求我解析这个列表.所以它"用户友好".我需要它创建某种类型的数组,再次将ISO-639双字母代码解析为完整的英文名称.
关于如何处理这个问题的任何提示?谢谢!
我认为Apple希望你显示一个列表
或者在法国系统上
因此,您需要将ISO语言代码转换为用户友好的本地化显示名称.此外,您还需要获取那些未使用ISO语言代码命名的.lproj包的ISO语言代码.为此,您需要一个查找表,例如:
NSLocale *englishLocale;
NSMutableDictionary *reverseLookupTable;
englishLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
reverseLookupTable = [NSMutableDictionary dictionaryWithCapacity:
[[NSLocale ISOLanguageCodes] count]
];
for (NSString *languageCode in [NSLocale ISOLanguageCodes]) {
NSString *displayName;
displayName = [[englishLocale
displayNameForKey:NSLocaleLanguageCode
value:languageCode
] lowercaseString];
if (displayName) {
[reverseLookupTable setObject:languageCode forKey:displayName];
}
}
[englishLocale release];
Run Code Online (Sandbox Code Playgroud)
然后
// Find a pretty display name for a few sample languages
NSArray *testLanguages;
testLanguages = [NSArray arrayWithObjects:
@"en", @"fr", @"German", @"de", @"Italian", @"Some non-existing language", nil
];
for (NSString *language in testLanguages) {
if ([[NSLocale ISOLanguageCodes] containsObject:[language lowercaseString]]) {
// seems this already is a valid ISO code
NSLog(
@"%@ - %@",
language,
[[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:language]
);
} else {
// try finding an ISO code from our table
NSString *isoCode;
isoCode = [reverseLookupTable objectForKey:[language lowercaseString]];
if (isoCode) {
// yay
NSLog(
@"%@ - %@",
language,
[[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:isoCode]
);
} else {
// no result ... chances are this is not a real language, but hey
NSLog(@"%@ - no result", language);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2100 次 |
| 最近记录: |