~shnatsel/+junk/pkg-kde-tools-backport

« back to all changes in this revision

Viewing changes to kubuntu/lib/libexec/createdesktopcontext.pl

  • Committer: Sergey "Shnatsel" Davidoff
  • Date: 2016-04-18 20:56:33 UTC
  • Revision ID: shnatsel@gmail.com-20160418205633-i7sh6o3o6yzm410a
Initial import of version 0.15.16ubuntu2 from vivid

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env perl
 
2
 
 
3
# Version for KDE4
 
4
 
 
5
use strict;
 
6
use warnings;
 
7
use v5.8.0; # We really want decent Unicode support
 
8
 
 
9
use Getopt::Long;
 
10
 
 
11
sub printdate
 
12
{
 
13
    printf ( "%04i", ( $_[5] + 1900 ) );
 
14
    print "-";
 
15
    printf ( "%02i", $_[4] + 1);
 
16
    print "-";
 
17
    printf ( "%02i", $_[3] );
 
18
    print " ";
 
19
    printf ( "%02i", $_[2] );
 
20
    print ":";
 
21
    printf ( "%02i", $_[1] );
 
22
    print "+0000";
 
23
}
 
24
 
 
25
sub prepare
 
26
{
 
27
    binmode( STDOUT, ":utf8" );
 
28
 
 
29
    my @now = gmtime();
 
30
    print "#, fuzzy\n";
 
31
    print "msgid \"\"\n";
 
32
    print "msgstr \"\"\n";
 
33
    print "\"Project-Id-Version: desktop files\\n\"\n";
 
34
    print "\"Report-Msgid-Bugs-To: http://bugs.kde.org\\n\"\n";
 
35
    print "\"POT-Creation-Date: "; printdate( @now ); print "\\n\"\n";
 
36
    print "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n";
 
37
    print "\"Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n\"\n";
 
38
    print "\"Language-Team: LANGUAGE <kde-i18n-doc\@kde.org>\\n\"\n";
 
39
    print "\"MIME-Version: 1.0\\n\"\n";
 
40
    print "\"Content-Type: text/plain; charset=UTF-8\\n\"\n";
 
41
    print "\"Content-Transfer-Encoding: 8bit\\n\"\n";
 
42
    print "\n\n";
 
43
}
 
44
 
 
45
sub processfiles
 
46
{
 
47
    my ( $files, $basedir) = ( @_ );
 
48
    for my $filename ( @$files )
 
49
    {
 
50
        chomp( $filename );
 
51
        next if -d $filename;
 
52
        open( FH, "<:utf8", $filename ) or warn "Cannot open file $filename";
 
53
    
 
54
        # print STDERR "Processing $filename...\n"; ### DEBUG
 
55
        
 
56
        my $regexp = qr{^(Name|Comment|Language|Keywords|X-KDE-Keywords|About|Description|GenericName|Query|ExtraNames|X-KDE-Submenu)=(.+)};
 
57
 
 
58
        # Context is given by preceeding the entry with # ctxt:... comment.
 
59
        # For example, this:
 
60
        #   # ctxt: Blah blah
 
61
        #   Name=...
 
62
        # ends up as "Name|Blah blah" context in the PO file.
 
63
        my $regexp_ctxt = qr{^\s*#\s*ctxt\s*:\s*(.*?)\s*$};
 
64
    
 
65
        my $context_free = "";
 
66
        while( <FH> )
 
67
        {
 
68
            if ( m/$regexp/o )
 
69
            {
 
70
                my $context = $1;
 
71
                my $msgid = $2;
 
72
                if ($context_free) {
 
73
                    $context = "$context|$context_free";
 
74
                    $context =~ s/\\/\\\\/g;
 
75
                    $context =~ s/\"/\\\"/g;
 
76
                }
 
77
                chomp( $msgid );
 
78
                $msgid =~ s/$regexp//;
 
79
                $msgid =~ s/\\/\\\\/g;
 
80
                $msgid =~ s/\"/\\\"/g;
 
81
                if ($msgid =~ m/ +$/) {
 
82
                   $msgid =~ s/ +$//; # remove trailing spaces
 
83
                   print STDERR "ERROR: white space at the end of $msgid in $filename\n";
 
84
                }
 
85
                if ($msgid =~ m/\r$/) {
 
86
                   $msgid =~ s/[ \r]+$//; # remove trailing space or CR characters
 
87
                   print STDERR "ERROR: CR at the end of $msgid in $filename\n";
 
88
                }
 
89
                $filename =~ s,^$basedir/,,;
 
90
                print "#: $filename:$.\n";
 
91
                print "msgctxt \"$context\"\n";
 
92
                print "msgid \"$msgid\"\n";
 
93
                print "msgstr \"\"\n";
 
94
                print "\n";
 
95
            }
 
96
            # Free context refers only to the immediate next line.
 
97
            # Thus, if next line is not extracted, current context is gone.
 
98
            if ( m/$regexp_ctxt/o ) {
 
99
                $context_free = $1;
 
100
            } else {
 
101
                $context_free = "";
 
102
            }
 
103
        }
 
104
    
 
105
        close( FH );
 
106
    }
 
107
}
 
108
 
 
109
my $onefilelist;
 
110
my $basedir;
 
111
GetOptions ( "file-list=s" => \$onefilelist,
 
112
             "base-dir=s" => \$basedir
 
113
           );
 
114
 
 
115
prepare;
 
116
 
 
117
open( FILELIST, $onefilelist ) or warn ( "Cannot open file list: $onefilelist" );
 
118
my @thislist = <FILELIST>;
 
119
processfiles( \@thislist, $basedir );
 
120
close( FILELIST );
 
121