Does NSURLConnection return an NSError in English only?

If I turn on airplane mode on my iPad and try to make NSURLConnection, I get the error message “Internet connection is disconnected”. If I switch to any other language, then English on my iPad I will have the same error text. Should I get an error in the current language that is selected?

Using this code:

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"Error: %@",[error localizedDescription]); } 
+4
source share
1 answer

I found the answer to my question, and since it is related to this question, I share it so that it can help if someone needs it.

A file containing error codes and localized descriptions is located in /System/Library/Frameworks/Foundation.Framework/Resources/en.lproj/FoundationErrors.strings Copy this file and paste it in another location (so as not to spoil the source file). Now run the command in the terminal to convert the binary file to a text file: plutil -convert xml1 FoundationErrors.strings Now drag the file into the Xcode project and right-click and select Open as... Property list . Now you have the keys and descriptions. You can translate (if the desired language is not available in the localization) or configure them the way you want and save it with the desired Persian.strings name in my case.

Now add this code to the method in which you want to use it:

 //persian error messages file full path NSString * persianErrorsListFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Persian.strings"]; //Load file as dictionary NSDictionary * persianErrorsList = [[NSDictionary alloc] initWithContentsOfFile:persianErrorsListFile]; NSString *errorKey = [NSString stringWithFormat:@"Err%ld", (long)errorCode]; NSString *errorMessage = persianErrorsList[errorKey]; 
+2
source

All Articles