iOS:无需重新启动即可更改本地化xib [英] iOS: Change Localized xib without restart

查看:184
本文介绍了iOS:无需重新启动即可更改本地化xib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有些容器可以更改本地化的字符串文件而无需重新启动..就像 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