Line | |
---|
1 | #! /usr/bin/perl -w
|
---|
2 |
|
---|
3 | # Written by Dirk Stöcker <openstreetmap@dstoecker.de>
|
---|
4 | # Public domain, no rights reserved.
|
---|
5 |
|
---|
6 | use strict;
|
---|
7 | use LWP::Simple;
|
---|
8 | use open qw/:std :encoding(utf8)/;
|
---|
9 |
|
---|
10 | my $item;
|
---|
11 | my $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 |
|
---|
16 | # Print a header to write valid Java code. No line break,
|
---|
17 | # so that the input and output line numbers will match.
|
---|
18 | print "class trans_maps { void tr(String s){} void f() {";
|
---|
19 |
|
---|
20 | my @lines;
|
---|
21 | if($ARGV[0] && $ARGV[0] =~ /^https?:\/\//)
|
---|
22 | {
|
---|
23 | my $content = get($ARGV[0]);
|
---|
24 | die "Couldn't get $ARGV[0]" unless defined $content;
|
---|
25 | @lines = split("\r?\n", $content);
|
---|
26 | }
|
---|
27 | else
|
---|
28 | {
|
---|
29 | @lines = <>;
|
---|
30 | }
|
---|
31 |
|
---|
32 | for my $line (@lines)
|
---|
33 | {
|
---|
34 | $line =~ s/\r//g;
|
---|
35 | chomp($line);
|
---|
36 | print "tr(\"---DUMMY-MARKER---\"); ";
|
---|
37 | if($line =~ /<name(?: +lang=['"]en['"])?>(.*)<\/name>/)
|
---|
38 | {
|
---|
39 | my $val = $1;
|
---|
40 | $val =~ s/&/&/g;
|
---|
41 | $val =~ s/"/\\"/g;
|
---|
42 | print "tr(\"$val\"); /* $line */\n";
|
---|
43 | }
|
---|
44 | elsif($line =~ /<description +lang=['"]en['"]>(.*)<\/description>/)
|
---|
45 | {
|
---|
46 | my $val = $1;
|
---|
47 | $val =~ s/&/&/g;
|
---|
48 | $val =~ s/"/\\"/g;
|
---|
49 | print "tr(\"$val\"); /* $line */\n";
|
---|
50 | }
|
---|
51 | elsif($line =~ /^[ \t]*$/)
|
---|
52 | {
|
---|
53 | print "\n";
|
---|
54 | }
|
---|
55 | elsif($line =~ /<entry>/) # required or the gettext info texts get too large
|
---|
56 | {
|
---|
57 | print "public newEntry() {};\n";
|
---|
58 | }
|
---|
59 | else
|
---|
60 | {
|
---|
61 | print "/* $line */\n";
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | print "}}\n";
|
---|
Note:
See
TracBrowser
for help on using the repository browser.