我知道有些容器可以更改本地化的字符串文件而无需重新启动..就像 iOS-CustomLocalisator 但是我的问题是我的项目严重依赖于xibs,并且它试图依赖于服务器本地化而不是设备本地化.
I Know that there's some pods for changing localized strings file without restarting .. just like iOS-CustomLocalisator But my problem is my project depending heavily on xibs and it's trying to depend on server localization not device localization..
希望有办法.
推荐答案我认为您首先需要对所有xib进行本地化(通过在文件检查器中单击本地化..."按钮).选择所需的语言,并在需要时对Localizable.strings执行相同的操作.
I think you first need to localize all your xibs (by clicking on "Localize..." button in the file inspector). Choose language you need and do the same for a Localizable.strings if you need it too.
然后在项目中导入 BundleLocalization 文件.如果您需要更改语言,只需使用:
Then import BundleLocalization files in your project. If you need to change language, simply use:
[[BundleLocalization sharedInstance] setLanguage:@"fr"];它将适用于xib,情节提要和NSLocalizedString函数.唯一的问题"是您在设置语言时需要重新加载当前的视图控制器.如果您有UINavigationController(带有小臂或滑板,则无关紧要),可以使用以下方法:
It will work for xib, storyboard and NSLocalizedString function. The only "issue" is your current view controller need to be reload when you set the language. Here is an approach you can use if you have a UINavigationController (with a xib or a stroyboard, it dpesn't matter):
UINavigationController *navController = self.navigationController; UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"currentViewControllerId"]; NSMutableArray *viewControllersArray = [[NSMutableArray alloc] initWithArray:navController.viewControllers]; [viewControllersArray replaceObjectAtIndex:([navController.viewControllers count] - 1) withObject:vc]; navController.viewControllers = viewControllersArray;更多推荐
iOS:无需重新启动即可更改本地化xib
发布评论