Skip to content

Instantly share code, notes, and snippets.

@Moligaloo
Last active August 29, 2015 14:07
Show Gist options
  • Save Moligaloo/43bb4249c1673d5c19cb to your computer and use it in GitHub Desktop.
Save Moligaloo/43bb4249c1673d5c19cb to your computer and use it in GitHub Desktop.
Append untranslated NSLocalizedString keys
#!/usr/bin/env perl
use File::Slurp;
use Set::Object qw(set);
if (@ARGV < 2) {
print "Usage: $0 <source directory> <lproj directory>\n";
exit 1;
}
my $classes_path = $ARGV[0];
my $ls_path = $ARGV[1] . "/Localizable.strings";
my @extracted = map {
(read_file $_) =~ /NSLocalizedString\(@"([^"]+)"/g;
} <"$classes_path/*.{m,mm}">;
my @existed = (read_file $ls_path) =~ /"([^"]+)"\s*=/g;
my @diff = @{set(@extracted) - set(@existed)};
if(@diff){
my @lines = map { "\"$_\" = \"...\";\n" } @diff;
unshift @lines, "\n//newly added\n";
append_file($ls_path, @lines);
print "Append ". @diff . " items\n";
}else{
print "No newly added!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment