Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Writing NSDictionary to Localizable.strings

This question is continuum to that one: iOS - Could I change the localizable.strings content during runtime?

The answer was useful, however, there is a problem that I am facing. The printed string doesn't include quotations (like these "") for single word keys and/or values. This made the Localizable.string invalid file. Hence, nothing is retrieved from it even for keys/values with correct format.

Example:

GBP = GBP; Glossary = Glossary; "Go_Location" = "Go to location";

First two are causing the file to be invalid strings file. How to fix that?

like image 672
Abdalrahman Shatou Avatar asked Dec 14 '25 10:12

Abdalrahman Shatou


1 Answers

Use NSDictionary's

- (NSString *)descriptionInStringsFileFormat;

Then write the resulting string to a file using the appropriate encoding:

NSString* strings = [dict descriptionInStringsFileFormat];
[strings writeToFile: @"Localizable.strings" atomically: YES  encoding: NSUTF16StringEncoding  error: nil];

(Obviously add whatever error checking you need).

like image 147
Robert Grant Avatar answered Dec 16 '25 00:12

Robert Grant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!