iOS - Could I change the localizable.strings content during runtime?

坚强是说给别人听的谎言 提交于 2019-11-27 03:34:45

问题


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?


回答1:


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

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

put the localizable into:

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

init a new cocoa bundle

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 

e.g.

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



回答2:


You can't edit anything in your application bundle, so no to your first question. (Note that you might be able to do it in the Simulator but it certainly won't work on a device.)

Not sure about the second question.



来源:https://stackoverflow.com/questions/13625008/ios-could-i-change-the-localizable-strings-content-during-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!