我需要分发所在目录的HTML文件和图片与我的应用程序。如何查找本地化目录的路径?
的应用有不同的语言支持。我创建了一个目录为每一种语言,然后从中挑选基于当前的区域设置是正确的:
NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"
inDirectory:[language stringByAppendingPathExtension:@"html"];];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
// Fallback to english
path = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"
inDirectory:@"en.html"];
}
我怎样才能更好地处理这个,而不必做以上(这是一个有点乱) ?
我想也许使用xx.lproj
目录这个不知何故,并把本地化HTML 目录每个xx.lproj目录,并使用NSBundle pathForResource
找到正确的文件。尽管如此,仍然无法实现。
算不上什么我要找的。 – 2011-05-04 09:43:54