Skip Menu |
 
rt.cpan.org will be shut down on March 1st, 2021.

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: 39292
Status: resolved
Priority: 0/
Queue: Locale-Maketext-Lexicon

People
Owner: Nobody in particular
Requestors: felix.ostmann [...] thewar.de
Cc:
AdminCc:

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



Subject: Parsing formfu config
Download (untitled) / with headers
text/plain 226b
Can someone plz check the formfu-config parsing? i parsed the Extract.pm for localization and get one string from the formfu-config-excample till the end of the line. Is this correct? i dont think so after reading the pod :-/
Download (untitled) / with headers
text/plain 863b
On Mon Sep 15 09:38:23 2008, Sadrak wrote: Show quoted text
> Can someone plz check the formfu-config parsing? > > i parsed the Extract.pm for localization and get one string from the > formfu-config-excample till the end of the line. Is this correct? i dont > think so after reading the pod :-/
I have attached 3 files: - locale-maketext-lexicon-formfu-tests.diff 1 changed and 2 new tests in one patch, which gives failures today (because the regexp is to greedy). - locale-maketext-lexicon-formfu-simple-fix.diff Simply fixing the regex-solution that is there today, to be non-greedy and properly work with more than one _loc: entry - locale-maketext-lexicon-formfu-extract.diff Which reimplements the formfu-plugin to use Data::Visitor::Callback. I did not use the YAML-plugin as a base simply because I couldn't figure out how to get both key and value at the same time.
diff -ura ../Locale-Maketext-Lexicon-0.71.orig/t/5-extract.t ./t/5-extract.t --- ../Locale-Maketext-Lexicon-0.71.orig/t/5-extract.t 2008-10-13 14:06:46.000000000 +0200 +++ ./t/5-extract.t 2008-10-13 15:28:00.000000000 +0200 @@ -1,7 +1,7 @@ #! /usr/bin/perl -w use lib '../lib'; use strict; -use Test::More tests => 76; +use Test::More tests => 78; use_ok('Locale::Maketext::Extract'); my $Ext = Locale::Maketext::Extract->new(); @@ -45,7 +45,27 @@ 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(<<"__YAML__" => "foo bar", "html-formfu extraction"); +--- + content_loc: foo bar + +__YAML__ + +extract_ok(<<"__YAML__" => 'foo barsomething else as well', 'html-formfu extraction'); +--- + content_loc: foo bar + name: something else + value_loc: something else as well +__YAML__ + + +extract_ok(<<"__YAML__" => 'foo barsomething else as well', 'html-formfu extraction'); +--- + content_loc: foo bar + name: something else +--- + value_loc: something else as well +__YAML__ extract_ok( q(my $x = loc('I "think" you\'re a cow.') . "\n";) => 'I "think" you\'re a cow.',
diff -ura ../Locale-Maketext-Lexicon-0.71.orig/lib/Locale/Maketext/Extract/Plugin/FormFu.pm lib/Locale/Maketext/Extract/Plugin/FormFu.pm --- ../Locale-Maketext-Lexicon-0.71.orig/lib/Locale/Maketext/Extract/Plugin/FormFu.pm 2008-10-13 14:06:46.000000000 +0200 +++ lib/Locale/Maketext/Extract/Plugin/FormFu.pm 2008-10-13 15:31:01.000000000 +0200 @@ -48,8 +48,8 @@ sub extract { my $self = shift; local $_ = shift; - my$line = 1; - while (m/\G(.*?_loc:\s+(.*))/sg) { + my$line = 0; + while (m/\G(.*?_loc:\s+(.*?)\n)/sg) { my ($str) = $2; $line += ( () = ($1 =~ /\n/g) ); # cryptocontext! $self->add_entry($str, $line );
diff -ura ../Locale-Maketext-Lexicon-0.71.orig/lib/Locale/Maketext/Extract/Plugin/FormFu.pm ../Locale-Maketext-Lexicon-0.71/lib/Locale/Maketext/Extract/Plugin/FormFu.pm --- ../Locale-Maketext-Lexicon-0.71.orig/lib/Locale/Maketext/Extract/Plugin/FormFu.pm 2008-10-13 14:06:46.000000000 +0200 +++ ../Locale-Maketext-Lexicon-0.71/lib/Locale/Maketext/Extract/Plugin/FormFu.pm 2008-10-13 15:18:55.000000000 +0200 @@ -41,22 +41,42 @@ =cut -sub file_types { - return qw( * ); -} +use YAML; +use Data::Visitor::Callback; + +use Data::Dump qw/dump/; sub extract { my $self = shift; - local $_ = shift; - my$line = 1; - while (m/\G(.*?_loc:\s+(.*))/sg) { - my ($str) = $2; - $line += ( () = ($1 =~ /\n/g) ); # cryptocontext! - $self->add_entry($str, $line ); + + # parse the YAML + my $data = shift; + my @docs = Load($data); + + my $walker = Data::Visitor::Callback->new( + hash => sub { + my ($visitor, $value) = @_; + my @keys = grep { /_loc$/ } keys(%$value); + if (scalar(@keys)) { + foreach my $k (@keys) { + + $self->add_entry($value->{$k}); + + } + } + }, + ); + + foreach my $doc (@docs) { + # walk it, looking for the right type of key + $walker->visit($doc); } + #$self->add_entry($str, $line ); } + + =head1 SEE ALSO =over 4
Download (untitled) / with headers
text/plain 1.3k
On Mon Oct 13 09:34:09 2008, ANDREMAR wrote: Show quoted text
> On Mon Sep 15 09:38:23 2008, Sadrak wrote:
> > Can someone plz check the formfu-config parsing? > > > > i parsed the Extract.pm for localization and get one string from the > > formfu-config-excample till the end of the line. Is this correct? i dont > > think so after reading the pod :-/
No, you're correct :) Show quoted text
> > - locale-maketext-lexicon-formfu-simple-fix.diff > Simply fixing the regex-solution that is there today, to be non-greedy > and properly work with more than one _loc: entry
This won't work for any multiline values - think folded or block scalars. Show quoted text
> > - locale-maketext-lexicon-formfu-extract.diff > Which reimplements the formfu-plugin to use Data::Visitor::Callback. I > did not use the YAML-plugin as a base simply because I couldn't figure > out how to get both key and value at the same time.
Unfortunately, your Data::Visitor::Callback doesn't give the line numbers for the extracted strings. And yes, YAML::Loader does make it difficult to find the key name. I've had a bash at rewriting Locale::Maketext::Extract::Plugin::FormFu as a subclass of YAML, and I think it now works well. I've included your tests, plus a few more, and it all seems to work. Please try out the attached version, and let me know if you see any problems. Check for line numbers as well. thanks Clint
Download FormFu.pm
text/x-perl 2.7k
package Locale::Maketext::Extract::Plugin::FormFu; use strict; use base qw(Locale::Maketext::Extract::Plugin::Base); =head1 NAME Locale::Maketext::Extract::Plugin::FormFu - FormFu format parser =head1 SYNOPSIS $plugin = Locale::Maketext::Extract::Plugin::FormFu->new( $lexicon # A Locale::Maketext::Extract object @file_types # Optionally specify a list of recognised file types ) $plugin->extract($filename,$filecontents); =head1 DESCRIPTION HTML::FormFu uses a config-file to generate forms, with built in support for localizing errors, labels etc. =head1 SHORT PLUGIN NAME formfu =head1 VALID FORMATS We extract the text after _loc: content_loc: this is the string =head1 KNOWN FILE TYPES =over 4 =item All file types =back =cut sub file_types { return qw( * ); } sub extract { my $self = shift; local $_ = shift; my$line = 1; while (m/\G(.*?_loc:\s+(.*))/sg) { my ($str) = $2; $line += ( () = ($1 =~ /\n/g) ); # cryptocontext! $self->add_entry($str, $line ); } } =head1 SEE ALSO =over 4 =item L<xgettext.pl> for extracting translatable strings from common template systems and perl source files. =item L<Locale::Maketext::Lexicon> =item L<Locale::Maketext::Plugin::Base> =item L<Locale::Maketext::Plugin::Perl> =item L<Locale::Maketext::Plugin::TT2> =item L<Locale::Maketext::Plugin::YAML> =item L<Locale::Maketext::Plugin::Mason> =item L<Locale::Maketext::Plugin::TextTemplate> =item L<Locale::Maketext::Plugin::Generic> =back =head1 AUTHORS Audrey Tang E<lt>cpan@audreyt.orgE<gt> =head1 COPYRIGHT Copyright 2002-2008 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>. This software is released under the MIT license cited below. =head2 The "MIT" License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =cut 1;
Download (untitled) / with headers
text/plain 479b
Show quoted text
> > I've had a bash at rewriting Locale::Maketext::Extract::Plugin::FormFu > as a subclass of YAML, and I think it now works well. > > I've included your tests, plus a few more, and it all seems to work. > Please try out the attached version, and let me know if you see any > problems. Check for line numbers as well. >
Damn, I've just realised I uploaded the old version, not my new test version, which I have now deleted. I'll rewrite it when I get a chance. sorry Clint
Download (untitled) / with headers
text/plain 320b
Show quoted text
> Damn, I've just realised I uploaded the old version, not my new test > version, which I have now deleted. > > I'll rewrite it when I get a chance.
I've rewritten the FormFu parser to use YAML.pm and released it in version 0.77. Please try it out and open a new bug if you have any problems with it. thanks Clint


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.