- # Check for "|..." shortcut(s)
- if ( ( $msgid =~ m/\|[^ ]/ ) != ( $msgstr =~ m/\|[^ ]/ ) ) {
- print( "Missing or redundant xforms shortcut:\n" );
- print( " '$msgid' => '$msgstr'\n" );
- $warn++;
- }
-
- $msgid_clean = lc($msgid);
- $msgstr_clean = lc($msgstr);
-
- $msgid_clean =~ s/|.*?$//;
- $msgid_clean =~ s/&([^ ])/$1/;
- $msgstr_clean =~ s/|.*?$//;
- $msgstr_clean =~ s/&([^ ])/$1/;
-
- if ( defined( $trans{$msgid_clean} ) && $msgstr_clean ne $trans{$msgid_clean}{'msgstr_clean'} ) {
- print( "Different translations for '$msgid_clean':\n" );
- print( " '$msgid' => '$msgstr'\n" );
- print( " '$trans{$msgid_clean}{'msgid'}' => '$trans{$msgid_clean}{'msgstr'}'\n" );
- $warn++;
- } else {
- $trans{$msgid_clean} = { 'msgid' => $msgid, 'msgstr' => $msgstr, 'msgstr_clean' => $msgstr_clean };
+ if ($check_periods) {
+ # Check period at the end of a message; uncomment code if you are paranoid
+ if ( ( $msgid =~ m/\. *(\|.*)?$/ ) != ( $msgstr =~ m/\. *(\|.*)?$/ ) ) {
+ print "Line $linenum: Missing or unexpected period:\n '$msgid' => '$msgstr'\n"
+ unless $only_total;
+ ++$bad{"Bad periods"};
+ $warn++;
+ }
+ }
+
+ if ($check_spaces) {
+ # Check space at the end of a message
+ if ( ( $msgid =~ m/ *?(\|.*)?$/ ) != ( $msgstr =~ m/ *?(\|.*)?$/ ) ) {
+ print "Line $linenum: Missing or unexpected space:\n '$msgid' => '$msgstr'\n"
+ unless $only_total;
+ ++$bad{"Bad spaces"};
+ $warn++;
+ }
+ }
+
+ if ($check_qt) {
+ # Check for "&" shortcuts
+ if ( ( $msgid =~ m/&[^ ]/ ) != ( $msgstr =~ m/&[^ ]/ ) ) {
+ print "Line $linenum: Missing or unexpected Qt shortcut:\n '$msgid' => '$msgstr'\n"
+ unless $only_total;
+ ++$bad{"Bad Qt shortcuts"};
+ $warn++;
+ }
+ }
+
+ if ($check_menu) {
+ # Check for "|..." shortcuts
+ if ( ( $msgid =~ m/\|[^ ]/ ) != ( $msgstr =~ m/\|[^ ]/ ) ) {
+ print "Line $linenum: Missing or unexpected menu shortcut:\n '$msgid' => '$msgstr'\n"
+ unless $only_total;
+ ++$bad{"Bad menu shortcuts"};
+ $warn++;
+ }
+ }
+
+ next unless $check_trans;
+
+ # we now collect these translations in a hash.
+ # this will allow us to check below if we have translated
+ # anything more than one way.
+ my $msgid_clean = lc($msgid);
+ my $msgstr_clean = lc($msgstr);
+
+ $msgid_clean =~ s/(.*)\|.*?$/$1/; # strip menu shortcuts
+ $msgstr_clean =~ s/(.*)\|.*?$/$1/;
+ $msgid_clean =~ s/&([^ ])/$1/; # strip Qt shortcuts
+ $msgstr_clean =~ s/&([^ ])/$1/;
+
+ # this is a hash of hashes. the keys of the outer hash are
+ # cleaned versions of ORIGINAL strings. the keys of the inner hash
+ # are the cleaned versions of their TRANSLATIONS. The value for the
+ # inner hash is an array of the orignal string and translation.
+ $trans{$msgid_clean}{$msgstr_clean} = [ $msgid, $msgstr, $linenum ];
+ }
+
+ if ($check_trans) {
+ foreach $msgid ( keys %trans ) {
+ # so $ref is a reference to the inner hash.
+ my $ref = $trans{$msgid};
+ # @msgstrkeys is an array of the keys of that inner hash.
+ my @msgstrkeys = keys %$ref;
+
+ # do we have more than one such key?
+ if ( $#msgstrkeys > 0 ) {
+ if (!$only_total) {
+ print "Different translations for '$msgid':\n";
+ foreach $msgstr ( @msgstrkeys ) {
+ print "Line $ref->{$msgstr}[2]: '" .
+ $ref->{$msgstr}[0] . "' => '" .
+ $ref->{$msgstr}[1] . "'\n";
+ }