Read .strings file in Objective-C?

前端 未结 4 1038
孤城傲影
孤城傲影 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:39

        NSString *path = [[NSBundle mainBundle] pathForResource:@"Labels" ofType:@"strings"];
        NSData *plistData = [NSData dataWithContentsOfFile:path];
        NSString *error; NSPropertyListFormat format;
    
        NSDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:plistData
                                                              mutabilityOption:NSPropertyListImmutable
                                                                        format:&format
                                                              errorDescription:&error];
        NSString *stringname = [dictionary objectForKey:@"LABEL_001"];
    

    I think it will be helpful to you.

提交回复
热议问题