参考:https://github.com/Alittlefly/AppLanguageChange
核心:
- (NSString *)localizeStringWithResourceName:(NSString *)RecoursePath withKey:(NSString *)key table:(NSString *)table{ NSString *PathString = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",RecoursePath] ofType:@"lproj"]; if (PathString.length == 0) { //没有这种语言 默认取系统偏好 NSString *perferredLanguage = keyAppDefaultLanguage; //[[NSLocale preferredLanguages] objectAtIndex:0]; if ([perferredLanguage isEqualToString:@"zh-Hans"]) { perferredLanguage = keyAppDefaultLanguage; } PathString = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@",perferredLanguage] ofType:@"lproj"]; } NSBundle * currentBundle = [NSBundle bundleWithPath:PathString]; NSString * LoaclizedString = [currentBundle localizedStringForKey:key value:nil table:table]; return LoaclizedString; }
通过切换 文件的路径修改要读取的资源。
有问题请留言!谢谢