| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | #!/usr/bin/perl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | @ARGV <= 2 || die "Usage: $0 [<po directory>] [<file pattern>]\n"; | 
					
						
							| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | my $source  = shift @ARGV; | 
					
						
							|  |  |  | my $pattern = shift @ARGV || '*.po'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 09:40:43 +00:00
										 |  |  | sub read_header | 
					
						
							| 
									
										
										
										
											2012-07-01 22:46:49 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	my $file = shift || return; | 
					
						
							|  |  |  | 	local $/; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	open P, "< $file" || die "open(): $!"; | 
					
						
							|  |  |  | 	my $data = readline P; | 
					
						
							|  |  |  | 	close P; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 09:40:43 +00:00
										 |  |  | 	$data =~ / | 
					
						
							|  |  |  | 		^ ( | 
					
						
							|  |  |  | 		msgid \s "" \n | 
					
						
							|  |  |  | 		msgstr \s "" \n | 
					
						
							|  |  |  | 		(?: " [^\n]+ " \n )+ | 
					
						
							|  |  |  | 		\n ) | 
					
						
							|  |  |  | 	/mx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return $1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sub write_header | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	my $file = shift || return; | 
					
						
							|  |  |  | 	my $head = shift || return; | 
					
						
							|  |  |  | 	local $/; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	open P, "< $file" || die "open(): $!"; | 
					
						
							|  |  |  | 	my $data = readline P; | 
					
						
							|  |  |  | 	close P; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$data =~ s/ | 
					
						
							|  |  |  | 		^ ( | 
					
						
							|  |  |  | 		msgid \s "" \n | 
					
						
							|  |  |  | 		msgstr \s "" \n | 
					
						
							|  |  |  | 		(?: " [^\n]+ " \n )+ | 
					
						
							|  |  |  | 		\n ) | 
					
						
							|  |  |  | 	/$head/mx; | 
					
						
							| 
									
										
										
										
											2012-07-01 22:46:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	open P, "> $file" || die "open(): $!"; | 
					
						
							|  |  |  | 	print P $data; | 
					
						
							|  |  |  | 	close P; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | my @dirs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if( ! $source ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-01-03 13:14:06 +00:00
										 |  |  | 	@dirs = glob("./*/*/po"); | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | } | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	@dirs = ( $source ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | foreach my $dir (@dirs) | 
					
						
							| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | 	if( open F, "find $dir -type f -name '$pattern' |" ) | 
					
						
							| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | 		while( chomp( my $file = readline F ) ) | 
					
						
							| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | 			my ( $basename ) = $file =~ m{.+/([^/]+)\.po$}; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 			if( -f "$dir/templates/$basename.pot" ) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				my $head = read_header($file); | 
					
						
							| 
									
										
										
										
											2014-06-13 09:40:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | 				printf "Updating %-40s", $file; | 
					
						
							| 
									
										
										
										
											2025-10-26 15:31:59 +02:00
										 |  |  | 				system("msgmerge", "-U", "-N", $file, "$dir/templates/$basename.pot") == 0 || die "$0: [$file] failed: $?\n"; | 
					
						
							| 
									
										
										
										
											2014-06-13 09:40:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | 				write_header($file, $head); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 16:46:58 +01:00
										 |  |  | 		close F; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-19 17:21:07 +00:00
										 |  |  | } |