diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index 6f4c39e786..58c12b9049 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -59,6 +59,7 @@ sub find_translation ($) { sub text_replace_tag ($$) { my($t, $attr) = @_; my $it; + my @ttvar; # value [tag=input], meta my $tag = lc($1) if $t =~ /^<(\S+)/s; @@ -71,12 +72,27 @@ sub text_replace_tag ($$) { my($key, $val, $val_orig, $order) = @{$attr->{$a}}; #FIXME if ($val =~ /\S/s) { - my $s = find_translation($val); - if ($attr->{$a}->[1] ne $s) { #FIXME - $attr->{$a}->[1] = $s; # FIXME - $attr->{$a}->[2] = ($s =~ /"/s)? "'$s'": "\"$s\""; #FIXME - $translated_p = 1; - } + # for selected attributes replace '[%..%]' with '%s' and remember matches + if ( $a =~ /title|value|alt|content|placeholder/ ) { + while ( $val =~ s/(\[\%.*?\%\])/\%s/ ) { + my $var = $1; + push @ttvar, $1; + } + } + # find translation for transformed attributes + my $s = find_translation($val); + # replace '%s' with original content (in order) on translated string, this is fragile! + if ( $a =~ /title|value|alt|content|placeholder/ and @ttvar ) { + while ( @ttvar ) { + my $var = shift @ttvar; + $s =~ s/\%s/$var/; + } + } + if ($attr->{$a}->[1] ne $s) { #FIXME + $attr->{$a}->[1] = $s; # FIXME + $attr->{$a}->[2] = ($s =~ /"/s)? "'$s'": "\"$s\""; #FIXME + $translated_p = 1; + } } } } diff --git a/misc/translator/xgettext.pl b/misc/translator/xgettext.pl index 0343ed29c2..8890d4252b 100755 --- a/misc/translator/xgettext.pl +++ b/misc/translator/xgettext.pl @@ -124,6 +124,11 @@ sub text_extract { || (ref $attr->{'type'} && $attr->{'type'}->[1] =~ /^(?:hidden|radio|checkbox)$/)); # FIXME my($key, $val, $val_orig, $order) = @{$attr->{$a}}; #FIXME $val = TmplTokenizer::trim $val; + # for selected attributes replace '[%..%]' with '%s' globally + if ( $a =~ /title|value|alt|content|placeholder/ ) { + $val =~ s/\[\%.*?\%\]/\%s/g; + } + # save attribute text for translation remember( $s, $val ) if $val =~ /\S/s; } }