[Rt-commit] rt branch, 4.2/placeholder-mismatch, updated. rt-4.0.0rc7-252-gfcb0448

Shawn Moore sartak at bestpractical.com
Fri May 20 12:21:37 EDT 2011


The branch, 4.2/placeholder-mismatch has been updated
       via  fcb0448f310b4986906b02eefa311100ee7f35a4 (commit)
      from  77c964770516a14bbddbe5b11fe0bc9458108974 (commit)

Summary of changes:
 devel/extract-message-catalog |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

- Log -----------------------------------------------------------------
commit fcb0448f310b4986906b02eefa311100ee7f35a4
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri May 20 12:21:22 2011 -0400

    Factor out the complain logic into a function

diff --git a/devel/extract-message-catalog b/devel/extract-message-catalog
index 77119db..a770779 100755
--- a/devel/extract-message-catalog
+++ b/devel/extract-message-catalog
@@ -320,18 +320,8 @@ 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";
+        complain_about_placeholder_mismatch($lang, $msgid, $msgstr)
+            unless $msgstr eq '';
     }
 
     my $is_english = ( $lang =~ /^en(?:[^A-Za-z]|$)/ );
@@ -380,6 +370,25 @@ sub update {
     return 1;
 }
 
+sub complain_about_placeholder_mismatch {
+    my $lang   = shift;
+    my $msgid  = shift;
+    my $msgstr = shift;
+
+    # 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);
+
+    return 0 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";
+
+    return 1;
+}
+
 sub escape {
     my $text = shift;
     $text =~ s/\b_(\d+)/%$1/;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list