xcode国际化.strings

作者: 慧惠 | 来源:发表于2016-01-06 14:54 被阅读437次

1、创建国际化.strings文件

创建国际化.strings文件

2、将国际化文件加入bundle中

国际化文件存放于bundle中

3、国际化文件的使用

//1、获取当前项目的资源bundle
+ (NSBundle *)frameworkBundle {
    static NSBundle* frameworkBundle = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath];
        NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:@"项目名Resource.bundle"];
        frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
    });
    return frameworkBundle;
}

//2、获取当前项目资源bundle中的一个.strings文件的内容
NSString *path = [[DPLocalizationManager frameworkBundle] pathForResource:tableName ofType:@"strings" inDirectory:nil forLocalization:@"当前语言"];
NSDictionary *tableContent = path ? [NSDictionary dictionaryWithContentsOfFile:path] : nil;

//3、读取.strings文件中的对应的key值
NSString *result = self.tables[@"XGSDKLocalizable"][key];

4、开启和关闭模拟器的竖屏

控制模拟器的界面显示的横竖

相关文章

网友评论

    本文标题:xcode国际化.strings

    本文链接:https://www.haomeiwen.com/subject/fjpxkttx.html