Can't automatically load localized resources with pathForResource
I've got an iPhone app that need to be localized. No problem with strings, but, I'm having trouble with resources : I need to load HTML pages that are localized. The files are like : presentation.htm The files are added in the project with the folder where they are (html/), and it add the group called as the folder.
I load the html pages with this code :
NSString *pathPresentation = [[NSBundle mainBundle] pathForResource:@"presentation" ofType:@"htm"];
if(!pathPresentation) {
NSLog(@"Could not find presentation.htm");
}
NSURL *url = [NSURL fileURLWithPath:pathPresentation];
NSLog(@"-> path presentation.htm : %@", pathPresentation);
UIWebView *webViewPresentation = [[UIWebView alloc] init];
NSData *htmlData = [NSData dataWithContentsOfFile:pathPresentation];
if (htmlData) {
[webViewPresentation loadData:htmlData MIMEType:@"text/html" textEncodingName:@"Latin-1" baseURL:url];
}
First Try :
I've followed the indications of this website I Can Localize, since there was yet localized resources in the app. The folders are named : en.lproj and fr.lproj.
I try it on the simulator, but it didn't succeed :
- the log indicates that the path is : (...)/myapp.app/presentation.htm
- the file loaded in the simulator is in french, while the simulator is in english.
Second Try :
Then, I delete the resources and re-add them in their group folder (Resource/html/). I pressed the Info button, and choose to "Make file localizable". The file was added in a English.lproj folder. Then I choose "Add Localization", and "French".
I try it on the simulator, but it didn't succeed (I have clean the build before testing) :
- the log indicates that the path is : (...)/myapp.app/presentation.htm
- the file loaded in the simulator is in french, whil开发者_运维知识库e the simulator is in english.
Third Try :
After reading this page about loading localized resources on iPhone OS 4.0, I've changed the resources in localized folders (delete resources, and rename folders in en_UK.lproj and fr_FR.lproj
I try it on the simulator, but it didn't succeed (I have clean the build before testing) :
- the log indicates that the path is : (...)/myapp.app/presentation.htm
- the file loaded in the simulator is in french, while the simulator is in english.
Help ?
Any idea ?
I know there is the function :
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName
But I want it to be as automatic as possible, and fixing things like Directory or localizationName may prevent my app to be automatic.
The solution is :
- remove application from simulator (or device)
- use simple localized folders, as : en.lproj
- clean build
精彩评论