Tuesday, June 14, 2011

How to Find Unlocalized Strings

How to make sure you have localized all text strings in your application? You check it manually once - and then change the code. Is everything still localized? Did someone else in team just touch the code?

Fortunately Apple Xcode team comes to rescue!

Xcode comes with a built-in feature to check whether your text strings have been localized or not. You do it by adding a runtime command line parameter (Xcode4):

Open top-left corner Scheme popup menu and select "Edit Scheme...". Choose Run scheme at left side table. Add "-NSShowNonLocalizedStrings YES" into "Arguments Passed On Launch". Add localized strings, recompile your app and run it.
[self.button setTitle:NSLocalizedString(@"KEY", @"comment") forState:UIControlStateNormal];
There are few things to notice:
  • Checks only NSLocalizedString strings. Search first for all @" and verify everything is localized.
  • Checks only strings used at runtime. This is not a full codebase static analyzer.
  • Works only with hardcoded string names. If you generate NSLocalizedString key dynamically, you will get "false" reports.
  • Results are in console, search for " not found in strings table "
2011-06-14 06:14:06.185 MyApp[35043:40b] Localizable string "Key" not found in strings table "Localizable" of bundle CFBundle 0x8017bf0 </Users/jouni/Library/Application Support/iPhone Simulator/4.1/Applications/82F7E73F-3C2B-32B6-R2D2-DB0094F27FAA/MyApp.app> (executable, loaded).
NSShowNonLocalizedStrings is not a complete solution, but it helps.

No comments:

Post a Comment