~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to po/po2ts.pl

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Patrick Matthäi, Mark Purcell
  • Date: 2013-11-30 15:44:59 UTC
  • mfrom: (1.1.16) (2.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20131130154459-s6lpalx8yy2zq7gx
Tags: 3.0.2-1
* New upstream release 

[ Patrick Matthäi ]
* New upstream release.
  - Add new libreadline-dev build dependency.
* Don't explicitly request xz compression - dpkg 1.17 does this by default.
* Bump Standards-Version to 3.9.5 (no changes needed).
* Fix Vcs-Browser control field.

[ Mark Purcell ]
* Switch to dh - reduce debian/rules bloat
* kid3 Replaces kid3-qt - low popcon, reduce archive bloat
* Fix vcs-field-not-canonical
* debian/compat -> 9
* Update Description:

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
package po2ts;
3
3
 
4
4
use strict;
5
 
use File::Basename;
 
5
use Cwd;
6
6
use File::Find;
7
 
use File::Path;
8
7
 
9
8
use vars qw(@ISA @EXPORT);
10
9
require Exporter;
11
10
@ISA = qw(Exporter);
12
11
@EXPORT = qw(generateTs);
13
12
 
14
 
# Read all source files given in the parameter list and copy them to the
15
 
# output directory, replaceing i18n by tr and I18N_NOOP by QT_TRANSLATE_NOOP.
16
 
sub createTranslateSources($@)
17
 
{
18
 
  my $outdir = shift;
19
 
  my $indir = shift;
20
 
  my @sources = @_;
21
 
  my $indirLen = length($indir);
22
 
  foreach my $file (@sources) {
23
 
    open IF, $file or die "Could not open $file: $!\n";
24
 
    my $outfn = $outdir . substr($file, $indirLen);
25
 
    my $outfndir = dirname($outfn);
26
 
    mkpath($outfndir) unless -d $outfndir;
27
 
    open OF, ">$outfn" or die "Could not create $outfn: $!\n";
28
 
    while (<IF>) {
29
 
      s/i18n\(/tr(/g;
30
 
      s/KCM_i18n1\(([^,]+), ([^)]+)\)/tr($1).arg($2)/g;
31
 
      s/KCM_i18n2\(([^,]+), ([^,]+), ([^)]+)\)/tr($1).arg($2).arg($3)/g;
32
 
      s/I18N_NOOP\(/QT_TRANSLATE_NOOP("\@default", /g;
33
 
      print OF $_;
34
 
    }
35
 
    close OF;
36
 
    close IF;
37
 
  }
38
 
}
39
 
 
40
13
# Read all translations from a .po file, fill them into an associative
41
14
# array.
42
15
sub getPoTranslations($)
113
86
      $source =~ s/&lt;/</g;
114
87
      $source =~ s/&gt;/>/g;
115
88
      $source =~ s/&apos;/'/g;
 
89
      $source =~ s/&quot;/\\"/g;
116
90
      $source =~ s/\n/\\n/g;
117
91
      if (exists $trans{$source}) {
118
92
        $translation = $trans{$source};
150
124
  my ($lupdate_cmd, $podir, $srcdir) = @_;
151
125
  my @pofiles = glob "$podir/*.po";
152
126
  my @languages = map { /^.*\/([\w@]+)\.po$/ } @pofiles;
153
 
  my $tmpdir = ".tsdir";
154
 
  mkdir $tmpdir unless -d $tmpdir;
 
127
  my $curdir = cwd();
155
128
  find(\&wanted, $srcdir);
156
 
  createTranslateSources($tmpdir, $srcdir, @sources);
157
 
  chdir $tmpdir or die "Could not change to $tmpdir: $!\n";
158
 
  system "$lupdate_cmd -recursive . -ts " . join ' ', map { "kid3_". $_ . ".ts" } @languages;
159
 
  chdir "..";
 
129
  chdir $srcdir or die "Could not change to $srcdir: $!\n";
 
130
  system "$lupdate_cmd -recursive . -ts " . join ' ', map { "$curdir/tmp_". $_ . ".ts" } @languages;
 
131
  chdir $curdir;
160
132
  foreach my $lang (@languages) {
161
 
    setTsTranslations("$tmpdir/kid3_$lang.ts", "kid3_$lang.ts",
 
133
    setTsTranslations("tmp_$lang.ts", "kid3_$lang.ts",
162
134
                      getPoTranslations("$podir/$lang.po"));
163
135
  }
164
 
  rmtree($tmpdir);
 
136
  unlink map { "tmp_". $_ . ".ts" } @languages;
165
137
}
166
138
 
167
139
if (!caller()) {