Reputation: 23550
I'm trying to display an html file into a UIWebView :
NSString *htmlPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"error.htm"];
NSError* error;
NSStringEncoding encoding;
NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath usedEncoding:&encoding error:&error];
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:bundlePath]];
error.htm is localized. When using this method, no page is loaded. The htmlContent refers to myApp.app/error.htm. But all my error.htm files are in localized folders.
If I use another non localized HTML file (error2.htm, pure copy of error.htm), it is displayed.
How may I use the localized file ?
Upvotes: 1
Views: 1439
Reputation: 1642
The answer is not correct (and also didn't work for me) - this is the function to use for loading localized resource:
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName;
the localizationName is the two characters localization language code. BTW - you can get your default/current one by using:
return [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
Upvotes: 0
Reputation: 7143
Localization shouldn't be the problem - I'm loading localized HTML files perfectly fine using something like this:
NSString *path = [[NSBundle mainBundle] pathForResource:@"error" ofType:@"htm"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path isDirectory:NO]];
// ...
[self.webView loadRequest:request];
Upvotes: 0
Reputation: 38475
You are creating the path to the html file yourself using the root resource path and a string - the iPhone isn't psychic, how would it know that you have localised this file?
Try using
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"];
instead - this should deal with localised resources for you.
Upvotes: 4