Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...