Skip to content

Instantly share code, notes, and snippets.

@richardbuckle
Last active September 27, 2015 16:28
Show Gist options
  • Save richardbuckle/1298850 to your computer and use it in GitHub Desktop.
Save richardbuckle/1298850 to your computer and use it in GitHub Desktop.
VERY quick and dirty regex to hunt for string literals that may need to be localised
(?<!Path:|Key:|NSLocalizedString\(|NibName:|NibNamed:|imageNamed:|PathComponent:|xpathQuery:|initForModel:|initWithDomain:|predicateWithFormat:|setDateFormat:|fontWithName:|entities:|sortBy:|NSClassFromString\(|NSLog\(|DLog\(|ALog\(|DebugLogging\()\s*(?!@"%@"|@"%d")@".+"
@richardbuckle
Copy link
Author

Explanation:

The conceptual template is:

(?<!PREFIXES_I_DONT_CARE_ABOUT)\s*(?!STRINGS_DONT_CARE_ABOUT)@".+"

(?<!foo|bar) is negative look-behind for "foo or bar". It eliminates any matches preceded by foo or bar.
(?!foo|bar) is negative look-ahead for "foo or bar". It eliminates any matches followed by foo or bar.
The basic idea is to find string literals, eliminating the common cases of @"%@" and @"%d" and eliminating typical Cocoa method and function calls that indicate a non-user-visible string.

With a real-life project, this reduced the number of hits from ~1500 to ~400.

I used BBEdit to search the whole source tree with a filter for Cocoa files (extensions m, mm, h and hh).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment