参考文章:
https://noahzy.com/ioskai-fa-ji-qiao-guo-ji-hua-localization-zhi-kan-yi-pian-jiu-gou-liao/
https://www.cnblogs.com/FrankieZ/p/8552830.html
https://www.cnblogs.com/zhchoutai/p/8393902.html
第一步,新建几个对应国家的LaunchScreen.storyboard,文件名自定义就好,如图:
image.png
image.png
,
image.png
获取设置启动页这个key的名称,“UILaunchStoryboardName”
第三步,info.list,实现国际化文件,如图:
image.png
image.png
在这些info.list strings文件里面添加这一行:
"UILaunchStoryboardName" = "LaunchScreen_EN";
对应不同国家,设置不同的启动页文件名称。
第四步测试,设置手机的系统语言为英文,打开app就是英文的启动页;
再修改系统语言为中文,发现还是英文的启动页,只有重新卸载了app才看到中文。因为ios的启动页有缓存,即使重新启动也没用。
题外话:
记录react-native使用react-native-splash-screen库,动态修改启动页,
1、修改showSplash方法,
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView {
// if (!loadingView) {
// loadingView = [[[NSBundle mainBundle] loadNibNamed:splashScreen owner:self options:nil] objectAtIndex:0];
// CGRect frame = rootView.frame;
// frame.origin = CGPointMake(0, 0);
// loadingView.frame = frame;
// }
if (!loadingView) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:splashScreen bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:splashScreen];
loadingView = vc.view;
CGRect frame = rootView.frame;
frame.origin = CGPointMake(0, 0);
loadingView.frame = frame;
}
waiting = false;
[rootView addSubview:loadingView];
}
2、AppDelegate.m修改如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"TestApp";
self.initialProps = @{};
[super application:application didFinishLaunchingWithOptions:launchOptions];
// [RNSplashScreen show];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"TestApp"
initialProperties:nil];
// rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:0.0f blue:0.0f alpha:0];
// if (@available(iOS 13.0, *)) {
// rootView.backgroundColor = [UIColor systemBackgroundColor];
// } else {
// rootView.backgroundColor = [UIColor whiteColor];
// }
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// iOS 获取设备当前语言和地区的代码
NSString *currentLanguageRegion = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] firstObject];
//===== preferredLanguage currentLanguageRegion:ja-JP、id-ID、zh-Hans-JP
NSLog(@"===== preferredLanguage 111====== currentLanguageRegion:%@", currentLanguageRegion);
// NSString *path = [[NSBundle mainBundle] pathForResource:currentLanguageRegion ofType:@"lproj" ];
// NSBundle *bundle = [NSBundle bundleWithPath:path];
// NSString *inviteMsg = [bundle localizedStringForKey:@"OK" value:nil table:@"Localizable"];
// [[NSUserDefaults standardUserDefaults] setValue:@[@"id"] forKey:@"AppleLanguages"];
// [[NSUserDefaults standardUserDefaults] synchronize];
[RNSplashScreen showSplash:@"LaunchScreen2" inRootView:rootViewController.view];
return YES;
}
3、测试,会先显示默认的启动页再显示自己动态设置的启动页。因为ios必须设置默认的启动页,不然会黑屏显示。