Bugzilla – Attachment 76329 Details for
Bug 15395
Internationalization: plural forms, context, and more
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15395: Extract strings from TT BLOCKs too
Bug-15395-Extract-strings-from-TT-BLOCKs-too.patch (text/plain), 5.19 KB, created by
Julian Maurice
on 2018-06-25 06:33:15 UTC
(
hide
)
Description:
Bug 15395: Extract strings from TT BLOCKs too
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2018-06-25 06:33:15 UTC
Size:
5.19 KB
patch
obsolete
>From c2e47023202ea17cee272b3e9900136787d5fcbc Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Sun, 24 Jun 2018 22:04:56 +0200 >Subject: [PATCH] Bug 15395: Extract strings from TT BLOCKs too > >--- > misc/translator/LangInstaller.pm | 76 ++++++++++++++++++-------------- > 1 file changed, 43 insertions(+), 33 deletions(-) > >diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm >index 141a410dd3..59754a748c 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/misc/translator/LangInstaller.pm >@@ -550,50 +550,60 @@ sub extract_messages_from_templates { > say "Extract messages from $file" if $self->{verbose}; > my $template = read_file("$intranetdir/$file"); > my $data = $parser->parse($template); >- my $document = PPI::Document->new(\$data->{BLOCK}); >+ unless ($data) { >+ warn "Error at $file : " . $parser->error(); >+ next; >+ } > >- # [% t('foo') %] is compiled to $output .= $stash->get(['t', ['foo']]); >- # We try to find all nodes corresponding to keyword (here 't') >- my $nodes = $document->find(sub { >- my ($topnode, $element) = @_; >+ make_path(dirname("$tempdir/$file")); >+ open my $fh, '>', "$tempdir/$file"; > >- # Filter out non-valid keywords >- return 0 unless ($element->isa('PPI::Token::Quote::Single')); >- return 0 unless (grep {$element->content eq qq{'$_'}} @keywords); >+ my @blocks = ($data->{BLOCK}, values %{ $data->{DEFBLOCKS} }); >+ foreach my $block (@blocks) { >+ my $document = PPI::Document->new(\$block); > >- # keyword (e.g. 't') should be the first element of the arrayref >- # passed to $stash->get() >- return 0 if $element->sprevious_sibling; >+ # [% t('foo') %] is compiled to >+ # $output .= $stash->get(['t', ['foo']]); >+ # We try to find all nodes corresponding to keyword (here 't') >+ my $nodes = $document->find(sub { >+ my ($topnode, $element) = @_; > >- return 0 unless $element->snext_sibling >- && $element->snext_sibling->snext_sibling >- && $element->snext_sibling->snext_sibling->isa('PPI::Structure::Constructor'); >+ # Filter out non-valid keywords >+ return 0 unless ($element->isa('PPI::Token::Quote::Single')); >+ return 0 unless (grep {$element->content eq qq{'$_'}} @keywords); > >- # Check that it's indeed a call to $stash->get() >- my $statement = $element->statement->parent->statement->parent->statement; >- return 0 unless grep { $_->isa('PPI::Token::Symbol') && $_->content eq '$stash' } $statement->children; >- return 0 unless grep { $_->isa('PPI::Token::Operator') && $_->content eq '->' } $statement->children; >- return 0 unless grep { $_->isa('PPI::Token::Word') && $_->content eq 'get' } $statement->children; >+ # keyword (e.g. 't') should be the first element of the arrayref >+ # passed to $stash->get() >+ return 0 if $element->sprevious_sibling; > >- return 1; >- }); >+ return 0 unless $element->snext_sibling >+ && $element->snext_sibling->snext_sibling >+ && $element->snext_sibling->snext_sibling->isa('PPI::Structure::Constructor'); > >- next unless $nodes; >+ # Check that it's indeed a call to $stash->get() >+ my $statement = $element->statement->parent->statement->parent->statement; >+ return 0 unless grep { $_->isa('PPI::Token::Symbol') && $_->content eq '$stash' } $statement->children; >+ return 0 unless grep { $_->isa('PPI::Token::Operator') && $_->content eq '->' } $statement->children; >+ return 0 unless grep { $_->isa('PPI::Token::Word') && $_->content eq 'get' } $statement->children; > >- # Write the Perl equivalent of calls to t* functions family, so xgettext >- # can extract the strings correctly >- make_path(dirname("$tempdir/$file")); >- open my $fh, '>', "$tempdir/$file"; >+ return 1; >+ }); >+ >+ next unless $nodes; > >- foreach my $node (@$nodes) { >- my @args = map { >- $_->significant && !$_->isa('PPI::Token::Operator') ? $_->content : () >- } $node->snext_sibling->snext_sibling->find_first('PPI::Statement')->children; >+ # Write the Perl equivalent of calls to t* functions family, so >+ # xgettext can extract the strings correctly >+ foreach my $node (@$nodes) { >+ my @args = map { >+ $_->significant && !$_->isa('PPI::Token::Operator') ? $_->content : () >+ } $node->snext_sibling->snext_sibling->find_first('PPI::Statement')->children; > >- my $keyword = $node->content; >- $keyword =~ s/^'t(.*)'$/__$1/; >+ my $keyword = $node->content; >+ $keyword =~ s/^'t(.*)'$/__$1/; >+ >+ say $fh "$keyword(" . join(', ', @args) . ");"; >+ } > >- say $fh "$keyword(" . join(', ', @args) . ");"; > } > > close $fh; >-- >2.17.1
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 15395
:
45797
|
45798
|
45799
|
46337
|
50023
|
50024
|
50025
|
50026
|
61873
|
61874
|
61875
|
61876
|
61934
|
61935
|
61977
|
62008
|
62041
|
62326
|
62327
|
62328
|
62329
|
62330
|
62331
|
62332
|
62333
|
62335
|
62709
|
65894
|
70974
|
70975
|
70976
|
71940
|
71941
|
71942
|
71943
|
71944
|
71945
|
71946
|
71947
|
71948
|
71949
|
71950
|
71951
|
71952
|
73901
|
73902
|
73903
|
73904
|
73905
|
73906
|
73907
|
73908
|
73909
|
73910
|
73911
|
73912
|
73913
|
76328
|
76329
|
76330
|
77475
|
77476
|
81152
|
81153
|
81154
|
81155
|
81156
|
81157
|
81158
|
81159
|
81167
|
81734
|
81735
|
81736
|
81737
|
81738
|
81739
|
81741
|
81742
|
81743