[Po4a-commits] po4a po4a,1.21,1.22

Jordi Vilalta po4a-devel@lists.alioth.debian.org
Fri, 11 Feb 2005 10:18:23 +0000


Update of /cvsroot/po4a/po4a
In directory haydn:/tmp/cvs-serv4449

Modified Files:
	po4a 
Log Message:
Added support for language templates in config files


Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- po4a	5 Feb 2005 13:03:22 -0000	1.21
+++ po4a	11 Feb 2005 10:18:21 -0000	1.22
@@ -49,6 +49,17 @@
 All non blank lines must begin with a [] command, followed by its arguments. 
 (sound difficult said that way, but it is rather easy, I hope ;)
 
+=head2 Specifying the template languages
+
+This is an optional command that can simplify the whole config file, and will
+make it more scalable. You have to specify a list of the languages in which
+you want to translate the documents. This is as simple as:
+
+ [po4a_langs] fr de
+
+This will enable you to expand $lang to all the specified languages in the rest
+of the config file.
+
 =head2 Specifying the paths to translator inputs
 
 First, you have to specify where the translator input files (ie, the files 
@@ -61,6 +72,11 @@
 
     <lang>:<path to the po file for this lang>
 
+If you've defined the template languages, you can rewrite the line above this
+way:
+
+ [po4a_paths] doc/l10n/project.doc.pot $lang:doc/l10n/$lang.po
+
 =head2 Specifying the documents to translate
 
 You now naturally have to specify which documents are translated, their 
@@ -78,6 +94,16 @@
 
  [type: <format>] <master_doc> <lang>:<localized_doc>* add_<lang>:<addendum>*
 
+If you've defined the template languages, you can rewrite the line above this
+way:
+
+ [type: pod] script $lang:doc/$lang/script.1 add_fr:doc/l10n/script.fr.add
+
+If all the languages had addendums with similar paths, you could also write
+something like:
+
+ [type: pod] script $lang:doc/$lang/script.1 add_$lang:doc/l10n/script.$lang.add
+
 =head1 OPTIONS
 
 =over 4
@@ -231,6 +257,7 @@
 -e $config_file || die wrap_msg(gettext("File %s does not exist."), $config_file);
 
 # Parse the config file
+my (@langs);
 my ($pot_filename) = "";
 my (%po_filename); # po_files: '$lang'=>'$path'
 my (%document); # '$master'=> {'format'=>'$format'; '$lang'=>'$path'; 'add_$lang'=>('$path','$path') }
@@ -252,11 +279,30 @@
       unless ($line =~ m/^\[([^\]]*)\] (\S+) (.*)$/ || $line =~ m/^\[([^\]]*)\] (\S+)$/);
     my ($cmd,$main,$args)=($1,$2,$3||"");
 
+    if (@langs) {
+	# Expand the $lang templates
+	my($args2) = "";
+	foreach my $arg (split(/ /,$args)) {
+	    if ( $arg =~ /\$lang/ ) {
+		# Expand for all the langs
+		foreach my $lang (@langs) {
+		    my($arg2) = $arg;
+		    $arg2 =~ s/\$lang/$lang/g;
+		    $args2 .= $arg2." ";
+		}
+	    } else {
+		# Leave the argument as is
+		$args2 .= $arg." ";
+	    }
+	}
+	$args = $args2;
+    }
+
     print "cmd=[$cmd]; main=$main; args=\"$args\"\n" if $debug;
 
     if ($cmd eq "po4a_paths") {
 	die wrap_ref_mod("$config_file:$nb", "",
-	    gettext("'po4a_path' redeclared"))
+	    gettext("'%s' redeclared"), "po4a_path")
 	  if (length $pot_filename);
 	$pot_filename = $main;
 	foreach my $arg (split(/ /,$args)) {
@@ -265,6 +311,12 @@
 	      unless ($arg =~ /^([^:]*):(.*)/);
 	    $po_filename{$1}=$2;
 	}
+
+    } elsif ($cmd eq "po4a_langs") {
+	die wrap_ref_mod("$config_file:$nb", "",
+	    gettext("'%s' redeclared"), "po4a_langs")
+	  if (@langs);
+	@langs = split(/ /,$main." ".$args);
 
     } elsif ($cmd =~ m/type: *(.*)/) {
 	$document{$main}{'format'} = $1;