source: osm/applications/editors/josm/i18n/convmaps.pl@ 35960

Last change on this file since 35960 was 34996, checked in by stoecker, 6 years ago

fix #josm17679 - CDATA in translated texts

File size: 1.5 KB
RevLine 
[12334]1#! /usr/bin/perl -w
2
3# Written by Dirk Stöcker <openstreetmap@dstoecker.de>
4# Public domain, no rights reserved.
5
6use strict;
[25613]7use LWP::Simple;
[31111]8use open qw/:std :encoding(utf8)/;
[12334]9
10my $item;
11my $comment = 0;
12
13# This is a simple conversion and in no way a complete XML parser
14# but it works with a default Perl installation
15
[13392]16# Print a header to write valid Java code. No line break,
17# so that the input and output line numbers will match.
[31029]18print "class trans_maps { void tr(String s){} void f() {";
[13392]19
[25613]20my @lines;
[33756]21if($ARGV[0] && $ARGV[0] =~ /^https?:\/\//)
[12334]22{
[28252]23 my $content = get($ARGV[0]);
24 die "Couldn't get $ARGV[0]" unless defined $content;
25 @lines = split("\r?\n", $content);
[25613]26}
27else
28{
29 @lines = <>;
30}
31
32for my $line (@lines)
33{
34 $line =~ s/\r//g;
[12334]35 chomp($line);
[31901]36 print "tr(\"---DUMMY-MARKER---\"); ";
[31030]37 if($line =~ /<name(?: +lang=['"]en['"])?>(.*)<\/name>/)
[12334]38 {
[26593]39 my $val = $1;
40 $val =~ s/&amp;/&/g;
[33940]41 $val =~ s/"/\\"/g;
[26939]42 print "tr(\"$val\"); /* $line */\n";
[12334]43 }
[34996]44 elsif($line =~ /<description +lang=['"]en['"]><!\[CDATA\[(.*)\]\]><\/description>/)
45 {
46 my $val = $1;
47 $val =~ s/"/\\"/g;
48 print "tr(\"$val\"); /* $line */\n";
49 }
[32825]50 elsif($line =~ /<description +lang=['"]en['"]>(.*)<\/description>/)
[31029]51 {
52 my $val = $1;
53 $val =~ s/&amp;/&/g;
[33940]54 $val =~ s/"/\\"/g;
[31029]55 print "tr(\"$val\"); /* $line */\n";
56 }
[26939]57 elsif($line =~ /^[ \t]*$/)
58 {
59 print "\n";
60 }
61 elsif($line =~ /<entry>/) # required or the gettext info texts get too large
62 {
63 print "public newEntry() {};\n";
64 }
[12334]65 else
66 {
67 print "/* $line */\n";
68 }
69}
[13392]70
71print "}}\n";
Note: See TracBrowser for help on using the repository browser.