Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Locale-Maketext-Lexicon CPAN distribution.

Report information
The Basics
Id: 33166
Status: resolved
Priority: 0/
Queue: Locale-Maketext-Lexicon

People
Owner: Nobody in particular
Requestors: andreas.marienborg [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.65
Fixed in: (no value)



Subject: Support in Extract.pm->extract for HTML::FormFu config-files
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Charset: utf8
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1202814955-22054-19"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 388
Download (untitled) / with headers
text/plain 388b
I use HTML::FormFu for generating forms in my web application, and it has built in support for localizing labels, comments, errors etc. This patch add support to Locale::Maketext::Extract (and thus xgettext.pl) for the format used by the config-files. It also adds one test to test the extraction, and some pod. The patch is against dist version 0.65 (0.22 of Locale::Maketext::Extract)
Subject: locale-maketext-extract-formfu-support.01.diff
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1202814955-22054-18"
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="locale-maketext-extract-formfu-support.01.diff"
Content-Disposition: inline; filename="locale-maketext-extract-formfu-support.01.diff"
Content-Transfer-Encoding: base64
Content-Length: 2057
diff -ur Locale-Maketext-Lexicon-0.65.orig/lib/Locale/Maketext/Extract.pm Locale-Maketext-Lexicon-0.65/lib/Locale/Maketext/Extract.pm --- Locale-Maketext-Lexicon-0.65.orig/lib/Locale/Maketext/Extract.pm 2008-02-12 11:28:48.000000000 +0100 +++ Locale-Maketext-Lexicon-0.65/lib/Locale/Maketext/Extract.pm 2008-02-12 12:10:51.000000000 +0100 @@ -51,6 +51,14 @@ Sentences between C<STARTxxx> and C<ENDxxx> are extracted individually. +=item HTML::FormFu + +HTML::FormFu uses a config-file to generate forms, with built in +support for localizing errors, labels etc. + +We extract the text after C<_loc: >: + content_loc: this is the string + =item Generic Template Strings inside {{...}} are extracted. @@ -234,6 +242,14 @@ $self->add_entry($str, [ $file, $line, $vars ]); } + # HTML::FormFu config-files + $line = 1; pos($_) = 0; + while (m/\G(.*?_loc:\s+(.*))/sg) { + my ($str) = $2; + $line += ( () = ($1 =~ /\n/g) ); # crypto something + $self->add_entry($str, [ $file, $line ]); + } + # Generic Template: $line = 1; pos($_) = 0; while (m/\G(.*?(?<!\{)\{\{(?!\{)(.*?)\}\})/sg) { diff -ur Locale-Maketext-Lexicon-0.65.orig/t/5-extract.t Locale-Maketext-Lexicon-0.65/t/5-extract.t --- Locale-Maketext-Lexicon-0.65.orig/t/5-extract.t 2008-02-12 11:28:48.000000000 +0100 +++ Locale-Maketext-Lexicon-0.65/t/5-extract.t 2008-02-12 12:09:22.000000000 +0100 @@ -1,7 +1,7 @@ #! /usr/bin/perl -w use lib '../lib'; use strict; -use Test::More tests => 28; +use Test::More tests => 29; use_ok('Locale::Maketext::Extract'); my $Ext = Locale::Maketext::Extract->new; @@ -44,6 +44,8 @@ extract_ok(q(_(q{foo\\\\bar})) => 'foo\\bar', 'Normalized \\\\ in q'); extract_ok(q(_(qq{foo\bar})) => "foo\bar", 'Interpolated \b in qq'); +# HTML::FormFu test +extract_ok(' content_loc: foo bar' => "foo bar", "html-formfu extraction"); extract_ok( q(my $x = loc('I "think" you\'re a cow.') . "\n";) => 'I "think" you\'re a cow.',
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-22069-1202822589-1658.33166-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 49
Thanks, applied and released as LML 0.66. Audrey
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Charset: utf8
Message-Id: <rt-3.6.HEAD-22040-1202825634-386.33166-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1202825634-22040-13"
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 167
Download (untitled) / with headers
text/plain 167b
After testing some more, I found some issues with my last patch. It basicly mucks up if there are several lines :/ I have written some more testcases, and a new patch.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Type: multipart/mixed; boundary="----------=_1202825634-22040-12"
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="locale-maketext-extract-formfu-support.02.diff"
Content-Disposition: inline; filename="locale-maketext-extract-formfu-support.02.diff"
Content-Transfer-Encoding: base64
Content-Length: 3210
Only in Locale-Maketext-Lexicon-0.65: Makefile Only in Locale-Maketext-Lexicon-0.65: blib diff -ur Locale-Maketext-Lexicon-0.65.orig/lib/Locale/Maketext/Extract/Run.pm Locale-Maketext-Lexicon-0.65/lib/Locale/Maketext/Extract/Run.pm --- Locale-Maketext-Lexicon-0.65.orig/lib/Locale/Maketext/Extract/Run.pm 2008-02-12 11:28:47.000000000 +0100 +++ Locale-Maketext-Lexicon-0.65/lib/Locale/Maketext/Extract/Run.pm 2008-02-12 12:48:44.000000000 +0100 @@ -52,6 +52,7 @@ foreach my $file (@{$opts{f}||[]}) { open FILE, $file or die "Cannot open $file: $!"; while (<FILE>) { + chomp; push @ARGV, $_ if -r and !-d; } } diff -ur Locale-Maketext-Lexicon-0.65.orig/lib/Locale/Maketext/Extract.pm Locale-Maketext-Lexicon-0.65/lib/Locale/Maketext/Extract.pm --- Locale-Maketext-Lexicon-0.65.orig/lib/Locale/Maketext/Extract.pm 2008-02-12 11:28:48.000000000 +0100 +++ Locale-Maketext-Lexicon-0.65/lib/Locale/Maketext/Extract.pm 2008-02-12 15:05:10.000000000 +0100 @@ -51,6 +51,14 @@ Sentences between C<STARTxxx> and C<ENDxxx> are extracted individually. +=item HTML::FormFu + +HTML::FormFu uses a config-file to generate forms, with built in +support for localizing errors, labels etc. + +We extract the text after C<_loc: >: + content_loc: this is the string + =item Generic Template Strings inside {{...}} are extracted. @@ -234,6 +242,14 @@ $self->add_entry($str, [ $file, $line, $vars ]); } + # HTML::FormFu config-files + $line = 1; pos($_) = 0; + while (m/\G(.*?_loc:\s+(.*?)($|\n))/sg) { + my ($str) = $2; + $line += ( () = ($1 =~ /\n/g) ); # crypto something + $self->add_entry($str, [ $file, $line ]); + } + # Generic Template: $line = 1; pos($_) = 0; while (m/\G(.*?(?<!\{)\{\{(?!\{)(.*?)\}\})/sg) { Only in Locale-Maketext-Lexicon-0.65: pm_to_blib diff -ur Locale-Maketext-Lexicon-0.65.orig/t/5-extract.t Locale-Maketext-Lexicon-0.65/t/5-extract.t --- Locale-Maketext-Lexicon-0.65.orig/t/5-extract.t 2008-02-12 11:28:48.000000000 +0100 +++ Locale-Maketext-Lexicon-0.65/t/5-extract.t 2008-02-12 15:05:33.000000000 +0100 @@ -1,7 +1,7 @@ #! /usr/bin/perl -w use lib '../lib'; use strict; -use Test::More tests => 28; +use Test::More tests => 33; use_ok('Locale::Maketext::Extract'); my $Ext = Locale::Maketext::Extract->new; @@ -45,6 +45,13 @@ extract_ok(q(_(qq{foo\bar})) => "foo\bar", 'Interpolated \b in qq'); +# HTML::FormFu test +extract_ok(' content_loc: foo bar' => "foo bar", "html-formfu extraction"); +extract_ok(" content_loc: foo bar\n attributes: somethingelse" => 'foo bar', 'html-formfu extraction with newline'); +extract_ok(" content_loc: foo bar's" => "foo bar's", "html formfu extraction with quotes"); +extract_ok(" content_loc: foo\" bar", => 'foo" bar', "html formu extraciton with escaped quotes"); +extract_ok(" content_loc: foo bar\nvalue_loc: another_location" => 'foo baranother_location', "html formfu multiple extration"); + extract_ok( q(my $x = loc('I "think" you\'re a cow.') . "\n";) => 'I "think" you\'re a cow.', "Handle escaped single quotes"
MIME-Version: 1.0
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Charset: utf8
Message-Id: <rt-3.6.HEAD-13838-1221832799-1652.33166-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1221832799-13838-22"
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 803
Download (untitled) / with headers
text/plain 803b
I notice the HTML-FormFu support is still broken. Note that it isn't really specific to HTML-FormFu - this can be used for any YAML file that uses a hash-key ending in "_loc" to identify a L10N string. I've rewritten the support, so that instead of using a regex to try to parse YAML - it now uses YAML.pm and Data::Visitor::Callback. Any file whose first non-comment line is the yaml start-of-document marker "---" will be treated as a YAML file. Taking the existing code to handle Text::Template as a precedent - I've not added YAML or Data::Visitor::Callback to the Makefile.PL prereqs - the modules are only require()d if a YAML filetype is encountered. Though if you're OK with these modules being added to the prereqs - I'll happily provide an updated patch to do that, and to add tests. Carl
MIME-Version: 1.0
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Content-Type: multipart/mixed; boundary="----------=_1221832799-13838-21"
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: text/x-patch; name="extract.patch"
Content-Disposition: inline; filename="extract.patch"
Content-Transfer-Encoding: binary
Content-Length: 2579
Download extract.patch
text/x-diff 2.5k
Index: t/5-extract.t =================================================================== --- t/5-extract.t (revision 1) +++ t/5-extract.t (working copy) @@ -1,7 +1,7 @@ #! /usr/bin/perl -w use lib '../lib'; use strict; -use Test::More tests => 43; +use Test::More tests => 42; use_ok('Locale::Maketext::Extract'); my $Ext = Locale::Maketext::Extract->new; @@ -44,9 +44,6 @@ extract_ok(q(_(q{foo\\\\bar})) => 'foo\\bar', 'Normalized \\\\ in q'); extract_ok(q(_(qq{foo\bar})) => "foo\bar", 'Interpolated \b in qq'); -# HTML::FormFu test -extract_ok(' content_loc: foo bar' => "foo bar", "html-formfu extraction"); - extract_ok( q(my $x = loc('I "think" you\'re a cow.') . "\n";) => 'I "think" you\'re a cow.', "Handle escaped single quotes" Index: lib/Locale/Maketext/Extract.pm =================================================================== --- lib/Locale/Maketext/Extract.pm (revision 1) +++ lib/Locale/Maketext/Extract.pm (working copy) @@ -244,6 +244,36 @@ $_ = ''; } + # YAML stream + my $yaml_doc = qr/ + ^ + (?: \s*? \# [^\n]*\n )* # any number of comment lines + ---\n # start of stream + /x; + + if ( $_ =~ $yaml_doc ) { + require YAML; + require Data::Visitor::Callback; + + my $data_visitor = Data::Visitor::Callback->new( + ignore_return_values => 1, + hash => sub { + my ( $visitor, $data ) = @_; + while ( my ( $key, $value ) = each %$data ) { + if ( $key =~ /_loc\z/ ) { + $self->add_entry( $value, [$file, $line] ); + } + } + }, + ); + + for my $document ( YAML::Load($_) ) { + $data_visitor->visit($document); + } + + $_ = ''; + } + # HTML::Mason $line = 1; pos($_) = 0; while (m!\G(.*?<&\|/l(?:oc)?(.*?)&>(.*?)</&>)!sg) { @@ -263,16 +293,8 @@ $trim_start && $str =~ s/^\s+//; $trim_end && $str =~ s/\s+$//; $self->add_entry($str, [ $file, $line, $vars ]); - } + } - # HTML::FormFu config-files - $line = 1; pos($_) = 0; - while (m/\G(.*?_loc:\s+(.*))/sg) { - my ($str) = $2; - $line += ( () = ($1 =~ /\n/g) ); # cryptocontext! - $self->add_entry($str, [ $file, $line ]); - } - # Generic Template: $line = 1; pos($_) = 0; while (m/\G(.*?(?<!\{)\{\{(?!\{)(.*?)\}\})/sg) {
CC: undisclosed-recipients: ;
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-13838-1221832799-1652.33166-5-0 [...] rt.cpan.org>
Content-Disposition: inline
References: <RT-Ticket-33166 [...] rt.cpan.org> <rt-3.6.HEAD-13838-1221832799-1652.33166-5-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
Received: from 31b.bestpractical.com (diesel.bestpractical.com [127.0.0.1]) by diesel.bestpractical.com (Postfix) with ESMTP id 07E6123C0E5; Tue, 23 Sep 2008 18:40:57 -0400 (EDT)
Received: by 31b.bestpractical.com (Postfix, from userid 501) id EE22C6F10B3; Tue, 23 Sep 2008 15:01:49 -0400 (EDT)
Delivered-To: cpan-bug+Locale-Maketext-Lexicon [...] diesel.bestpractical.com
User-Agent: Mutt/1.5.18 (2008-05-17)
Subject: Re: [rt.cpan.org #33166] Support in Extract.pm->extract for HTML::FormFu config-files
Return-Path: <jesse [...] bestpractical.com>
X-Original-To: bug-Locale-Maketext-Lexicon [...] rt.cpan.org
Date: Tue, 23 Sep 2008 15:01:49 -0400
Message-Id: <20080923190149.GA69042 [...] 31b.local>
To: Carl Franks via RT <bug-Locale-Maketext-Lexicon [...] rt.cpan.org>
From: Jesse Vincent <jesse [...] fsck.com>
RT-Message-ID: <rt-3.6.HEAD-31395-1222209713-11.33166-0-0 [...] rt.cpan.org>
Content-Length: 1311
Download (untitled) / with headers
text/plain 1.2k
I can't speak for the other authors, but making YAML and Data::Visitor::Callback a dependency doesn't feel quite right. Is there any chance you could set up your tests to compare expected results textually? Your patch also didn't apply cleanly against SVN (and seems to remove a test :/) On Fri 19.Sep'08 at 10:00:09 -0400, Carl Franks via RT wrote: Show quoted text
> Queue: Locale-Maketext-Lexicon > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=33166 > > > I notice the HTML-FormFu support is still broken. > Note that it isn't really specific to HTML-FormFu - this can be used for > any YAML file that uses a hash-key ending in "_loc" to identify a L10N > string. > > I've rewritten the support, so that instead of using a regex to try to > parse YAML - it now uses YAML.pm and Data::Visitor::Callback. > > Any file whose first non-comment line is the yaml start-of-document > marker "---" will be treated as a YAML file. > > Taking the existing code to handle Text::Template as a precedent - I've > not added YAML or Data::Visitor::Callback to the Makefile.PL prereqs - > the modules are only require()d if a YAML filetype is encountered. > Though if you're OK with these modules being added to the prereqs - I'll > happily provide an updated patch to do that, and to add tests. > > Carl >
--
MIME-Version: 1.0
X-Mailer: MIME-tools 5.426 (Entity 5.426)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-27688-1223899159-1950.33166-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 74
No longer relevant, since the extract-stuff now is refactored into plugins


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.