1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#!/usr/bin/env perl
###########################################################################
# processing2cpp.pl
# ---------------------
# begin : July 2015
# copyright : (C) 2015 by Juergen E. Fischer
# email : jef at norbit dot de
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
use XML::Simple;
use YAML::XS qw/LoadFile/;
use Data::Dumper;
sub xmlescape {
my $data = shift;
$data =~ s/&/&/sg;
$data =~ s/</</sg;
$data =~ s/>/>/sg;
$data =~ s/"/"/sg;
return $data;
}
die "usage: $0 dir\n" unless @ARGV==1;
die "directory $ARGV[0] not found" unless -d $ARGV[0];
my %strings;
for my $f (<python/plugins/grassprovider/description/*.txt>) {
open I, $f;
binmode(I, ":utf8");
my $name = scalar(<I>);
my $desc = scalar(<I>);
my $group = scalar(<I>);
while( my($class, $name, $description, $rest) = split /\|/, scalar(<I>) ) {
next unless defined $description;
$description =~ s/\s+$//;
$strings{"GrassAlgorithm"}{$description} = $f;
}
close I;
chop $desc;
chop $group;
$strings{"GrassAlgorithm"}{$desc} = $f;
$strings{"GrassAlgorithm"}{$group} = $f;
}
for my $f (<python/plugins/processing/algs/help/*.yaml>) {
my ($base) = $f =~ /.*\/(.*)\.yaml$/;
$base = uc $base;
my $yaml = LoadFile($f);
for my $k (keys %$yaml) {
$strings{"${base}Algorithm"}{$yaml->{$k}} = $k;
}
}
for my $f ( ("python/plugins/processing/gui/algnames.txt") ) {
open I, $f;
binmode(I, ":utf8");
while(<I>) {
chop;
s/^.*,//;
foreach my $v (split "/", $_) {
$strings{"AlgorithmClassification"}{$v} = $f;
}
}
close I;
}
foreach my $k (keys %strings) {
die "$ARGV[0]/$k-i18n.ui already exists" if -f "$ARGV[0]/$k-i18n.ui";
open F, ">$ARGV[0]/$k-i18n.ui";
binmode(F, ":utf8");
print F <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is NOT a proper UI code. This file is only designed to be caught
by qmake and included in lupdate. It contains all translateable strings collected
by scripts/processing2ui.pl.
-->
<ui version="4.0">
<class>$k</class>;
EOF
foreach my $v (keys %{ $strings{$k} } ) {
next if $v eq "";
my $c = $strings{$k}{$v};
$c =~ s#^.*/##;
$c =~ s#\.[^.]+$##;
print F " <property><string extracomment=\"$c\">" . xmlescape($v) . "</string></property>\n";
}
print F <<EOF;
</ui>
EOF
close F;
}
|