iOS - 我可以在运行时更改localizable.strings内容吗? [英] iOS - Could I change the localizable.strings content during runtime?

查看:205
本文介绍了iOS - 我可以在运行时更改localizable.strings内容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次启动应用程序时,我都会通过JSON文件加载翻译。我可以解析那个JSON,清理它并将它放在localizable.strings文件中吗?

I am loading the translation through a JSON file every time I launch the application. Could I parse that JSON, clean it up and place it in the localizable.strings file?

如果没有,我能否从本地化文件中加载本地化文件文件目录?

If not, will I be able to load localization from localizable file created in the Documents directory?

推荐答案

没有第一个,因为您无法在部署后编辑应用资源

no the first as you can't edit app resources after deployment

然而,您可以告诉NSBundle使用不同的localizeFile ..或者更确切地说下载json并将其放入NSBundle

you can however tell NSBundle to use a different localizeFile.. or rather download the json and put it in a NSBundle

将localizable放入:

put the localizable into:

<APP/DOCUMENTS>/<APPNAME>.bundle/<LANGUAGE_CODE>.lproj/Localizable.strings

初始化新的可可包

NSBundle *b = [NSBundle bundleWithPath:@"<APP/DOCUMENTS>/<APPNAME>.bundle/"];

然后只需在捆绑包上使用:

then just use this on the bundle:

 - (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName 

例如

[b localizedStringForKey:@"HIHO" value:nil table:nil];

这篇关于iOS - 我可以在运行时更改localizable.strings内容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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