Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Icarox

macrumors newbie
Original poster
Oct 13, 2012
6
0
Hi I'm trying to localize an app; database is stored on external server www.XXXXX.com/MyAnnotations_es.plist. Actually I've got two plists MyAnnotations_es.plist and MyAnnotations_en.plist



In Localizable.strings (Spanish) I've got:



Code:
[COLOR="Navy"]"MyAnnotations_es.plist" = "MyAnnotations_es.plist";[/COLOR]
and in Localizable.strings (English) I've got:



Code:
[COLOR="Navy"]"MyAnnotations_en.plist" = "MyAnnotations_en.plist";[/COLOR]


On the ViewController:



Code:
[COLOR="Navy"]- (void)downloadPlist {
    NSLog(@"Download in progress...");
    
    [refreshPlist release];
    
    
    deletePlist.enabled = NO;
    progressView.alpha = 1.0;
    pushToOpen.hidden = YES;
    pushToOpenText.alpha = 0.0;
    
    // Here we're downloading the .plist file from a server to the app's Documents Directory.
    // Create file manager
    fileManager = [NSFileManager defaultManager];
    
    // Point to Document directory
    documentsDirectory = [NSHomeDirectory()
                          stringByAppendingPathComponent:@"Documents"];
    
    documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    
    NSString *filename = NSLocalizedString(@"MyAnnotations_es.plist", @"filename for annotations");
    
    
    filePath = [documentsDirectory stringByAppendingPathComponent:filename];
    
    NSString *urlStr = [@"http://www.XXXXX.com/" stringByAppendingString:filename];
    
    
    NSURL *url;
    url = [NSURL URLWithString:urlStr];
    
    request = [ASIHTTPRequest requestWithURL:url];
    [request setShowAccurateProgress:YES];
    [request setDownloadDestinationPath:filePath];
    [request setDownloadProgressDelegate:progressView];
    [request setDelegate:self];
    [request startAsynchronous];
}[/COLOR]
With this, when I switch to Spanish language on my device shows MyAnnotations_es.plist database. And when English language is switched it shows MyAnnotations_es.plist.

I'd like to show MyAnnotations_en.plist



How can I do it?



Thanks in advance ;)
 
Last edited:
Hi Dejo,

I tried so, using the same key

Localizable.strings (Spanish):

Code:
"MyAnnotations_es.plist" = "MyAnnotations_en.plist";

Localizable.strings (English):

Code:
"MyAnnotations_es.plist" = "MyAnnotations_en.plist";


And in sànish language shows MyAnnotations_es.plist data and switching my device into English shows nothing (blank list) it should show the other plist but it doesn't.

Antother thing is that in the view controller where the list and pin maps is shown has this code:

Code:
// Fetching annotations from our .plist file.
- (void)loadAnnotations {
    // Retrieve path of plist file and populate relevant types with its information.
    
    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    documentsDirectory = [paths objectAtIndex:0];
    
    myPathDocs =  [documentsDirectory stringByAppendingPathComponent:@"MyAnnotations_es.plist"];
    // Uncomment the following line if you want to load annotations from a plist file, in your app bundle instead of a server, and then, comment the line above.
     //myPathDocs = [[NSBundle mainBundle] pathForResource:@"MyAnnotations" ofType:@"plist"];
    
    if (![[NSFileManager defaultManager] fileExistsAtPath:myPathDocs]) {
        NSLog(@"No such file.");
    }

and

Code:
// Loading the .plist file that has been downloaded in MainViewController.
    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    documentsDirectory = [paths objectAtIndex:0];
    
    myPathDocs =  [documentsDirectory stringByAppendingPathComponent:@"MyAnnotations_es.plist"];
    
    if (![[NSFileManager defaultManager] fileExistsAtPath:myPathDocs])
    {
        NSLog(@"File doesn't exist.");
    }

Do you thing that I should write the
Code:
NSLocalizedString(@"MyAnnotations_es.plist", @"filename for annotations")
in the whole project where "MyAnnotations_es.plist" appears?

Thanks
 
And in sànish language shows MyAnnotations_es.plist data and switching my device into English shows nothing (blank list) it should show the other plist but it doesn't.

Do your ASIHTTPRequest delegate methods report any errors?

Do you thing that I should write the
Code:
NSLocalizedString(@"MyAnnotations_es.plist", @"filename for annotations")
in the whole project where "MyAnnotations_es.plist" appears?

Anywhere where you want the string returned to be dependent on the locale, yes.
 
Anywhere where you want the string returned to be dependent on the locale, yes.

That was the key ;)

I forgot to put
Code:
NSLocalizedString(@"MyAnnotations_es.plist", @"filename for annotations")
in anywhere to change teh string from one language to another.

And.... as you said,
You need to use the same key for both Localizable.strings:
"MyAnnotations_es.plist" = "MyAnnotations_es.plist";
"MyAnnotations_es.plist" = "MyAnnotations_en.plist";

Now plists are shown in their proper language ;)

Thanks for all your help Dejo.
Now my app will be localizable :D

language_esp.jpg

language_en.jpg


I guess we can close this thread. Solved!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.