Skip to content

Commit 2f431bc

Browse files
committed
i18n:
* include processing algorithm descriptions from yaml (with yaml fixes) * create ui instead of cpp where possible and use -no-ui-lines to avoid artificial ever changing line numbers in ts files * drop old used scripts: create_new_ts.sh, create_new_ts.sh and integrate_function_help.pl, update_ts_files.sh
1 parent 8105905 commit 2f431bc

File tree

11 files changed

+201
-457
lines changed

11 files changed

+201
-457
lines changed

python/plugins/processing/algs/help/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import codecs
2828
import yaml
2929
from qgis.core import QgsSettings, Qgis
30-
from qgis.PyQt.QtCore import QLocale
30+
from qgis.PyQt.QtCore import QLocale, QCoreApplication
3131

3232

3333
def loadShortHelp():
@@ -37,7 +37,11 @@ def loadShortHelp():
3737
if f.endswith("yaml"):
3838
filename = os.path.join(path, f)
3939
with codecs.open(filename, encoding='utf-8') as stream:
40-
h.update(yaml.load(stream))
40+
for k, v in yaml.load(stream).items():
41+
if v is None:
42+
continue
43+
h[k] = QCoreApplication.translate("{}Algorithm".format(f[:-5].upper()), v)
44+
4145
version = ".".join(Qgis.QGIS_VERSION.split(".")[0:2])
4246
overrideLocale = QgsSettings().value('locale/overrideFlag', False, bool)
4347
if not overrideLocale:
@@ -51,7 +55,9 @@ def replace(s):
5155
return s.replace("{qgisdocs}", "https://docs.qgis.org/%s/%s/docs" % (version, locale))
5256
else:
5357
return None
58+
5459
h = {k: replace(v) for k, v in list(h.items())}
60+
5561
return h
5662

5763

python/plugins/processing/algs/help/qgis.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ qgis:pointsalonglines: >
301301

302302
An optional start and end offset can be specified, which controls how far from the start and end of the geometry the points should be created.
303303

304-
qgis:pointsdisplacement:
304+
qgis:pointsdisplacement: >
305305
Offsets nearby point features by moving nearby points by a preset amount to minimize overlapping features.
306306

307307
qgis:pointslayerfromtable: >
@@ -311,7 +311,7 @@ qgis:pointslayerfromtable: >
311311

312312
The attributes table of the resulting layer will be the input table.
313313

314-
qgis:pointstopath:
314+
qgis:pointstopath: >
315315
Converts a point layer to a line layer, by joining points in a defined order.
316316

317317
Points can be grouped by a field to output individual line features per group.

scripts/appinfo2cpp.py renamed to scripts/appinfo2ui.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import sys
2323
from xml.etree import ElementTree as et
24+
from html import escape
2425

2526
strings = {}
2627

@@ -45,15 +46,18 @@
4546

4647
f.close()
4748

