Last active
August 29, 2015 14:07
-
-
Save Moligaloo/43bb4249c1673d5c19cb to your computer and use it in GitHub Desktop.
Append untranslated NSLocalizedString keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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