Read .strings file in Objective-C?

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

    Simple Code

    Just create a method as follows

    - (void)localisationStrings
    {
        NSString* path = [[NSBundle mainBundle] pathForResource:@"localisation" ofType:@"strings"];
        NSDictionary *localisationDict = [NSDictionary dictionaryWithContentsOfFile:path];
        NSLog(@"\n %@",[localisationDict objectForKey:@"hello"]);
    }
    

提交回复
热议问题