iOS:无需重新启动即可更改本地化xib

编程入门 行业动态 更新时间:2024-10-27 10:25:42
本文介绍了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

本文发布于:2023-11-24 02:59:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重新启动   iOS   xib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!