Bugzilla – Attachment 91931 Details for
Bug 10492
Translation problems with TT directives in po files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10492: Translation problems with TT directives in po files
Bug-10492-Translation-problems-with-TT-directives-.patch (text/plain), 5.28 KB, created by
Nick Clemens (kidclamp)
on 2019-08-02 13:55:58 UTC
(
hide
)
Description:
Bug 10492: Translation problems with TT directives in po files
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2019-08-02 13:55:58 UTC
Size:
5.28 KB
patch
obsolete
>From 07a8964718b6875d7352ef2fb0af9bdbd28b6b28 Mon Sep 17 00:00:00 2001 >From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Date: Sun, 5 May 2019 15:12:15 -0300 >Subject: [PATCH] Bug 10492: Translation problems with TT directives in po > files > >This patch implements the replacement of TTvariables >'[%...%]' with normal placeholders '%s' for text >inside HTML tags (eg. img, meta, input) > >The replacement is done in two files: >* xgettext.pl, used on create/update, so TTvars are not >found on the text to translate (msgid) >* tmpl_proccess3.pl, used on install time, so the correct >translation is found (msgstr) and the right TTvar is put on >the translated text. > >To test: >Before applying the patch >1) Update your favorite language > cd misc/traslator > perl translate update xx-YY > >2) Build a list (ini.txt) of 'msgid' to do a comparison > msgcat --no-wrap --use-first po/xx-YY-*po -o - | egrep "^msgid" | sort > ini.txt > >3) Apply the patch > >4) Update your favorite language, again > cd misc/traslator > perl translate update xx-YY > >5) Build a final list (end.txt) of 'msgid' to do a comparison > msgcat --no-wrap --use-first po/xx-YY-*po -o - | egrep "^msgid" | sort > end.txt > >6) Compare both files, you must find (most) TTvars replaced by '%s' > diff ini.txt end.txt > > for example: > < msgid "Translate item type [% itemtype.itemtype | html %]" > > msgid "Translate item type %s" > > < msgid "Holds on this item: [% item_loo.item_holds | html %] / Total holds on this record: [% item_loo.holds | html -%]" > > msgid "Holds on this item: %s / Total holds on this record: %s" > > < msgid "tag_anchor_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]" > > msgid "tag_anchor_%s_%s%s" > > < msgid "[% innerloo.tag_lib | html %] - Click to Expand this Tag" > > msgid "%s - Click to Expand this Tag" > >7) Translate one of the examples, with more than one variable if >possible, for example this text in xx-YY-staff-prog.po > > msgid "Holds on this item: %s / Total holds on this record: %s" >Check it's not marked as 'fuzzy' > >8) Apply the translation > perl translate install xx-YY > >9) Check the translated string has all variables in the right order > edit koha-tmpl/intranet-tmpl/prog/es-ES/modules/tools/batchMod-edit.tt > around line '187', first '[% item_loo.item_holds | html %]', then > '[% item_loo.holds | html -%]' on this case, > or use another example > >If approved this patch can be backported to current stable >versions. > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > misc/translator/tmpl_process3.pl | 28 ++++++++++++++++++++++------ > misc/translator/xgettext.pl | 5 +++++ > 2 files changed, 27 insertions(+), 6 deletions(-) > >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; > } > } >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10492
:
89365
|
91899
| 91931