#!/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; 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 () { open I, $f; binmode(I, ":utf8"); my $name = scalar(); my $desc = scalar(); my $group = scalar(); while( my($class, $name, $description, $rest) = split /\|/, scalar() ) { 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 () { 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() { 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 < $k; EOF foreach my $v (keys %{ $strings{$k} } ) { next if $v eq ""; my $c = $strings{$k}{$v}; $c =~ s#^.*/##; $c =~ s#\.[^.]+$##; print F " " . xmlescape($v) . "\n"; } print F < EOF close F; }