Source code encoding detection modifications for intltool
Carlos Perelló Marín <[email protected]> 14 Jul 2003 20:34:18 +0200
| Newsgroups | gmane.comp.gnome.internationalization.general,gmane.comp.gnome.lib.xml.internationalization |
|---|---|
| Organization | GNOME Foundation |
| Message-ID | <[email protected]> |
--=-RC5GE1dAImJ8AxHStwxP Content-Type: multipart/mixed; boundary="=-s8gFV8N70Sv0P62/EXDY" --=-s8gFV8N70Sv0P62/EXDY Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Hi, here you have a patch that tries to detect the file encoding used and then, calls xgettext with that encoding option. Please, test it and review it I have no idea about perl so my change it's mainly a cut & paste fix I will also prepare a gettext >=3D 0.12 check so new intltool releases will require it to be able to deal with UTF-8 source files. Some comments. I get the file encoding with the "file" command and thus, I'm not able to know the XML and yacc files encoding, so I'm assuming that XML files are UTF-8 and any other file that it's not UTF-8, ISO* or XML is ASCII Comments, ideas? I will apply this patch to my intltool installation so the status pages will start to use it. Cheers. P.S.: This patch is an evolution from this http://deaddog.org/~maddog/intltool-update.patch --=20 Carlos Perell=F3 Mar=EDn Debian GNU/Linux Sid (PowerPC) Linux Registered User #121232 mailto:[email protected] || mailto:[email protected] http://carlos.pemas.net Valencia - Spain --=-s8gFV8N70Sv0P62/EXDY Content-Disposition: attachment; filename=intltool.patch Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; name=intltool.patch; charset=ISO-8859-15 ? .intltool-update.in.in.swp Index: intltool-update.in.in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/gnome/intltool/intltool-update.in.in,v retrieving revision 1.85 diff -u -w -r1.85 intltool-update.in.in --- intltool-update.in.in 25 May 2003 23:06:05 -0000 1.85 +++ intltool-update.in.in 14 Jul 2003 18:26:45 -0000 @@ -55,6 +55,7 @@ my $conf_file; # remove later my %varhash =3D (); my %po_files_by_lang =3D (); +my $encoding =3D "ASCII"; =20 # Regular expressions to categorize file types. # FIXME: Please check if the following is correct @@ -251,6 +252,38 @@ return "gettext\/$gettext_type"; } =20 +sub determine_code ($)=20 +{ + my $comments =3D $_; + my $code =3D $_; + my $filename; + my $type; + my $gettext_code=3D"ASCII"; # All files are ASCII by default + + if ($comments =3D~ /^[^#]/) + { + $code =3D~ s/^\[[^\[].*]\s*//; + $filename =3D "../$code"; + $type=3D`file $filename | cut -d ' ' -f 2`; + if ($? eq "0") + { + if (!($type =3D~ /^[^ISO]/) or !($type =3D~ /^[^UTF]/)) + { + $gettext_code=3D$type; + chomp $gettext_code; + } + elsif (!($type =3D~ /^[^XML]/)) + { + $gettext_code=3D"UTF-8"; # We asume that .glade and other .xml fil= es are UTF-8 + } + } + + } + =20 + return $gettext_code; +} + + sub find_leftout_files { my (@buf_i18n_plain, @@ -517,14 +550,31 @@ while (<INFILE>)=20 { chomp; + + my $gettext_code; +=09 if (/\.($xml_extension|$ini_extension)$/ || /^\[/)=20 { s/^\[.*]\s*//; print OUTFILE "$_.h\n"; + $gettext_code =3D &determine_code ("$_.h"); }=20 else=20 { print OUTFILE "$_\n"; + $gettext_code =3D &determine_code ("$_"); + } + + if ($gettext_code ne "" and $encoding ne $gettext_code) + { + if ($encoding eq "ASCII") + { + $encoding=3D$gettext_code; + } + elsif ($gettext_code ne "ASCII") + { + print "Warning: You should use the same file encoding for all you= r project files, but you have $encoding and $gettext_code files ($_).\n"; + } } } =20 @@ -534,6 +584,7 @@ system ("xgettext", "--default-domain\=3D$MODULE",=20 "--directory\=3D\.\.", "--add-comments",=20 + "--from-code\=3D$encoding",=20 "--keyword\=3D\_",=20 "--keyword\=3DN\_",=20 "--keyword\=3DU\_", @@ -675,7 +726,7 @@ } } =20 - if ($str =3D~ /^(.*)\${?([A-Z]+)}?(.*)$/) + if ($str =3D~ /^(.*)\${?([A-Z_]+)}?(.*)$/) { my $rest =3D $3; my $untouched =3D $1; --=-s8gFV8N70Sv0P62/EXDY-- --=-RC5GE1dAImJ8AxHStwxP Content-Type: application/pgp-signature; name=signature.asc Content-Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQA/EvepEuPMamD5V9cRAvshAJ9c8FtO1F7upT55vLfP3obr8vXFJwCfbap8 CSIpAp5Nx1kIxfCR8hfX8nM= =6kju -----END PGP SIGNATURE----- --=-RC5GE1dAImJ8AxHStwxP--