48-
print("""
49-
/*
50-
This is NOT a proper c++ source code. This file is only designed to be caught
49+
print("""\
50+
<?xml version="1.0" encoding="UTF-8"?>
51+
<!--
52+
This is NOT a proper UI code. This file is only designed to be caught
5153
by qmake and included in lupdate. It contains all translateable strings collected
52-
by pylupdate5.
53-
*/
54+
by scripts/appinfo2ui.py.
55+
-->
56+
<ui version="4.0">
57+
<class>appinfo</class>;
5458
""")
5559

5660
for k in strings:
57-
k = k.replace('"', '\\"')
58-
k = k.replace('\n', '\\n')
59-
print("translate( \"appinfo\", \"{}\" )".format(k))
61+
print("<property><string>{}</string></property>".format(escape(k)))
62+
63+
print("</ui>")

scripts/create_new_ts.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

scripts/integrate_function_help.pl

Lines changed: 0 additions & 148 deletions
This file was deleted.

scripts/processing2cpp.pl renamed to scripts/processing2ui.pl

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@
1515
###########################################################################
1616

1717
use XML::Simple;
18+
use YAML::XS qw/LoadFile/;
1819
use Data::Dumper;
1920

20-
die "usage: $0 dest.cpp\n" unless @ARGV==1;
21+
sub xmlescape {
22+
my $data = shift;
2123

22-
open F, ">$ARGV[0]";
23-
binmode(F, ":utf8");
24+
$data =~ s/&/&amp;/sg;
25+
$data =~ s/</&lt;/sg;
26+
$data =~ s/>/&gt;/sg;
27+
$data =~ s/"/&quot;/sg;
2428

25-
print F <<EOF;
26-
/*
27-
This is NOT a proper c++ source code. This file is only designed to be caught
28-
by qmake and included in lupdate. It contains all translateable strings collected
29-
by processing2cpp.pl.
30-
*/
29+
return $data;
30+
}
3131

32-
EOF
32+
33+
die "usage: $0 dir\n" unless @ARGV==1;
34+
die "directory $ARGV[0] not found" unless -d $ARGV[0];
3335

3436
my %strings;
3537

@@ -79,7 +81,16 @@
7981
$strings{"SAGAAlgorithm"}{$desc} = 1;
8082
}
8183

82-
for my $f ( ("python/plugins/processing/gui/algclasssification.txt", "python/plugins/processing/gui/algnames.txt") ) {
84+
for my $f (<python/plugins/processing/algs/help/*.yaml>) {
85+
my ($base) = $f =~ /.*\/(.*)\.yaml$/;
86+
$base = uc $base;
87+
my $yaml = LoadFile($f);
88+
for my $k (keys %$yaml) {
89+
$strings{"${base}Algorithm"}{$yaml->{$k}} = 1;
90+
}
91+
}
92+
93+
for my $f ( ("python/plugins/processing/gui/algnames.txt") ) {
8394
open I, $f;
8495
while(<I>) {
8596
chop;
@@ -92,13 +103,29 @@
92103
}
93104

94105
foreach my $k (keys %strings) {
95-
foreach my $v (keys %{ $strings{$k} } ) {
96-
$v =~ s/\\/\\\\/g;
97-
$v =~ s/"/\\"/g;
98-
$v =~ s/\n/\\n/g;
106+
die "$ARGV[0]/$k-i18n.ui already exists" if -f "$ARGV[0]/$k-i18n.ui";
107+
open F, ">$ARGV[0]/$k-i18n.ui";
108+
binmode(F, ":utf8");
99109

100-
print F "translate(\"$k\", \"$v\");\n";
110+
print F <<EOF;
111+
<?xml version="1.0" encoding="UTF-8"?>
112+
<!--
113+
This is NOT a proper UI code. This file is only designed to be caught
114+
by qmake and included in lupdate. It contains all translateable strings collected
115+
by scripts/processing2ui.pl.
116+
-->
117+
<ui version="4.0">
118+
<class>$k</class>;
119+
EOF
120+
121+
foreach my $v (keys %{ $strings{$k} } ) {
122+
next if $v eq "";
123+
print F " <property><string>" . xmlescape($v) . "</string></property>\n";
101124
}
102-
}
103125

104-
close F;
126+
print F <<EOF;
127+
</ui>
128+
EOF
129+
130+
close F;
131+
}

scripts/qgm2cpp.pl renamed to scripts/qgm2ui.pl

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
use XML::Simple;
1818
use Data::Dumper;
1919

20-
print <<EOF;
21-
/*
22-
This is NOT a proper c++ source code. This file is only designed to be caught
23-
by qmake and included in lupdate. It contains all translateable strings collected
24-
by pylupdate5.
25-
*/
26-
27-
EOF
20+
sub xmlescape {
21+
my $data = shift;
22+
$data =~ s/&/&amp;/sg;
23+
$data =~ s/</&lt;/sg;
24+
$data =~ s/>/&gt;/sg;
25+
$data =~ s/"/&quot;/sg;
26+
return $data;
27+
}
2828

2929
my %labels;
3030
my $file;
@@ -67,9 +67,19 @@ sub parse {
6767
}
6868
close I;
6969

70+
print <<EOF;
71+
<?xml version="1.0" encoding="UTF-8"?>
72+
<!--
73+
This is NOT a proper UI code. This file is only designed to be caught
74+
by qmake and included in lupdate. It contains all translateable strings collected
75+
by scripts/qgm2ui.pl.
76+
-->
77+
<ui version="4.0">
78+
<class>grasslabels</class>;
79+
EOF
80+
7081
foreach (sort keys %labels) {
71-
s/\\/\\\\/g;
72-
s/"/\\"/g;
73-
s/\n/\\n/g;
74-
print "translate( \"grasslabel\", \"$_\" );\n";
82+
print " <property><string>" . xmlescape($_) . "</string></property>\n";
7583
}
84+
85+
print "</ui>\n";

0 commit comments

Comments
 (0)