Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch arguments (NSDoubleLocalizedStrings, NSShowNonLocalizedStrings) don't work

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:enter image description here enter image description here 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:

enter image description here

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?

like image 404
iyuna Avatar asked Nov 01 '25 04:11

iyuna


1 Answers

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.

like image 191
iyuna Avatar answered Nov 03 '25 20:11

iyuna