View | Details | Raw Unified | Return to bug 25067
Collapse All | Expand All

(-)a/misc/translator/xgettext-pref (-10 / +11 lines)
Lines 45-50 display this help and exit Link Here
45
45
46
use Modern::Perl;
46
use Modern::Perl;
47
47
48
use File::Basename;
48
use Getopt::Long;
49
use Getopt::Long;
49
use Locale::PO;
50
use Locale::PO;
50
use Pod::Usage;
51
use Pod::Usage;
Lines 90-103 my $pot = { Link Here
90
for my $file (@files) {
91
for my $file (@files) {
91
    my $pref = LoadFile($file);
92
    my $pref = LoadFile($file);
92
    while ( my ($tab, $tab_content) = each %$pref ) {
93
    while ( my ($tab, $tab_content) = each %$pref ) {
93
        add_po($file, undef, $tab);
94
        add_po(undef, basename($file));
94
95
95
        if ( ref($tab_content) eq 'ARRAY' ) {
96
        if ( ref($tab_content) eq 'ARRAY' ) {
96
            add_prefs( $file, $tab, $tab_content );
97
            add_prefs( $file, $tab, $tab_content );
97
        } else {
98
        } else {
98
            while ( my ($section, $sysprefs) = each %$tab_content ) {
99
            while ( my ($section, $sysprefs) = each %$tab_content ) {
99
                my $context = "$tab > $section";
100
                my $context = "$tab > $section";
100
                add_po($file, $tab, $section);
101
                my $msgid = sprintf('%s %s', basename($file), $section);
102
                add_po($tab, $msgid);
101
                add_prefs( $file, $context, $sysprefs );
103
                add_prefs( $file, $context, $sysprefs );
102
            }
104
            }
103
        }
105
        }
Lines 123-148 sub add_prefs { Link Here
123
                    next unless $key eq 'choices' or $key eq 'multiple';
125
                    next unless $key eq 'choices' or $key eq 'multiple';
124
                    next unless ref($value) eq 'HASH';
126
                    next unless ref($value) eq 'HASH';
125
                    for my $ckey ( keys %$value ) {
127
                    for my $ckey ( keys %$value ) {
126
                        add_po( $file, "$context > $pref_name", $value->{$ckey} );
128
                        my $msgid = sprintf('%s#%s# %s', basename($file), $pref_name, $value->{$ckey});
129
                        add_po( "$context > $pref_name", $msgid );
127
                    }
130
                    }
128
                }
131
                }
129
            }
132
            }
130
            elsif ($element) {
133
            elsif ($element) {
131
                add_po( $file, "$context > $pref_name", $element );
134
                my $msgid = sprintf('%s#%s# %s', basename($file), $pref_name, $element);
135
                add_po( "$context > $pref_name", $msgid );
132
            }
136
            }
133
        }
137
        }
134
    }
138
    }
135
}
139
}
136
140
137
sub add_po {
141
sub add_po {
138
    my ( $reference, $msgctxt, $msgid ) = @_;
142
    my ($comment, $msgid ) = @_;
139
143
140
    return unless $msgid;
144
    return unless $msgid;
141
145
142
    my $key = ($msgctxt // '') . ";$msgid";
146
    $pot->{$msgid} = Locale::PO->new(
143
    $pot->{$key} = Locale::PO->new(
147
        -comment   => $comment,
144
        -reference => $reference,
145
        -msgctxt   => $msgctxt,
146
        -msgid     => $msgid,
148
        -msgid     => $msgid,
147
        -msgstr    => '',
149
        -msgstr    => '',
148
    );
150
    );
149
- 

Return to bug 25067