| 
									
										
										
										
											2015-10-18 17:16:46 +02:00
										 |  |  | #!/usr/bin/perl -CS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-29 13:30:20 +01:00
										 |  |  | # Run this script to check if translations messed up format string arguments | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Usage  scripts/checktranslations.pl translations/*ts | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-18 17:16:46 +02:00
										 |  |  | use strict; | 
					
						
							| 
									
										
										
										
											2017-10-29 13:30:20 +01:00
										 |  |  | use utf8::all; | 
					
						
							| 
									
										
										
										
											2015-10-18 17:16:46 +02:00
										 |  |  | use XML::TreeBuilder; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | foreach my $file_name (@ARGV) { | 
					
						
							|  |  |  | 	my $tree = XML::TreeBuilder->new({'NoExpand' => 0, 'ErrorContext' => 0}); | 
					
						
							|  |  |  | 	$tree->parse_file($file_name, ProtocolEncoding => 'UTF-8'); | 
					
						
							|  |  |  | 	foreach my $string ($tree->find_by_tag_name('message')) { | 
					
						
							|  |  |  | 		my $source = $string->find_by_tag_name('source')->as_text; | 
					
						
							| 
									
										
										
										
											2017-10-29 13:30:20 +01:00
										 |  |  | 		my $translation = $string->find_by_tag_name('translation'); | 
					
						
							|  |  |  | 		if ($translation->find_by_tag_name('numerusform')) { | 
					
						
							|  |  |  | 			my @all = $translation->find_by_tag_name('numerusform'); | 
					
						
							|  |  |  | 			foreach my $transstring(@all) { | 
					
						
							|  |  |  | 				&compare($file_name, $source, $transstring->as_text); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			&compare($file_name, $source, $translation->as_text); | 
					
						
							| 
									
										
										
										
											2015-10-18 17:16:46 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-29 13:30:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | sub compare { | 
					
						
							|  |  |  | 	my ($file_name, $src, $trans) = @_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #	print "Checking $src\n"; | 
					
						
							|  |  |  |        	return unless $trans =~ /\S/; | 
					
						
							|  |  |  | 	my @source_args = sort {$a cmp $b} ($src =~ /\%([^\s\-\(\)\,\.\:])/g); | 
					
						
							|  |  |  |         my @translation_args = sort {$a cmp $b} ($trans =~ /\%([^\s\-\(\)\,\.\:])/g); | 
					
						
							|  |  |  | #	print join("|", @translation_args), " vs ", join("|", @source_args),"\n"; | 
					
						
							|  |  |  |         unless (join('', @source_args) eq join('', @translation_args)) { | 
					
						
							|  |  |  |         	print "$file_name:\n$src\n->\n$trans\n\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  |   |