Debian Codegraph @

scripts/tmx-explode

raw
1 #!/usr/bin/perl
2
3 # PODNAME: tmx-explode
4 # ABSTRACT: Explodes tmx files in a file per language
5
6 use warnings;
7 use strict;
8
9 use XML::TMX::Reader;
10
11 my @files = grep {-f $_} @ARGV;
12
13 for my $file (@files) {
14 print STDERR "exploding $file..";
15
16 my $reader = XML::TMX::Reader->new($file);
17
18 my $name = $file;
19 $name =~ s/\.tmx//;
20
21 my %fh;
22 my $i = 1;
23 $reader->for_tu(
24 sub {
25 my ($langs) = @_;
26 print STDERR "." unless $i % 10;
27 for my $l (keys %$langs) {
28 next if $l eq "-prop";
29 mkdir $l unless -d $l;
30 $langs->{$l} =~ s/\n/ /g;
31 $langs->{$l} =~ s/\s+/ /g;
32 unless ($fh{$l}) {
33 open $fh{$l}, ">$l/$name";
34 binmode $fh{$l}, ":utf8";
35 }
36 print {$fh{$l}} "$i\t$langs->{$l}\n";
37 }
38 ++$i;
39 },
40 );
41 close $fh{$_} for (keys %fh);
42 print STDERR "DONE\n";
43 }
44
45 __END__
46
47 =pod
48
49 =encoding UTF-8
50
51 =head1 NAME
52
53 tmx-explode - Explodes tmx files in a file per language
54
55 =head1 VERSION
56
57 version 0.39
58
59 =head1 SYNOPSIS
60
61 tmx-explode foo.tmx bar.tmx
62
63 # if foo.tmx and bar.tmx have only PT and EN languages, you will get
64 # \-EN
65 # \-- foo
66 # \-- bar
67 # \-PT
68 # \-- foo
69 # \-- bar
70
71 =head1 DESCRIPTION
72
73 Explodes a set of tmx files, creating a folder per language, and a
74 file per tmx file.
75
76 =head1 AUTHORS
77
78 =over 4
79
80 =item *
81
82 Alberto Simões <[email protected]>
83
84 =item *
85
86 José João Almeida <[email protected]>
87
88 =back
89
90 =head1 COPYRIGHT AND LICENSE
91
92 This software is copyright (c) 2010-2017 by Projeto Natura <[email protected]>.
93
94 This is free software; you can redistribute it and/or modify it under
95 the same terms as the Perl 5 programming language system itself.
96
97 =cut