Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 939
Abdalrahman Shatou Avatar asked Nov 29 '12 11:11

Abdalrahman Shatou


People also ask

What are localizable strings?

Localizable. strings file is where you add translation data as key-value pairs. Earlier versions of XCode used to generate a Localizable. strings file by default, and we were able to easily duplicate the Localizable. strings file for other languages.

How do I add localizable strings?

Step 1: Create Localizable.Select File → New → File… or just tap Ctrl+N or Cmd+N . Search for strings and you will see Strings File in Resource window: Choose Strings File and name the file Localizable : Now, let's select Localizable.

What is dynamic localization?

Dynamic localization is the suppression of the broadening of a charged-particle wave packet as it moves along a periodic potential in an a.c. electric field1,2,3.

How does NSLocalizedString work?

NSLocalizedString is a macros for denoting strings as user-facing. (A macros is used to make tasks using the application less repetitive.) It has two arguments: a key, which uniquely identifies the string to be localized, and a comment, a string that is used to provide sufficient context for accurate translation.


1 Answers

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];
like image 106
Daij-Djan Avatar answered Oct 19 '22 15:10

Daij-Djan