3

I'm working on a bilingual simple IOS App: a PDF file is loaded in a UIWebView with the method described here:

Loading Local PDF File Into WebView

In XCode, using the "Localization" feature, I added a second language (French). The MainStoryboard contains 2 "sub" storyboards, one for English, and one for French.

In the MainStoryboard (English), I inserted a UIWebview --> connect that view to the MainViewController.h --> add the code for inserting the English PDF file in the MainViewController.m:

NSString *path = [[NSBundle mainBundle] pathForResource:@"EnglishBook" ofType:@"pdf" inDirectory:@"PDFBooks"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_UIWebViewBook loadRequest:request];
[_UIWebViewBook setScalesPageToFit:YES];

The English version runs well.

But... where to put the French PDF file ?

Is there a way to target a language-specific PDF file ?

Could "pathForResource:@" be "language" sensitive ?

Thanks for your help !

Community
  • 1
  • 1
SDrolet
  • 165
  • 7

1 Answers1

0
NSString *path = [[NSBundle mainBundle] pathForResource:@"Book" ofType:@"pdf" inDirectory:@"PDFBooks"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_UIWebViewBook loadRequest:request];
[_UIWebViewBook setScalesPageToFit:YES];

Make the request for a single book, then in your project folder make a subfolder en.lproj and fr.lproj add the English version French version respectively and drag both into your Xcode project.

They will both appear, under en.lproj and fr.lproj, then depending on the device localisation, the correct one should load.

To Clarify. In Finder set up this directory structure: enter image description here enter image description here

When you then drag MyBook.txt (pdf in your case) to Xcode, it will look like: enter image description here

Then when you call for MyBook.txt the device will automatically chose which version to grab, depending on the devices international language settings (Settings-General-International-Language).

You might also want to look into UIDocumentInteractionController for documents.

SlateEntropy
  • 3,988
  • 1
  • 23
  • 31
  • Thanks very much for answering ! I almost succeeded... I succeeded with the folders in the following way: Supporting Files / PDFBooks / en.lproj / Book.pdf and Supporting Files / PDFBooks / fr.lproj / Book.pdf But... I still have a problem: I put the UIWebview in the MainStoryboard --> it propagates to the English version (so that it runs well) but the French version is empty (the UIWebView doesn't propagate to the French version). Any idea of how to make the UIWebview propagate to the second storyboard ? – SDrolet Sep 22 '12 at 19:16
  • I tried another solution: I put a new UIWebview in the French Storyboard --> linked it to @property (weak, nonatomic) IBOutlet UIWebView *UIWebViewBook in the MainViewController.h --> Now, this is the English version of the Book that appears in the French iPhone !! Is there a way to make the French UIWebview to point to the Supporting files / PDFBooks / fr.lproj / Book.pdf ? – SDrolet Sep 22 '12 at 19:22
  • Done it !! I solved my last problem with the help of "A critique of Apple’s approach for iOS GUI localization and how to do it much better in your Apps" http://techblog.41concepts.com/author/mmc41/ Thanks to "mmc" ! Thanks again "SurfDev" ! – SDrolet Sep 23 '12 at 13:38