--- intltool-merge.in.in-old	2003-08-04 02:50:19.000000000 +0800
+++ intltool-merge.in.in-split	2003-08-08 05:41:48.000000000 +0800
@@ -53,6 +53,7 @@
 my $QUIET_ARG = 0;
 my $PASS_THROUGH_ARG = 0;
 my $UTF8_ARG = 0;
+my $SPLIT_ARG = 0;
 my $cache_file;
 
 ## Handle options
@@ -70,6 +71,7 @@
  "rfc822deb-style|r" => \$RFC822DEB_STYLE_ARG,
  "pass-through|p" => \$PASS_THROUGH_ARG,
  "utf8|u" => \$UTF8_ARG,
+ "split-xml" => \$SPLIT_ARG,
  "cache|c=s" => \$cache_file
  ) or &error;
 
@@ -594,8 +599,6 @@
        close INPUT;
     }
 
-    open OUTPUT, ">$OUTFILE" or die;
-
     # FIXME: support attribute translations
 
     # Empty nodes never need translation, so unmark all of them.
@@ -603,33 +606,78 @@
     $source =~ s|<\s*_($w+)\s*/>|<$1/>|g;
 
     # Support for <_foo>blah</_foo> style translations.
-    while ($source =~ s|^(.*?)([ \t]*)<\s*_($w+)\s*>(.*?)<\s*/_\3\s*>([ \t]*\n)?||s) 
+
+    if ($SPLIT_ARG)
     {
-        print OUTPUT $1;
+	if ($OUTFILE !~ /XX/)
+	{
+	    warn "WARNING: Output file should have specified `XX' within file name with --split\n".
+	         "         option. Will append locale name to output file name by default.\n";
+	    $OUTFILE .= "-XX";
+	}
 
-        my $spaces = $2;
-        my $tag = $3;
-        my $string = $4;
-
-	print OUTPUT "$spaces<$tag>$string</$tag>\n";
-
-	$string =~ s/\s+/ /g;
-	$string =~ s/^ //;
-	$string =~ s/ $//;
-	$string = entity_decode($string);
+	for my $lang (sort keys %po_files_by_lang)
+	{
+	    my $source_copy = $source;
 
-	for my $lang (sort keys %po_files_by_lang) 
-        {
-	    my $translation = $translations{$lang, $string};
-	    next if !$translation;
-	    $translation = entity_encode($translation);
-	    print OUTPUT "$spaces<$tag xml:lang=\"$lang\">$translation</$tag>\n";
-        }
+	    (my $outfilename = $OUTFILE) =~ s/XX/$lang/;
+	    open OUTPUT, ">$outfilename" or die "Can't open $outfilename for writing\n";
+
+	    while ($source_copy =~ s|^(.*?)([ \t]*)<\s*_($w+)\s*>(.*?)<\s*/_\3\s*>([ \t]*\n)?||s) 
+	    {
+		print OUTPUT $1;
+
+		my ($spaces, $tag, $string) = ($2, $3, $4);
+
+		$string =~ s/\s+/ /g;
+		$string =~ s/^ //;
+		$string =~ s/ $//;
+		$string = entity_decode($string);
+
+		my $translation = $translations{$lang, $string};
+		if ($translation)
+		{
+		    $translation = entity_encode($translation);
+		    print OUTPUT "$spaces<$tag xml:lang=\"$lang\">$translation</$tag>\n";
+	        }
+		else
+		{
+		    print OUTPUT "$spaces<$tag>$string</$tag>\n";
+		}
+	    }
+	    print OUTPUT $source_copy;
+	    close OUTPUT;
+	}
     }
+    else
+    {
+	open OUTPUT, ">$OUTFILE" or die "Can't open $OUTFILE for writing\n";
 
-    print OUTPUT $source;
+	while ($source =~ s|^(.*?)([ \t]*)<\s*_($w+)\s*>(.*?)<\s*/_\3\s*>([ \t]*\n)?||s) 
+	{
+	    print OUTPUT $1;
 
-    close OUTPUT;
+	    my ($spaces, $tag, $string) = ($2, $3, $4);
+
+	    print OUTPUT "$spaces<$tag>$string</$tag>\n";
+
+	    $string =~ s/\s+/ /g;
+	    $string =~ s/^ //;
+	    $string =~ s/ $//;
+	    $string = entity_decode($string);
+
+	    for my $lang (sort keys %po_files_by_lang) 
+            {
+		my $translation = $translations{$lang, $string};
+		next if !$translation;
+		$translation = entity_encode($translation);
+		print OUTPUT "$spaces<$tag xml:lang=\"$lang\">$translation</$tag>\n";
+            }
+	}
+
+	print OUTPUT $source;
+	close OUTPUT;
+    }
 }
 
 sub keys_merge_translations
