I'm trying to use the launch arguments such as NSDoubleLocalizedStrings and NSShowNonLocalizedStrings to test localization in my Objective-C project. For some reason I couldn't get neither of them to work. I tried to set both arguments on launch and options in scheme settings:
Also I've checked NSUserDefaults keys and they both are YES. But the arguments still don't work.
To make sure it's not an XCode bug I've created absolutely new single-view project on Objective-C and Swift with one label on the view. Both projects had empty Localizable.strings files and the code in these projects was the following:
@interface ViewController ()
@property (nonatomic, strong) IBOutlet UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.label.text = NSLocalizedString(@"Some text", nil);
}
@end
and
class ViewController: UIViewController {
@IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label.text = NSLocalizedString("Some text", comment: "")
}
}
The result looked like this:

So here are the questions:
1) What could be the reasons launch arguments don't work in my Objective-C project?
2) Why NSDoubleLocalizedStrings argument doesn't work in Swift?
Spending couple days on investigation and deleting gradually all the files and frameworks from my Objective-C project I figured out that the reason was in AFNetworking library. The issue is described here. If you want to use AFNetworking in your project and debug the localization issues you can add such lines to application: didFinishLaunchingWithOptions:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:YES forKey:@"NSDoubleLocalizedStrings"];
[defaults setBool:YES forKey:@"NSShowNonLocalizedStrings"];
[defaults synchronize];
On second launch of the app you’ll see those launch arguments working.
The answer for the second question about why NSDoubleLocalizedStrings argument doesn't work in Swift is that it's probably a bug in XCode. It might be connected with macros which are not supported in Swift, and NSLocalizedString is actually a macro. Therefore I've created a bug on radar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With