ios启动页国际化的尝试

参考文章:
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

第二步,修改info.list的
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必须设置默认的启动页,不然会黑屏显示。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PS:修改设备系统语言方法设置 -> 通用 -> 语言与地区 -> iPhone 语言Settings -> Ge...
    流火绯瞳阅读 2,890评论 1 4
  • Demo同步更新到Swift2.3本文地址: http://mokai.me/iOS-i18n.html 在真正...
    _GKK_阅读 5,910评论 13 55
  • 一、使用launchImage 国际化方法 对图片进行国际化,由于Image.xcassets无法国际化图片,所以...
    上路喽阅读 3,066评论 0 3
  • 据说有两种方式,本人尝试第一种方法不行,查询之后改为第二种方法,可行。 第一种方法 建一个launchScreen...
    笑破天阅读 5,545评论 3 3
  • 开门见山,国际化有两种方式, 第一种是自己手动创建国际化的各种文件, 此方法的灵活, 容易维护.第二种方式是app...
    heron_funny阅读 2,439评论 1 1