Read .strings file in Objective-C?

前端 未结 4 1039
孤城傲影
孤城傲影 2021-02-08 10:14

I\'m creating a Mac app and I want to localize my Labels. I thought a .strings file would be a better choice. But I have trouble reading .strings file

4条回答
  •  礼貌的吻别
    2021-02-08 10:37

    One. You have to name your file Localizable.strings in the .lproj directory in the app bundle.

    Two. Use the NSLocalizedString macro:

    NSString *loc = NSLocalizedString(@"LABEL_001", nil);
    

    Three. If nothing works, you can initialize an NSDictionary using a strings file, as a strings file is a special type of plist:

    NSString *fname = [[NSBundle mainBundle] pathForResource:@"whatever" ofType:@"strings"];
    NSDictionary *d = [NSDictionary dictionaryWithContentsOfFile:fname];
    NSString *loc = [d objectForKey:@"LABEL_001"];
    

提交回复
热议问题