[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with bash script to translate @ref{} items in translated manual
From: |
Andrew Bernard |
Subject: |
Re: help with bash script to translate @ref{} items in translated manuals |
Date: |
Sat, 22 Apr 2017 13:37:55 +1000 |
Hi Federico,
I believe you are trying to automate a set of translations, correct? If so,
here's a way to do it in perl that avoids all the shell convolutions. I
assume you do know perl. If not, always worth knowing for this sort of
quick work.
Just add the translations to the hash table in the script. The virtue of
this small tool is that it will tell you if you missed any.
Reads file from stdin. Outputs to stdout. You can figure how to process the
whole directory. There's a hundred ways to do this. Some people like to
open all the files in the perl script. I prefer to keep it simple.
Hope this may be useful for now and in the future.
Andrew
== snip
#!/usr/bin/perl
use strict;
use warnings;
my @ref;
# translation table
my %translations = (
'Automatic beams' => 'Automatic Beams in Italian',
'Stems' => 'Stems in Italian',
);
while (<>) {
if (@ref = /address@hidden(.+)\}/) {
if (exists $translations{$ref[0]}) {
s/$ref[0]/$translations{$ref[0]}/;
}
else {
print STDERR "no translation for $ref[0]", "\n";
}
}
print;
}
== snip
Re: help with bash script to translate @ref{} items in translated manuals,
Andrew Bernard <=