<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

die "usage: $0 source.ts dest.cpp\n" unless @ARGV==2 &amp;&amp; -f $ARGV[0];

my $xml = XMLin($ARGV[0], ForceArray=&gt;1);

open F, "&gt;$ARGV[1]";

print F &lt;&lt;EOF;
/*
 This is NOT a proper c++ source code. This file is only designed to be caught
 by qmake and included in lupdate. It contains all translateable strings collected
 by pylupdate4.
*/

EOF

die "context expected" unless exists $xml-&gt;{context};

foreach my $context ( @{ $xml-&gt;{context} } ) {
	print F "\n// context: $context-&gt;{name}-&gt;[0]\n\n";

	foreach my $message ( @{ $context-&gt;{message} } ) {
		$message-&gt;{source}-&gt;[0] =~ s/"/\\"/g;
		$message-&gt;{source}-&gt;[0] =~ s/\n/\\n/g;

		print F "translate( \"$context-&gt;{name}-&gt;[0]\", \"$message-&gt;{source}-&gt;[0]\"";

		if( exists $message-&gt;{comment} &amp;&amp; $message-&gt;{comment}-&gt;[0] ne "") {
			$message-&gt;{comment}-&gt;[0] =~ s/"/\\"/g;
			$message-&gt;{comment}-&gt;[0] =~ s/\n/\\n/g;

			print F ",\"$context-&gt;{comment}-&gt;[0]\"";
		}

		print F ");\n";
	}
}

close F;
</pre></body></html>