1.1.43
by Jonathan Riddell
Import upstream version 4.4.80 |
1 |
#! /usr/bin/env perl
|
2 |
||
3 |
# Copyright (c) 2010 Volker Krause <vkrause@kde.org>
|
|
4 |
# based on extractrc by:
|
|
5 |
# Copyright (c) 2004 Richard Evans <rich@ridas.com>
|
|
6 |
||
7 |
sub usage |
|
8 |
{
|
|
9 |
warn <<"EOF"; |
|
10 |
||
11 |
extractqml [flags] filenames
|
|
12 |
||
13 |
This script extracts messages from QML files writes on standard output
|
|
14 |
(usually redirected to rc.cpp) the equivalent i18n() calls so that
|
|
15 |
xgettext can parse them.
|
|
16 |
||
17 |
--ignore-no-input : Do not warn if there were no filenames specified
|
|
18 |
--help|? : Display this summary
|
|
19 |
||
20 |
EOF
|
|
21 |
||
22 |
exit; |
|
23 |
}
|
|
24 |
||
25 |
###########################################################################################
|
|
26 |
||
27 |
use strict; |
|
28 |
use warnings; |
|
29 |
use Getopt::Long; |
|
30 |
use Data::Dumper; |
|
31 |
||
32 |
###########################################################################################
|
|
33 |
# Add options here as necessary - perldoc Getopt::Long for details on GetOptions
|
|
34 |
||
35 |
GetOptions ( "ignore-no-input" => \my $opt_ignore_no_input, |
|
36 |
"help|?" => \&usage ); |
|
37 |
||
38 |
unless( @ARGV ) |
|
39 |
{
|
|
40 |
warn "No filename specified" unless $opt_ignore_no_input; |
|
41 |
exit; |
|
42 |
}
|
|
43 |
||
44 |
###########################################################################################
|
|
45 |
||
1.1.45
by Alessandro Ghersi
Import upstream version 4.4.90 |
46 |
# We check for lines like:
|
47 |
#
|
|
48 |
# vvvv
|
|
49 |
# KDE.i18n( "single message", 2, test, "another string" )
|
|
50 |
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
51 |
# match the first expression to know the function (i18n, i18nc, i18np, i18ncp)
|
|
52 |
# match the second expression to know the arguments for that function
|
|
53 |
#
|
|
54 |
# NOTE: this is a "hackish" solution that works if the function calls we
|
|
55 |
# want to # match are regular enough. If more complicated patterns start to
|
|
56 |
# happen maybe we need to find another solution.
|
|
57 |
||
58 |
my $double_string = qr/ (?: \" (?: \\ \" | .)* \") /x; |
|
59 |
my $single_string = qr/ (?: ' (?: \\ ' | .)* ') /x; |
|
60 |
my $string = qr/ (?: $double_string | $single_string) /x; |
|
61 |
my $simple_expression = qr/ [^,\)]* [^,\s\)] /x; |
|
62 |
my $arguments = qr/ $string (?: \s* , \s* (?: $string | $simple_expression ) )* /x; |
|
63 |
||
64 |
my $match_i18n = qr/ KDE \. ( i18nc?p? ) \s* \( \s* ( $arguments ) \s* \) /x; |
|
65 |
||
66 |
||
1.1.43
by Jonathan Riddell
Import upstream version 4.4.80 |
67 |
for my $file_name ( @ARGV ) |
68 |
{
|
|
69 |
my $fh; |
|
70 |
||
71 |
unless ( open $fh, "<", $file_name ) |
|
72 |
{
|
|
73 |
# warn "Failed to open: '$file_name': $!";
|
|
74 |
next; |
|
75 |
}
|
|
76 |
||
1.1.45
by Alessandro Ghersi
Import upstream version 4.4.90 |
77 |
# Trick to read the entire file contents
|
78 |
my $contents = do { local $/; <$fh> }; |
|
79 |
||
80 |
while ( $contents =~ m/$match_i18n/gx ) { |
|
81 |
print "$1($2);\n"; |
|
1.1.43
by Jonathan Riddell
Import upstream version 4.4.80 |
82 |
}
|
83 |
||
84 |
close $fh or warn "Failed to close: '$file_name': $!"; |
|
85 |
}
|