从官网下载的ShareSDK中是没有手动修改语言入口的。
不过ShareSDKUI是开源的,通过修改源码,新增个语言属性,通过该属性手动控制语言,源码如下:
https://github.com/MobClub/ShareSDKUI
下载源码
1.在文件SSUIShareSheetConfiguration.h中新增语言属性,通过该属性控制语言
image.png
2.在SSUIPlatformItem文件中,重写生成SSUIPlatformItem实例的方法
+ (instancetype)itemWithPlatformType:(SSDKPlatformType)platformType languageCode:(NSString*)languageCode
{
SSUIPlatformItem *info = [[self alloc] init];
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"ShareSDKUI"
ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
info.iconNormal = [MOBFImage imageName:[NSString stringWithFormat:@"Icon/sns_icon_%lu.png",(unsigned long)platformType] bundle:bundle];
info.iconSimple = [MOBFImage imageName:[NSString stringWithFormat:@"Icon_simple/sns_icon_%lu.png",(unsigned long)platformType] bundle:bundle];
//指定语言
{
NSString *language = languageCode;
if( language == nil ){
language = [NSLocale preferredLanguages].firstObject;
}
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";
}
bundle = [NSBundle bundleWithPath:[bundle pathForResource:language ofType:@"lproj"]];
}
NSString *temName = [NSString stringWithFormat:@"ShareType_%lu",(unsigned long)platformType];
info.platformName = NSLocalizedStringWithDefaultValue(temName, @"ShareSDKUI_Localizable", bundle, temName, nil);
return info;
}
image.png
3.在SSUIShareSheetViewController.m中,修改生成SSUIPlatformItem实例的方法为带有语言的
image.png
4.重新编译生成新的framework,替换官网下载的
网友评论