I need to distribute a directory containing html files and images with my application.
The application supports different languages. I created a directory for each language, and then select the correct one based on the current language version:
NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
NSString *path = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"
inDirectory:[language stringByAppendingPathExtension:@"html"];];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
path = [[NSBundle mainBundle] pathForResource:@"index"
ofType:@"html"
inDirectory:@"en.html"];
}
How can I deal with this better instead of doing the above (which is a bit messy)?
I think it’s possible, using directories xx.lprojfor this somehow and putting a localized html directory in each xx.lproj directory and using NSBundle pathForResourceto find the correct file. Failed to get it to work.
source
share