Duck
Duck

Reputation: 35953

iphone - cleaning the Localizable.strings

I have an app that suffered a major surgery and a lot of stuff was modified.

This app was and is localized to several languages.

I am sure that some of the strings on the localizable.strings file are no longer being used. At least 20% of them. Is there a way to check which strings are still being used by apps, so I can get rid of the unnecessary strings out of all language files?

Thanks.

Upvotes: 3

Views: 2785

Answers (1)

Olaf
Olaf

Reputation: 3042

You could:

Dump a new localizable.strings to a temporary directory with

genstrings -o temporary.directory *.m

Then drop the right side of the equal sign from the localizable.strings file to make the comparison easier:

cat temporary.directory/Localizable.strings | awk -F"\=" '{print $1}' > Localizable_new.strings

Do the same for the "old" Localizable.strings (assuming you have an English version):

cat en.lproj/Localizable.strings | awk -F"\=" '{print $1}' > Localizable_old.strings

Then use /Developer/Applications/Utilities/FileMerge to compare Localizable_old.strings with Localizable_new.strings.

Depending on how much 20% are, you might get away with "quickly" deleting the obsolete lines.

I admit this procedure might be tedious and has lots of room for improvement and for example it can't handle correctly equal signs in the comments, but maybe it helps.

EDIT:

I have never been truly happy with above. Looking for a solution easier to maintain I eventually stopped using NSLocalizedString and refractored the code to use NSLocalizedStringWithDefaultValue(<#key#>, <#tbl#>, <#bundle#>, <#val#>, <#comment#>)

Now I make all changes to the localization inside the source code, then run genstrings. genstrings will overwrite the Localizable.strings, but the '<#val#>' filed will contain the string I want inside Localizable.strings. I don't need to edit Localizable.strings for the original language. More details are in my Blog

Upvotes: 2

Related Questions