Xcode全局搜索这个类方法,根据应用当前语言的本地标识,在对应的位置设置语言。
Podfile中写出对应版本号 :pod 'MJRefresh', '~> 3.7.5'
+ (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value
{
static NSBundle *bundle = nil;
//注释掉判断 因为应用内部可以随时切换语言
//if (bundle == nil) {
#if 1
//获取切换所选择的语言
NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"DE_LANGUAGE"];
#else
// //(iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理
// NSString *language = [NSLocale preferredLanguages].firstObject;
#endif
if ([language hasPrefix:@"en"]) {
language = @"en";
} else if ([language hasPrefix:@"zh"]) {
if ([language rangeOfString:@"Hans"].location !=NSNotFound) {
language =@"zh-Hans"; //简体中文
} else { // zh-Hant\zh-HK\zh-TW
language =@"zh-Hant"; //繁體中文
}
} else {
language =@"en";
}
//从MJRefresh.bundle中查找资源
bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]];
//}
value = [bundle localizedStringForKey:key value:value table:nil];
return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
}