/usr/bin/tsv2tmx is in libxml-tmx-perl 0.31-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
### Option varialbes
my $man = 0;
my $help = 0;
my ($sl, $tl);
our $verbose = 1;
my $header = 1;
my $columns = "1,2";
#### ------
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
GetOptions ('help|h' => \$help, 'man' => \$man,
"source=s" => \$sl,
"target=s" => \$tl,
"header" => \$header,
"columns=s" => \$columns,
"verbose|v" => \$verbose)
or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;
##
our ($c1, $c2);
if ($columns =~ /^(\d+),(\d+)$/) {
($c1,$c2) = ($1,$2);
} else {
die "Columns definition should be a pair of integers: 1,2\n";
}
if (!$sl || !$tl) {
if ($header) {
_log ("No source language or target language defined. Guessing!");
my ($l1, $l2) = readLine();
$sl = $l1 unless defined $sl;
$tl = $l2 unless defined $tl;
} else {
die "No header, and one of the source or target languages not defined!\n";
}
$header = 0;
}
readLine() if $header;
use XML::TMX::Writer;
my $tmx = XML::TMX::Writer->new();
$tmx->start_tmx(id => 'tsv2tmx');
my @r;
while (@r = readLine()) {
$tmx->add_tu($sl=>$r[0],$tl=>$r[1]);
}
$tmx->end_tmx();
sub _log {
say STDERR @_ if $verbose;
}
sub readLine {
my $line = <STDIN>;
if ($line) {
chomp $line;
return (split /\t/, $line)[$c1,$c2]
} else {
return ();
}
}
__END__
=encoding utf-8
=head1 NAME
tsv2tmx - Create a TMX from a TSV file
=head1 SYNOPSIS
tsv2tmx [options]
Options:
--help brief help message
--man full documentation
--verbose | -v activated verbose mode
--sl=EN --tl=PT describe source and target language names
--header treat first line as a heading
--columns=1,2 specify which columns to extract
=head1 OPTIONS
=over 8
=item B<--help>
Print a brief help message and exits.
=item B<--man>
Prints the manual page and exits.
=item B<--verbose> | B<-v>
Activates the verbose mode.
=item B<--sl> | B<--tl>
Use these options to specify the names for the source and target
languages.
=item B<--header>
By default this switch is on, and it means that the TSV file
includes a first line with a heading. If no source or target
language names are specified, the first line will be used to
guess them.
=item B<--columns=1,2>
Specify which columns should be extracted. Needs to be a pair
of integers, separated by a comma. Columns indexes start at 0.
Default to C<1,2>.
=back
=head1 DESCRIPTION
Useful to create translation memories from TSV files, that can be
easily exported from spreadsheet software.
=head1
=head1 SEE ALSO
XML::TMX
=head1 AUTHOR
Alberto Simões, C<< <ambs@cpan.org> >>
=head1 COPYRIGHT AND LICENSE
Copyright 2016 by Projecto Natura
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|