iOS 应用内切换语言。

参考: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;
}

 

通过切换 文件的路径修改要读取的资源。

有问题请留言!谢谢

  

iOS 应用内切换语言。

上一篇:按键精灵对APP自动化测试(上)


下一篇:HBuilder打包vue项目app后请求不到数据