[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

l10n-check 0.2.4



Bonjour,

après utilisation avec les fichiers po d'apt et window maker, voici
quelques nouvelles corrections.

journal des modifications :
version 0.2.4
  - add: documentation in pod format
  - add: po format
  - change: use a hash table for file types
  - bug fix:
    - add a space for nice presentation
    - add a debug message

La rustine est attachée, le script complet ici :
http://perso.wanadoo.fr/nico.bertol/l10n-check/l10n-check.txt

le tarball est ici :
http://perso.wanadoo.fr/nico.bertol/l10n-check/l10n-check.tar.gz
(n'oubliez pas le fichier caché .l10n-check).

J'ai aussi attaché les nouveaux fichiers de règles po et common.


Nicolas
-- 
--- l10n-check_0.2.3.txt	Mon Jan 21 21:52:06 2002
+++ l10n-check_0.2.4.txt	Sat Jan 26 14:14:49 2002
@@ -11,6 +11,13 @@
 
 # available fields:
 my @FIELDS = qw(comment start stop rule id pre_hint hint post_hint pre_valid post_valid pre_fix pre_insert fix post_insert post_fix);
+# filetype:
+my %FILE_TYPES = (
+  '\.wml$'	 => "wml",
+  '\.wml\.relu$' => "wml",
+  '\.po$'	 => "po",
+  '\.po\.relu$'	 => "po"
+);
 # available colors:
 my %TEXT_COLORS = (
   "black"	=> "\033[30;1m",
@@ -41,6 +48,7 @@
 my ($rules_dir,			# = "$ENV{HOME}/l10n/l10ncheck/rules";
     $rules_e,			# = "rules";
     $bak_e,			# = "bak";
+    $comment,			# = ">> ";
     $debug,			# = 0;
     $ispell,			# = "yes";
     $dictionary,		# = "francais";
@@ -53,13 +61,13 @@
 
 # Read the config file
 my $config = $ENV{HOME}."/.l10n-check";	# config file
-die("You must define \$rules_dir, \$rules_e, \$bak_e, \$debug, \$ispell, \$dictionary,\n"
-   ."\$word_letters, \$review, \$highlight_text_color, \$comment_text_color,\n"
+die("You must define \$rules_dir, \$rules_e, \$bak_e, \$comment, \$debug, \$ispell,\n"
+   ."\$dictionary, \$word_letters, \$review, \$highlight_text_color, \$comment_text_color,\n"
    ."\$letter_color Perl variables in \$HOME/.l10n-check\n") unless -r $config;
 scalar eval `cat $config`;	# get the variables
 
 # Test if variables are defined
-foreach (qw(rules_dir rules_e bak_e debug ispell dictionary word_letters review 
+foreach (qw(rules_dir rules_e bak_e comment debug ispell dictionary word_letters review 
 	    highlight_text_color comment_text_color letter_color)) {
 	eval "\$config=\$$_";
 	suicide("\$$_ not defined in \$HOME/.l10n-check") unless ($config ne "");
@@ -73,23 +81,6 @@
 my $HC = $NC.$highlight_text_color;		# highlighted text color
 my $LC = $NC.$letter_color;			# letter color
 
-# rules file format:
-# [item]			# search regexpr to unvalid present token
-# id = "id"			# identificator
-#
-# hint  = "hint"		# hint to explain error on present token
-# fix n = "fix"			# string #n to replace matched item
-#
-# pre_hint    n = "pre_hint"	# hint to explain error before present token
-# pre_valid   n = "pre_valid"	# regexpr to valid matched item if found before it
-# pre_insert  n = "pre_insert"	# string #n to insert before matched item
-# pre_fix     n = "pre_fix"	# string #n to replace preceeding token
-# 
-# post_hint     = "post_hint"	# hint to explain error after present token
-# post_valid    = "post_valid"	# regexpr to valid matched item if found after it
-# post_insert n = "post_insert"	# string #n to insert after matched item
-# post_fix    n = "post_fix"	# string #n to replace next token
-#
 # rules structure:
 # { item => 	{ 'valid'	=> { id => { 'pre'  => pre_valid,
 # 					     'post' => post_valid },
@@ -104,7 +95,272 @@
 #		  'post_fix'    => [ post_fix0, ... ] },
 #   ... }
 
-my $version = "0.2.3";
+=head1 NAME
+
+l10n-check - tool to check spelling and syntax in l10n files
+
+=head1 SYNOPSIS
+
+l10n-check [-q] [--quiet] [-v] [--verbose n]
+           [-i] [--spell] [--dict] [-n] [--nospell]
+	   [-r] [--review] [-t] [--trans] filename"
+
+=head1 DESCRIPTION
+
+This program parses a file checking for syntax rules and optionaly asking
+ispell for checking words spelling. It makes fix suggestions and outputs a
+corrected file accordingly adding review comments if requested.
+
+It tries to find the file type according the extension or the first lines and
+loads rules accordingly.
+
+It displays lines when they are parse.
+
+When an error is found, a choose menu is displayed. Enter nothing if you don't
+want to change anything. If a choice suits you, enter the corresponding letter.
+If you want to fix it but no choice is correct, enter a space, then you will be
+asked for a string to replace the highlighted text. The script will replace the
+hightlighted text with your choice and parse it again for new errors.
+
+=head1 OPTIONS
+
+Verbosity level:
+
+=over 4
+
+=item I<-q> I<--quiet>, quiet mode
+
+=item I<-v>, verbose, start at level 1, add more for more verbosity
+
+=item I<--verbose n>, set verbosity level to I<n>
+
+=back
+
+Spelling check:
+
+=over 4
+
+=item I<-i> I<--spell>, check spelling with ispell
+
+=item I<--dict language>, use I<language> dictionary for ispell
+
+=item I<-n> I<--nospell>, don't check spelling
+
+=back
+
+Mode:
+
+=over 4
+
+=item I<-r> I<--review>, review mode, add comments on lines beginning with `I<E<gt>E<gt> >'
+
+=item I<-t> I<--trans>, translator mode, don't add comments
+
+=back
+
+In each option group, options are not compatible, last found option overrides
+previous one.
+
+=head1 CONFIG FILE
+
+This is your F<~/.l10n-check> file.
+
+It contains lines to define variables:
+
+$I<variable_name> = 'I<variable_value>';
+
+Some sample values are provided into square brackets, they should be suitable
+for most installations.
+
+The file MUST contain the following variables:
+
+=over 4
+
+=item I<$rules_dir>, directory for rules description files [$ENV{HOME}/l10n-check]
+
+=item I<$rules_e>, extension for rules description files [rules]
+
+=item I<$bak_e>, extension for backup files [bak]
+
+=item I<$comment>, comment string for review [>> ]
+
+=item I<$debug>, verbosity level [0]
+
+=item I<$ispell>, use ispell for spelling [yes]
+
+=item I<$dictionary>, dictionary to use with ispell
+
+=item I<$word_letters>, regural expression to define letters allowed to write a word [a-z-]
+
+=item I<$review>, set to `B<yes>' if you want review comments to be added in the output file
+
+=item I<$highlight_text_color>, color used to highlight text, this should highlight space charactaters (see below for available colors) [$TEXT_COLORS{'red_h'}]
+
+=item I<$comment_text_color>, color used for comments and hints [$TEXT_COLORS{'cyan'}]
+
+=item I<$letter_color>, color used for letters in choose menu [$TEXT_COLORS{'green'}]
+
+=back
+
+available colors are:
+
+=over 4
+
+=item I<$TEXT_COLORS{'black'}>, black
+
+=item I<$TEXT_COLORS{'red'}>, red
+
+=item I<$TEXT_COLORS{'green'}>, green
+
+=item I<$TEXT_COLORS{'yellow'}>, yellow
+
+=item I<$TEXT_COLORS{'blue'}>, blue
+
+=item I<$TEXT_COLORS{'magenta'}>, magenta
+
+=item I<$TEXT_COLORS{'cyan'}>, cyan
+
+=item I<$TEXT_COLORS{'white'}>, white
+
+=item I<$TEXT_COLORS{'black_h'}>, black background
+
+=item I<$TEXT_COLORS{'red_h'}>, red background
+
+=item I<$TEXT_COLORS{'green_h'}>, green background
+
+=item I<$TEXT_COLORS{'yellow_h'}>, yellow background
+
+=item I<$TEXT_COLORS{'blue_h'}>, blue background
+
+=item I<$TEXT_COLORS{'magenta_h'}>, magenta background
+
+=item I<$TEXT_COLORS{'cyan_h'}>, cyan background
+
+=item I<$TEXT_COLORS{'white_h'}>, white background
+
+=item I<$TEXT_COLORS{'bold'}>, blod
+
+=item I<$TEXT_COLORS{'blink'}>, blink
+
+=item I<$TEXT_COLORS{'inverse'}>, video inverted
+
+=item I<$TEXT_COLORS{'normal'}>, normal
+
+=item I<$TEXT_COLORS{'underscore'}>, underlined
+
+=back
+
+=head1 RULES DESCRIPTION FILES
+
+This is a text file containing the rules for skipping comments and for syntax
+checking. Fields are defined on their own lines like this:
+
+I<name> [I<index>] = "I<value>"
+
+=over 4
+
+=item I<index> is optional and not requested for all fields
+
+=item I<value> can contain any type of characters
+
+=item Comments are no allowed on field lines but can be added anywhere else on lines starting with `#'.
+
+=back
+
+Skipping comments fields are:
+
+=over 4
+
+=item I<comment>, mandatory for each comment rule
+
+I<value> is a unique identifier
+
+=item I<start>, mandatory for each comment identifier
+
+I<value> is a regular expression matching beginning of comments, parsing will
+stop before match.
+
+=item I<stop>, mandatory for each comment identifier
+
+I<value> is a regular expression matching end of comments, parsing will start
+after match
+
+=back
+
+Syntax rules are:
+
+=over 4
+
+=item I<rule>, mandatory for each syntax rule
+
+I<value> contains a regular expression matching an error
+
+=item I<id>, optional
+
+I<value> contains a unique identifier for this rule to define pre- and
+post-validation rules, optional is there is only one pre- and post-validation
+rule
+
+=item I<pre_valid>, optional
+
+=item I<post_valid>, optional
+
+I<value> contains a regular expression for validation rule, for the same I<id>,
+if I<pre_valid> matches before the matched rule string, and I<post_valid>
+matches after the matched rule string, string is valid. Only one can be
+defined, in this case the other always matches
+
+=item I<pre_hint>, optional
+
+I<value> contains a string displayed before the choose menu, and in the output
+comment, to explain the found error if no pre-validation rule matches
+
+=item I<post_hint>, optional
+
+I<value> contains a string displayed before the choose menu, and in the output
+comment, to explain the found error if no post-validation rule matches
+
+=item I<hint>, optional
+
+I<value> contains a string displayed before the choose menu, and in the output
+comment, to explain the found error if there is no pre- and no post-validation
+rule
+
+=item I<pre_fix>, optional
+
+I<value> contains a string that could replace the matched rule string to fix
+the error if no pre-validation rule matches, you can suggest several string by
+providing an I<index> number, starting at zero
+
+=item I<pre_insert>, optional
+
+I<value> contains a string that could be inserted before the matched rule
+string to fix the error if no pre-validation rule matches, you can suggest
+several string by providing an I<index> number, starting at zero.
+
+=item I<post_insert>, optional
+
+I<value> contains a string that could replace the matched rule string to fix
+the error if no post-validation rule matches, you can suggest several string by
+providing an I<index> number, starting at zero.
+
+=item I<post_fix>, optional
+
+I<value> contains a string that could be inserted after the matched rule string
+to fix the error if no post-validation rule matches, you can suggest several
+string by providing an I<index> number, starting at zero.
+
+=item I<fix>, optional
+
+I<value> contains a string that could replace the matched rule string to fix
+the error if no pre- and no post-validation rule is provided, you can suggest
+several string by providing an I<index> number, starting at zero.
+
+=back
+
+=cut
+
+my $version = "0.2.4";
 
 # Test if configuration as been made
 my @dir=split("/", $rules_dir);		# get all subdirs
@@ -112,7 +368,7 @@
 	my $dir = join("/", (@dir[0..$i]));	# subdir path
 	if (! -d $dir) {			# if not exist, try to create it
 		mkdir ($dir, 0755) || suicide("Is the script configured?",
-					     "Can't create `$dir': $!");
+					      "Can't create `$dir': $!");
 	}
 }
 
@@ -161,8 +417,11 @@
 
 	debug 1, "filename $file";
 
-	return "wml" if ($file =~ /.wml.relu$/);
-	return "wml" if ($file =~ /.wml$/);
+	foreach (keys %FILE_TYPES) {
+		next unless ($file =~ /$_/);
+		debug 2, "  file type: $FILE_TYPES{$_}";
+		return $FILE_TYPES{$_};
+	}
 
 	open FILE, $file	|| suicide "Can't open $file: $!";
 	while (<FILE>) {
@@ -284,7 +543,7 @@
 	$choice = @choices[ord(lc $&)-97] unless $choice;	# set choice
 
 	print "$LC>$NC$l$choice$r\n";				# print fixed line
-	return (">> $choice : $hint", $l.$choice.$r);		# comment and fixed line
+	return ("$comment$choice : $hint", $l.$choice.$r);		# comment and fixed line
 }
 
 # parse one line
@@ -389,7 +648,6 @@
 				
 			@ret ? pos $line = $save - length($w) :		# set last match position at the beginning of the modification
 			       pos $line = $save;			#  restore last match position if no change
-			#$line =~ /(\w+)/g unless @ret;			# next one if no correction
 
 			next;
 		}
@@ -462,6 +720,7 @@
 do {
 	$d = "";			# option not parsed
 	$_ = shift || "";		# get next option
+	debug 2, "parsing option: $_";
 
 	if (/^-v$/) {			# add verbose
 		$d = 1;
# common rules
rule = "status|statut"
hint	= "« état » en français, cf. FAQ § 2.13.4"
fix	= "état"

rule = "plateforme"
hint	= "Trait d'union manquant"
fix	= "plate-forme"

rule = "entete|entête"
hint	= "Trait d'union manquant"
fix	= "en-tête"

rule = "digital"
hint	= "Angliscisme"
fix	= "numérique"

rule = "complétion"
hint	= "Franglisme, cf. FAQ § 2.13.4"
fix	= "complètement"

rule = "(?<=\s)(e-?)?mail"
hint	= "courrier, courriel ou courrier électronique : en français, cf. FAQ § 2.13.3"
fix 0	= "courriel"
fix 1	= "courrier"
fix 2	= "courrier électronique"

rule = "maintainer|mainteneur"
hint	= "« Responsable [d'un paquet] » en français, cf. FAQ § 2.13.1"
fix	= "responsable"

rule = "package"
hint	= "« paquet » en français, cf. FAQ § 4.1"
fix	= "paquet"

rule = "paquetage"
	pre_valid = "em|dé"
pre_hint = "« paquet » en français, cf. FAQ § 4.1"
pre_fix	 = "paquet"

rule = "patch"
hint	= "« rustine » en français, cf. FAQ § 2.13.3"
fix	= "rustine"

rule = "ROMs"
hint	= "Les sigles de prennent pas la marque du pluriel en français"
fix	= "ROM"

rule = "GNU/Linux"
hint	= "Trait d'union en français, cf. FAQ § 5.1.2.7"
fix	= "GNU-Linux"

rule = "GNU/Hurd"
hint	= "Trait d'union en français, cf. FAQ § 5.1.2.7"
fix	= "GNU-Hurd"

rule = "\"(?=\S)"
hint	= "Guillemet français, cf. FAQ § 5.1.2.2"
fix	= "« "

rule = "(?<=\S)\""
hint	= "Guillemet français, cf. FAQ § 5.1.2.2"
fix	= " »"

rule = "(?<=\s)'(?=\S)"
hint	= "Guillemet français, cf. FAQ § 5.1.2.2"
fix	= "« "

rule = "(?<=\S)'(?=(\s|$))"
hint	= "Guillemet français, cf. FAQ § 5.1.2.2"
fix	= " »"

rule = "(?<=\s)`(?=\S)"
hint	= "Guillemet français, cf. FAQ § 5.1.2.2"
fix	= "« "

rule = "plate-?formes"
hint	= "Pluriel du nom composé"
fix	= "plates-formes"

rule = "etc"
	post_valid = "\."
post_hint   = "Point abréviatif manquant"
post_insert = "."

# comment rules
comment = "comment"
	start = "^#"
	stop  = ".*$"
comment = "english"
	start = "id \""
	stop  = "str \""
comment = "empty"
	start = "\"$"
	stop  = "^(\"|msg)"

# rules for text files

rule = ":"
id   = "url"
	 pre_valid  = "(ftp|http|file)"
	post_valid  = "//"
id   = "espace"
	 pre_valid  = " "
	post_valid  = "( |$)"
 pre_hint   = "Espace (insécable) avant les deux-points, cf. FAQ § 5.1"
post_hint   = "Espace normale après les deux-points, cf. FAQ § 5.1"
 pre_insert = " "
post_insert = " "

rule = ";"
id   = "espace"
	 pre_valid  = " "
	post_valid  = "( |$)"
 pre_hint   = "Espace (insécable) avant le point-virgule, cf. FAQ § 5.1"
post_hint   = "Espace normale après le point-virgule, cf. FAQ § 5.1"
 pre_insert = " "
post_insert = " "

rule = "!"
id   = "espace"
	 pre_valid  = " "
	post_valid  = "( |$)"
 pre_hint   = "Espace (insécable) avant le point d'exclamation, cf. FAQ § 5.1"
post_hint   = "Espace normale après le point d'exclamation, cf. FAQ § 5.1"
 pre_insert = " "
post_insert = " "

rule = "\?"
id   = "espace"
	 pre_valid  = " "
	post_valid  = "( |$)"
 pre_hint   = "Espace (insécable) avant le point d'interrogation, cf. FAQ § 5.1"
post_hint   = "Espace normale après le point d'interrogation, cf. FAQ § 5.1"
 pre_insert = " "
post_insert = " "

rule = "«"
id   = "espace"
	post_valid  = " "
post_hint   = "Espace (insécable) après « « », cf. FAQ § 5.1"
post_insert = " "

rule = "»"
id   = "espace"
	  pre_valid = " "
   pre_hint = "Espace (insécable) avant « » », cf. FAQ § 5.1"
 pre_insert = " "


Reply to: