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

(-)a/gulpfile.js (-4 / +4 lines)
Lines 144-150 const poTypes = Object.keys(poTasks); Link Here
144
144
145
function po_extract_marc (type) {
145
function po_extract_marc (type) {
146
    return src(`koha-tmpl/*-tmpl/*/en/**/*${type}*`, { read: false, nocase: true })
146
    return src(`koha-tmpl/*-tmpl/*/en/**/*${type}*`, { read: false, nocase: true })
147
        .pipe(xgettext('misc/translator/xgettext.pl --charset=UTF-8 -s', `Koha-marc-${type}.pot`))
147
        .pipe(xgettext('misc/translator/xgettext.pl --charset=UTF-8 -F', `Koha-marc-${type}.pot`))
148
        .pipe(dest('misc/translator'))
148
        .pipe(dest('misc/translator'))
149
}
149
}
150
150
Lines 163-169 function po_extract_staff () { Link Here
163
    ];
163
    ];
164
164
165
    return src(globs, { read: false, nocase: true })
165
    return src(globs, { read: false, nocase: true })
166
        .pipe(xgettext('misc/translator/xgettext.pl --charset=UTF-8 -s', 'Koha-staff-prog.pot'))
166
        .pipe(xgettext('misc/translator/xgettext.pl --charset=UTF-8 -F', 'Koha-staff-prog.pot'))
167
        .pipe(dest('misc/translator'))
167
        .pipe(dest('misc/translator'))
168
}
168
}
169
169
Lines 179-185 function po_extract_opac () { Link Here
179
    ];
179
    ];
180
180
181
    return src(globs, { read: false, nocase: true })
181
    return src(globs, { read: false, nocase: true })
182
        .pipe(xgettext('misc/translator/xgettext.pl --charset=UTF-8 -s', 'Koha-opac-bootstrap.pot'))
182
        .pipe(xgettext('misc/translator/xgettext.pl --charset=UTF-8 -F', 'Koha-opac-bootstrap.pot'))
183
        .pipe(dest('misc/translator'))
183
        .pipe(dest('misc/translator'))
