3
votes

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 !

1

1 Answers

0
votes
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 hereenter 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.