我需要分發所在目錄的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