Add a trailing full stop to the kernel32 error messages

Francois Gouget fgouget at free.fr
Thu Feb 9 11:47:55 CST 2012


Translators: This may concern you! See the (*) below.
(hence the post to wine-devel)

It was discovered that the kernel32 error messages are supposed to all 
end with a full stop. This is a lot of strings and impacts a lot of 
translations.

   http://www.winehq.org/pipermail/wine-devel/2012-January/093969.html

So this fix is not provided as a patch but as a set of two scripts.
 * mcfix adds a trailing full stop if needed to the kernel32 error 
   messages.
 * pofix does the matching changes to the specified PO file both on the 
   English and translated strings (taking into account the full-width 
   for Chinese and Japanese translations).

The advantage is that this can update everything with no fuzzying and 
without risking conflicts when applying it to Wine(*). To update Wine, 
simply run:

   ./mcfix dlls/kernel32/winerror.mc; for i in po/*.po;do ./pofix $i;done


(*) As a translator if you have a local PO file that you took before 
this change and you modified some kernel32 error translations you patch 
will conflict. But that's easy to solve, simply run:

   ./pofix myfile.po

-- 
Francois Gouget <fgouget at free.fr>              http://fgouget.free.fr/
                              145 = 1! + 4! + 5!
-------------- next part --------------
#!/usr/bin/perl -w
# (c) Copyright 2012. Francois Gouget.
use strict;

my $name0=$0;
$name0 =~ s+^.*/++;


my $opt_file;
my $usage;
while (@ARGV > 0)
{
    my $arg=shift @ARGV;
    if ($arg eq "-?" or $arg eq "-h" or $arg eq "--help")
    {
        $usage=0;
    }
    elsif ($arg =~ /^-/)
    {
        print STDERR "$name0:error: unknown '$arg' option\n";
        $usage=2;
        last;
    }
    elsif (!defined $opt_file)
    {
        $opt_file=$arg;
    }
    else
    {
        print STDERR "$name0:error: unknown '$arg' option\n";
        $usage=2;
        last;
    }
}
if (!defined $usage)
{
    if (!defined $opt_file)
    {
        print STDERR "$name0:error: you must specify the path to the PO file to fix\n";
        $usage=2;
    }
}
if (defined $usage)
{
    if ($usage)
    {
        print STDERR "$name0:error: try '$name0 --help' for more information\n";
        exit $usage;
    }
    print "Usage: $name0 MC_FILE [--help]\n";

    print "\n";
    print "Adds a full stop at the end of the winerror.mc messages,\n";

    print "\n";
    print "Options:\n";
    print "  MC_FILE         The source MC file\n";
    print "  --help, -h      Shows this help message\n";
    exit 0;
}

my $fh;
if (!open($fh, "<:encoding(utf-8)", $opt_file))
{
    print STDERR "$name0:error: unable to open '$opt_file' for reading: $!\n";
    exit 1;
}

my @lines;

while (my $line=<$fh>)
{
    if ($line =~ /^\.$/)
    {
        $lines[-1] =~ s/\n$/.\n/ if ($lines[-1] !~ /\.\n$/);
    }
    push @lines, $line;
}
close($fh);

if (!open($fh, ">:encoding(utf-8)", $opt_file))
{
    print STDERR "$name0:error: unable to open '$opt_file' for writing: $!\n";
    exit 1;
}
print $fh @lines;
close($fh);
-------------- next part --------------
#!/usr/bin/perl -w
# (c) Copyright 2012. Francois Gouget.
use strict;

my $name0=$0;
$name0 =~ s+^.*/++;


my $opt_file;
my $usage;
while (@ARGV > 0)
{
    my $arg=shift @ARGV;
    if ($arg eq "-?" or $arg eq "-h" or $arg eq "--help")
    {
        $usage=0;
    }
    elsif ($arg =~ /^-/)
    {
        print STDERR "$name0:error: unknown '$arg' option\n";
        $usage=2;
        last;
    }
    elsif (!defined $opt_file)
    {
        $opt_file=$arg;
    }
    else
    {
        print STDERR "$name0:error: unknown '$arg' option\n";
        $usage=2;
        last;
    }
}
if (!defined $usage)
{
    if (!defined $opt_file)
    {
        print STDERR "$name0:error: you must specify the path to the PO file to fix\n";
        $usage=2;
    }
}
if (defined $usage)
{
    if ($usage)
    {
        print STDERR "$name0:error: try '$name0 --help' for more information\n";
        exit $usage;
    }
    print "Usage: $name0 PO_FILE [--help]\n";

    print "\n";
    print "Adds a full stop at the end of the winerror.mc messages,\n";

    print "\n";
    print "Options:\n";
    print "  PO_FILE         The source PO file\n";
    print "  --help, -h      Shows this help message\n";
    exit 0;
}

my $fh;
if (!open($fh, "<:encoding(utf-8)", $opt_file))
{
    print STDERR "$name0:error: unable to open '$opt_file' for reading: $!\n";
    exit 1;
}

my $fstop_re='(?:\.|\x{3002})';
my $fstop=($opt_file =~ /(?:ja|zh)/ ? "\x{3002}" : '.');
my $change=0;
my $state="";
my @lines;

sub fix_last_line()
{
    if (@lines and $lines[-1] =~ /\"\"\n$/)
    {
        # Nothing to do
    }
    elsif ($change and $state eq "msgid")
    {
        $lines[-1] =~ s/(?:\\n)?\"\n$/.\\n\"\n/ if ($lines[-1] !~ /$fstop_re(?:\\n)?\"\n$/);
    }
    elsif ($change and $state eq "msgstr")
    {
        $lines[-1] =~ s/(?:\\n)?\"\n$/$fstop\\n\"\n/ if ($lines[-1] !~ /$fstop_re(?:\\n)?\"\n$/);
    }
}

while (my $line=<$fh>)
{
    if ($line =~ /^#:.* winerror\.mc:/)
    {
        fix_last_line();
        # This message comes from winerror.mc
        $change=1;
        $state="";
    }
    elsif ($line =~ /^\s*$/)
    {
        fix_last_line();
        $change=0 if ($state eq "msgstr");
        $state="";
    }
    elsif ($line =~ /^msgid /)
    {
        fix_last_line();
        $state="msgid";
    }
    elsif ($line =~ /^msgstr /)
    {
        fix_last_line();
        $state="msgstr";
    }
    elsif ($line =~ /^\"/)
    {
        # Just continuing the current msgid / msgstr
        # Nothing to do
    }
    else
    {
        fix_last_line();
        $change=0 if ($state ne "");
        $state="";
    }
    push @lines, $line;
}
if ($change and $lines[-1] =~ /^(?:msg|\")/)
{
    # This is an msgstr -> end-of-file boundary so fix that msgstr's last line
    $lines[-1] =~ s/\\n\"\n$/$fstop\\n\"\n/ if ($lines[-1] !~ /$fstop_re\\n\"\n$/);
}
close($fh);

if (!open($fh, ">:encoding(utf-8)", $opt_file))
{
    print STDERR "$name0:error: unable to open '$opt_file' for writing: $!\n";
    exit 1;
}
print $fh @lines;
close($fh);


More information about the wine-patches mailing list