Skip to content

Instantly share code, notes, and snippets.

@Xenofex
Created November 3, 2014 06:55
Show Gist options
  • Save Xenofex/8c85c192d277f9ebafa6 to your computer and use it in GitHub Desktop.
Save Xenofex/8c85c192d277f9ebafa6 to your computer and use it in GitHub Desktop.
genstrings for Swift
#!/bin/bash
#
# genstrings which searchs both Objective-C .m files and Swift files
#
# Set the 'PROJECT' variable
# I'm using a short function 'LS' to replace NSLocalizedString. This script searches them both.
#
if ! type -P ggrep >/dev/null; then
>&2 echo "Error: GNU grep 'ggrep' not found. Install by 'brew install homebrew/dupes/grep'"
exit 1
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR/..
PROJECT=$DIR/../<YOUR PROJECT FOLDER HERE>
find $PROJECT -name '*.m' -o -name '*.swift' | xargs ggrep -hoP '(LS|NSLocalizedString)\(@?"\K.*?(?=")'| sort | uniq -u | gawk '{ print "\"" $0 "\" = \"" $0 "\";" }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment