Subject: | Support in Extract.pm->extract for HTML::FormFu config-files |
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 |
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.',