Files
tdv/dicts/gnu-fdl-en-cz.sh
T

30 lines
1.1 KiB
Bash
Raw Normal View History

2021-10-07 03:37:12 +02:00
#!/bin/sh -e
# GNU/FDL English-Czech dictionary, see https://www.svobodneslovniky.cz/
curl -Lo- https://www.svobodneslovniky.cz/data/en-cs.txt.gz | \
zcat | grep -v ^# | sed 's/\\//g' | perl -CSD -F\\t -le '
2021-10-10 06:11:28 +02:00
sub tabesc { shift =~ s/\\/\\\\/gr =~ s/\n/\\n/gr =~ s/\t/\\t/gr }
2021-10-07 03:37:12 +02:00
sub w {
2021-10-10 06:11:28 +02:00
my ($name, $dict, $collation) = @_;
open(my $f, "|-", "tdv-tabfile", "--pango", "--collation=$collation",
2021-10-10 06:11:28 +02:00
"--website=https://www.svobodneslovniky.cz",
"gnu-fdl-$name") or die $!;
print $f tabesc($keyword) . "\t" . tabesc(join("\n", @$defs))
while ($keyword, $defs) = each %{$dict};
2021-10-07 03:37:12 +02:00
close($f);
}
2021-10-10 06:11:28 +02:00
sub xmlesc { shift =~ s/&/&amp;/gr =~ s/</&lt;/gr =~ s/>/&gt;/gr }
sub entry {
my ($definition, $notes) = map {xmlesc($_)} @_;
$notes ? "$definition <i>$notes</i>" : $definition;
}
my ($en, $cs, $notes, $special, $translator) = @F;
if ($cs) {
2021-10-07 03:37:12 +02:00
$notes =~ s/\w+:\s?//g; # remove word classes
$notes =~ s/(\w+\.)(?!])/($1)/; # quote "pl."
2021-10-10 06:11:28 +02:00
push(@{$encs{$en}}, entry($cs, $notes));
push(@{$csen{$cs}}, entry($en, $notes));
2021-10-07 03:37:12 +02:00
} END {
2021-10-10 06:11:28 +02:00
w("en-cz", \%encs, "en");
w("cz-en", \%csen, "cs");
2021-10-07 03:37:12 +02:00
}'