[Rt-commit] rt branch, 4.2/placeholder-mismatch, created. rt-4.0.0rc7-251-g77c9647
Shawn Moore
sartak at bestpractical.com
Fri May 20 11:50:06 EDT 2011
The branch, 4.2/placeholder-mismatch has been created
at 77c964770516a14bbddbe5b11fe0bc9458108974 (commit)
- Log -----------------------------------------------------------------
commit 77c964770516a14bbddbe5b11fe0bc9458108974
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri May 20 11:49:43 2011 -0400
First cut of warning about mismatched placeholders
http://issues.bestpractical.com/Ticket/Display.html?id=17456
diff --git a/devel/extract-message-catalog b/devel/extract-message-catalog
index 6b231a6..77119db 100755
--- a/devel/extract-message-catalog
+++ b/devel/extract-message-catalog
@@ -247,6 +247,11 @@ sub extract_strings_from_code {
close (_);
}
+sub uniq {
+ my %seen;
+ return grep { !$seen{$_}++ } @_;
+}
+
sub update {
my $lang = shift;
my $file = shift;
@@ -314,6 +319,19 @@ sub update {
$Lexicon{$msgid} = $msgstr;
$Header{$msgid} = $msghdr;
+
+ # skip empty messages
+ next if $msgstr eq '';
+
+ # we uniq because a string can use a placeholder more than once
+ # (eg %1 %quant(%1, ...) like in our czech localization
+ my @expected_variables = uniq($msgid =~ /%\d+/g);
+ my @got_variables = uniq($msgstr =~ /%\d+/g);
+
+ next if @expected_variables == @got_variables;
+ warn "$lang string does not have the expected number of placeholders\n";
+ warn "expected " . scalar(@expected_variables) . " in msgid: $msgid\n";
+ warn " got " . scalar(@got_variables) . " in msgstr: $msgstr\n\n";
}
my $is_english = ( $lang =~ /^en(?:[^A-Za-z]|$)/ );
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list