184
}
184
}
185
185
Lines 284-290 function po_create_installer_marc21 () { return po_create_type('installer-MARC2 Link Here
284
function po_create_installer_unimarc () { return po_create_type('installer-UNIMARC') }
284
function po_create_installer_unimarc () { return po_create_type('installer-UNIMARC') }
285
285
286
function po_update_type (type) {
286
function po_update_type (type) {
287
    const msgmerge_opts = '--backup=off --quiet --sort-output --update';
287
    const msgmerge_opts = '--backup=off --quiet -F --update';
288
    const cmd = `msgmerge ${msgmerge_opts} <%= file.path %> misc/translator/Koha-${type}.pot`;
288
    const cmd = `msgmerge ${msgmerge_opts} <%= file.path %> misc/translator/Koha-${type}.pot`;
289
    const languages = getLanguages();
289
    const languages = getLanguages();
290
    const globs = languages.map(language => `misc/translator/po/${language}-${type}.po`);
290
    const globs = languages.map(language => `misc/translator/po/${language}-${type}.po`);
(-)a/misc/translator/xgettext.pl (-62 / +76 lines)
Lines 190-262 msgstr "" Link Here
190
190
191
EOF
191
EOF
192
    my $directory_re = quotemeta("$directory/");
192
    my $directory_re = quotemeta("$directory/");
193
    for my $t (string_list) {
193
194
	if ($text{$t}->[0]->type == C4::TmplTokenType::TEXT_PARAMETRIZED) {
194
    for my $t ( keys %text ) {
195
	    my($token, $n) = ($text{$t}->[0], 0);
195
        my @ordered_tokens = sort {
196
        printf $OUTPUT "#. For the first occurrence,\n"
196
                   $a->pathname cmp $b->pathname
197
		    if @{$text{$t}} > 1 && $token->parameters_and_fields > 0;
197
                || $a->line_number cmp $b->line_number
198
	    for my $param ($token->parameters_and_fields) {
198
        } @{$text{$t}};
199
		$n += 1;
199
        my $token = $ordered_tokens[0];
200
		my $type = $param->type;
200
201
		my $subtype = ($type == C4::TmplTokenType::TAG
201
        if ( $token->type == C4::TmplTokenType::TEXT_PARAMETRIZED ) {
202
			&& $param->string =~ /^<input\b/is?
202
            my $n = 0;
203
				$param->attributes->{'type'}->[1]: undef);
203
            printf $OUTPUT "#. For the first occurrence,\n"
204
		my $fmt = TmplTokenizer::_formalize( $param );
204
                if @{ $text{$t} } > 1 && $token->parameters_and_fields > 0;
205
		$fmt =~ s/^%/%$n\$/;
205
            for my $param ( $token->parameters_and_fields ) {
206
		if ($type == C4::TmplTokenType::DIRECTIVE) {
206
                $n += 1;
207
#		    $type = "Template::Toolkit Directive";
207
                my $type    = $param->type;
208
		    $type = $param->string =~ /\[%(.*?)%\]/is? $1: 'ERROR';
208
                my $subtype = ( $type == C4::TmplTokenType::TAG
209
		    my $name = $param->string =~ /\bname=(["']?)([^\s"']+)\1/is?
209
                        && $param->string =~ /^<input\b/is?
210
			    $2: undef;
210
                        $param->attributes->{'type'}->[1] : undef );
211
            printf $OUTPUT "#. %s: %s\n", $fmt,
211
                my $fmt = TmplTokenizer::_formalize($param);
212
			"$type" . (defined $name? " name=$name": '');
212
                $fmt =~ s/^%/%$n\$/;
213
		} else {
213
                if ( $type == C4::TmplTokenType::DIRECTIVE ) {
214
		    my $name = $param->attributes->{'name'};
214
215
            my $value;
215
                    #		    $type = "Template::Toolkit Directive";
216
            $value = $param->attributes->{'value'}
216
                    $type = $param->string =~ /\[%(.*?)%\]/is ? $1 : 'ERROR';
217
			    unless $subtype =~ /^(?:text)$/;
217
                    my $name = $param->string =~ /\bname=(["']?)([^\s"']+)\1/is?
218
            printf $OUTPUT "#. %s: %s\n", $fmt, "type=$subtype"
218
                        $2: undef;
219
			    . (defined $name?  " name=$name->[1]": '')
219
                    printf $OUTPUT "#. %s: %s\n", $fmt,
220
			    . (defined $value? " value=$value->[1]": '');
220
                        "$type" . ( defined $name ? " name=$name" : '' );
221
		}
221
                } else {
222
	    }
222
                    my $name = $param->attributes->{'name'};
223
	} elsif ($text{$t}->[0]->type == C4::TmplTokenType::TAG) {
223
                    my $value;
224
	    my($token) = ($text{$t}->[0]);
224
                    $value = $param->attributes->{'value'}
225
        printf $OUTPUT "#. For the first occurrence,\n"
225
                        unless $subtype =~ /^(?:text)$/;
226
		    if @{$text{$t}} > 1 && $token->parameters_and_fields > 0;
226
                    printf $OUTPUT "#. %s: %s\n", $fmt, "type=$subtype"
227
	    if ($token->string =~ /^<meta\b/is) {
227
                        . ( defined $name  ? " name=$name->[1]"   : '' )
228
		my $type = $token->attributes->{'http-equiv'}->[1];
228
                        . ( defined $value ? " value=$value->[1]" : '' );
229
        print $OUTPUT "#. META http-equiv=$type\n" if defined $type;
229
                }
230
	    } elsif ($token->string =~ /^<([a-z0-9]+)/is) {
230
            }
231
		my $tag = uc($1);
231
        } elsif ( $token->type == C4::TmplTokenType::TAG ) {
232
		my $type = (lc($tag) eq 'input'?
232
            printf $OUTPUT "#. For the first occurrence,\n"
233
			$token->attributes->{'type'}: undef);
233
                if @{ $text{$t} } > 1 && $token->parameters_and_fields > 0;
234
		my $name = $token->attributes->{'name'};
234
            if ( $token->string =~ /^<meta\b/is ) {
235
        printf $OUTPUT "#. %s\n", $tag
235
                my $type = $token->attributes->{'http-equiv'}->[1];
236
		    . (defined $type? " type=$type->[1]": '')
236
                print $OUTPUT "#. META http-equiv=$type\n" if defined $type;
237
		    . (defined $name? " name=$name->[1]": '');
237
            } elsif ( $token->string =~ /^<([a-z0-9]+)/is ) {
238
	    }
238
                my $tag  = uc($1);
239
	} elsif ($text{$t}->[0]->has_js_data) {
239
                my $type = ( lc($tag) eq 'input'?
240
        printf $OUTPUT "#. For the first occurrence,\n" if @{$text{$t}} > 1;
240
                    $token->attributes->{'type'}: undef );
241
        printf $OUTPUT "#. SCRIPT\n";
241
                my $name = $token->attributes->{'name'};
242
	}
242
                printf $OUTPUT "#. %s\n", $tag
243
	my $cformat_p;
243
                   . (defined $type? " type=$type->[1]": '')
244
	for my $token (@{$text{$t}}) {
244
                   . (defined $name? " name=$name->[1]": '');
245
	    my $pathname = $token->pathname;
245
            }
246
	    $pathname =~ s/^$directory_re//os;
246
        } elsif ( $token->has_js_data ) {
247
        $pathname =~ s/^.*\/koha-tmpl\/(.*)$/$1/;
247
            printf $OUTPUT "#. For the first occurrence,\n" if @{ $text{$t} } > 1;
248
        printf $OUTPUT "#: %s:%d\n", $pathname, $token->line_number
248
            printf $OUTPUT "#. SCRIPT\n";
249
		    if defined $pathname && defined $token->line_number;
249
        }
250
	    $cformat_p = 1 if $token->type == C4::TmplTokenType::TEXT_PARAMETRIZED;
250
        my $cformat_p;
251
	}
251
        my $location = {};
252
        for my $token ( @{ $text{$t} } ) {
253
            my $pathname = $token->pathname;
254
            $pathname =~ s/^$directory_re//os;
255
            $pathname =~ s/^.*\/koha-tmpl\/(.*)$/$1/;
256
            push @{ $location->{$pathname} }, $token->line_number
257
                if defined $pathname && defined $token->line_number;
258
            $cformat_p = 1 if $token->type == C4::TmplTokenType::TEXT_PARAMETRIZED;
259
        }
260
261
        for my $pathname ( sort keys %$location ) {
262
            for my $line_number ( @{ $location->{$pathname} } ) {
263
                printf $OUTPUT "#: %s:%d\n", $pathname, $line_number;
264
            }
265
        }
266
252
        printf $OUTPUT "#, c-format\n" if $cformat_p;
267
        printf $OUTPUT "#, c-format\n" if $cformat_p;
253
        printf $OUTPUT "msgid %s\n", TmplTokenizer::quote_po(
268
        printf $OUTPUT "msgid %s\n", TmplTokenizer::quote_po(
254
            TmplTokenizer::string_canon(
269
            TmplTokenizer::string_canon(
255
                TmplTokenizer::charset_convert($t, $charset_in, $charset_out)
270
                TmplTokenizer::charset_convert( $t, $charset_in, $charset_out )
256
            )
271
            )
257
        );
272
        );
258
        printf $OUTPUT "msgstr %s\n\n", (defined $translation{$t}?
273
        printf $OUTPUT "msgstr %s\n\n", (defined $translation{$t}?
259
		TmplTokenizer::quote_po( $translation{$t} ): "\"\"");
274
            TmplTokenizer::quote_po( $translation{$t} ): "\"\"");
260
    }
275
    }
261
}
276
}
262
277
263
- 

Return to bug 34959