[Po4a-devel]Config files enhancement
Nicolas François
nicolas.francois@centraliens.net
Sat, 16 Apr 2005 10:13:51 +0200
--BXVAT5kNtrzKuDFl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Fri, Apr 15, 2005 at 03:38:08PM +0200, Martin Quinson wrote:
> On Fri, Apr 15, 2005 at 01:18:51PM +0200, Jordi Vilalta wrote:
> > Hi,
> >
> > while trying to translate the new website proposal I found the need to add
> > module options in the config files (a longstanding limitation of the po4a
> > script). A posible solution came to my mind: we could define "module
> > aliases". For example, we could define po4aweb to be an alias to the xml
> > module with some options:
> >
> > [po4a_alias: po4aweb] xml -o inline="<a>"
> > [type: po4aweb] index.xml $lang:index.xml.$lang
> >
> > Would it be so difficult to implement it?
>
> What about
> [type: xml] index.xml $lang:index.xml.$lang modopt:inline="<a>"
> ?
It looks a little bit easier to implement.
It has the little drawback that modopt needs to be the last parameter
(it's only a potential drawback for future extension)
> It sounds rather simple to implement, too. It would solve the module option
> issue, as long as you don't want to pass different module options for the
> different languages.
Passing different module options for the different languages may raise the
same issue as the with_non-breking_spaces option: there is a risk that the
POT will differ from one language to the other.
> The schema could be extended a bit for the other cases:
> - language specific module option: modopt_fr and friends?
> - non-module option such as -k to po4a-translate: no idea. Maybe directly:
> [type: xml] index.xml $lang:index.xml.$lang modopt:inline="<a>" -k 40
The attached implementation is really basic. It does not deal with
non-module options. It will also fail if you want to use quotes to specify
a parameter with a space (my_option="parameter with spaces")
Also, modopt has to be the last parameter.
> but that's just an idea, I'd prefere to let this simple case work, play a
> bit with it and add other features afterward, when we really need them.
So, lets get it complicated.
Does anybody know about a command line arguments parser in perl?
(I'm not willing to mess with quotes, apostrophes, escaped quotes, ...)
I will give the non-module options a try.
--
Nekral
--BXVAT5kNtrzKuDFl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="po4a.diff"
Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.26
diff -u -r1.26 po4a
--- po4a 4 Mar 2005 16:40:40 -0000 1.26
+++ po4a 16 Apr 2005 07:49:06 -0000
@@ -321,6 +321,10 @@
} elsif ($cmd =~ m/type: *(.*)/) {
$document{$main}{'format'} = $1;
+ if ($args =~ m/^(.*) modopt:(.*)$/) {
+ $args = $1;
+ $document{$main}{'modopt'} = $2;
+ }
foreach my $arg (split(/ /,$args)) {
die wrap_ref_mod("$config_file:$nb", "",
gettext("Unparsable argument '%s' (%s)."), $arg, $line)
@@ -362,7 +366,15 @@
my $potfile=Locale::Po4a::Po->new();
foreach my $master (keys %document) {
- my $doc=Locale::Po4a::Chooser::new($document{$master}{'format'},%options);
+ my %master_options = %options;
+ foreach (split (/ /, $document{$master}{'modopt'})) {
+ if (m/^([^=]*)=(.*)$/) {
+ $master_options{$1}="$2";
+ } else {
+ $master_options{$_}=1;
+ }
+ }
+ my $doc=Locale::Po4a::Chooser::new($document{$master}{'format'},%master_options);
# We ensure that the generated po will be in utf-8 if the input document
# isn't entirely in ascii
$doc->{TT}{utf_mode} = 1;
@@ -441,7 +453,15 @@
DOC: foreach my $master (sort keys %document) {
next unless defined $document{$master}{$lang};
- my $doc=Locale::Po4a::Chooser::new($document{$master}{'format'} ,%options);
+ my %master_options = %options;
+ foreach (split (/ /, $document{$master}{'modopt'})) {
+ if (m/^([^=]*)=(.*)$/) {
+ $master_options{$1}="$2";
+ } else {
+ $master_options{$_}=1;
+ }
+ }
+ my $doc=Locale::Po4a::Chooser::new($document{$master}{'format'},%master_options);
my (@file_in_name,@po_in_name);
push @file_in_name, $master;
--BXVAT5kNtrzKuDFl--