File: processing2ui.pl

package info (click to toggle)
qgis 3.40.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,185,444 kB
  • sloc: cpp: 1,616,454; python: 372,967; xml: 23,474; sh: 3,761; perl: 3,664; ansic: 2,829; sql: 2,137; yacc: 1,068; lex: 577; javascript: 540; lisp: 411; makefile: 155
file content (112 lines) | stat: -rw-r--r-- 2,910 bytes parent folder | download | duplicates (9)
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/</&lt;/sg;
  $data =~ s/>/&gt;/sg;
  $data =~ s/"/&quot;/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;
}