首页 > 移动平台 > 详细

iOS 应用内切换语言。

时间:2019-03-14 12:50:03      阅读:159      评论:0      收藏:0      [点我收藏+]

参考: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 应用内切换语言。

原文:https://www.cnblogs.com/littleflyer/p/10529482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!