码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 应用内切换语言。

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

标签:string   format   value   文件   nsstring   https   问题   hpa   nbu   

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

标签:string   format   value   文件   nsstring   https   问题   hpa   nbu   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!