gunnar: server/kolab-webadmin/admin/locale .cvsignore, NONE, 1.1 extract_messages, NONE, 1.1

cvs at kolab.org cvs at kolab.org
Fri Aug 17 10:51:28 CEST 2007


Author: gunnar

Update of /kolabrepository/server/kolab-webadmin/admin/locale
In directory doto:/tmp/cvs-serv14729/locale

Added Files:
	.cvsignore extract_messages 
Log Message:
The web admin will be restructured to get a better distinction between the library and the web application parts. This currently a draft but I wanted to add this early into CVS so that the following changes will be visible.

--- NEW FILE: .cvsignore ---
messages.pot

--- NEW FILE: extract_messages ---
#!/kolab/bin/perl
# This script extracts messages from the TPL files to pass along with the PHP files to xgettext
# It also manages the i18n files and directory structure
# 2000 by Romain Pokrzywka <romain at kdab.net>

#
# Check for usage message
#
if($ARGV[0] eq "-h" || $ARGV[0] eq "--help") {
    print "Usage: extract_messages [create|update] languages...\n\n";
    print "This scripts extracts messages from the .php and .tpl files into the file messages.pot. ";
    print "Then it copies this file to every language subdirectory, where appropriate translations can be inserted.\n\n";
    print "There are two working modes : create and update. In create mode, the file messages.po is simply copied from the template file (messages.pot) in each language subdirectory (which is created if needed). In update mode, the already existing file messages.po is merged with the new template file, which may contain new messages, modified and even deleted ones. Note that using create mode on languages with existing messages.po files will fail, just like using update mode on languages without messages.po files.\n";
    print "If you don't specify any mode, then the script will automatically chose the appropriate mode for each language, depending on the existence of the file messages.po.\n\n";
    print "You can specify as many languages as you want, using their locale code, e.g. : fr, de, sv... You can also specify sublanguage codes for finer translations, e.g. : en_GB, en_US, pt_BR... For every language specified, a corresponding subdirectory is created. This directory contains a directory LC_MESSAGES, in which the file messages.po is created. This is also where the file messages.mo (the binary version actually used by xgettext) should be put.\n";
    print "If you don't specify any language, then the script will use all the already existing languages, based on the existing subdirectories.\n";
    exit(0);
}

#
# Retrieve command line arguments
#
$action = "auto";
if($ARGV[0] eq "update" || $ARGV[0] eq "create") {
    $action = $ARGV[0];
    shift(@ARGV);
}
@languages = @ARGV;
#print "languages : " . join(" ", @languages) . "\n";

$templatesDir = "../templates";
$phpDir = "../admin";
$includeDir = "../include";

#
# Extract messages from the templates
#
$tplMessagesFile = "tpl_messages.php";
open(OUTFILE, ">", "$tplMessagesFile") or die("unable to open output file $tplMessagesFile");
if ( $^V ge v5.8.0 ) {
  binmode(OUTFILE,":utf8");
} else {
  warn ("NOT using utf8! Upgrade to perl >= 5.8.0.\n");
}

print OUTFILE "<?php\n";

@tplFiles = `find $templatesDir -name "*.tpl" -o -name "*.tpl.in" 2> /dev/null`;

foreach $tpl (@tplFiles)
{
        chomp($tpl);
        #print "opening file $tpl...\n";
        open(INFILE, "<", "$templatesDir/$tpl") or die("unable to open file $tpl");
        if ( $^V ge v5.8.0 ) {
            binmode(INFILE,":utf8");
        } else {
            warn ("NOT using utf8! Upgrade to perl >= 5.8.0.\n");
        }
        
        while($line = <INFILE>)
        {
            chomp $line;
            while($line =~ /\{tr.*?msg="(.*?[^\\])".*?\}/g) {
                #print "found message $1\n";
                print OUTFILE "_(\"$1\");\n";
            }
        }
        close(INFILE);
}

print OUTFILE "?>\n";
close(OUTFILE);

#
# Get all the php files recursively in www/admin and in the includes
#
@phpFiles = `find $phpDir -name "*.php" -o -name "*.php.in" 2> /dev/null`;
foreach (@phpFiles) { chomp; }
@includeFiles = `find $includeDir -name "*.php" -o -name "*.php.in" 2> /dev/null`;
foreach (@includeFiles) { chomp; }
#print join(" ", @phpFiles);
#print join(" ", @includeFiles);

#
# Call xgettext on all the php files (including the one generated from templates)
#
$allFiles = "$tplMessagesFile " . join(" ", @phpFiles) . " " . join(" ", at includeFiles);
#print "$allFiles\n";
print `xgettext --language=PHP -o messages.pot $allFiles`;

#
# If no language is specified on the command line, get all the already installed languages
#
if(@languages == 0) {
    @languages = `find . -maxdepth 1 -type d -not -name "." -and -not -name "CVS" 2> /dev/null`;
    foreach (@languages) { chomp; }
    print "languages : " . join(" ", @languages) . "\n";
}

#
# Create directory structure (if needed) then do the proper action
#
foreach $lang (@languages)
{
    `mkdir -p $lang/LC_MESSAGES`;
    #print "current language : $lang\n";
    $initialaction = $action;
    
    if($action eq "auto") {
        if(-e "$lang/LC_MESSAGES/messages.po") {
            $action = "update";
        } else {
            $action = "create";
        }
        print "Using $action mode for language $lang\n";
    }
    
    if($action eq "create") {
        if(-e "$lang/LC_MESSAGES/messages.po") {
            print "messages.po already exists for language $lang. Skipping. (did you intend to update ?)\n";
        } else {
            print `cp messages.pot $lang/LC_MESSAGES/messages.po`;
        }
    } else {
        if( ! -e "$lang/LC_MESSAGES/messages.po" ) {
            print "messages.po doesn't exist for language $lang. Skipping. (did you intend to create ?)\n";
        } else {
            print `msgmerge --update --backup=simple $lang/LC_MESSAGES/messages.po messages.pot`;
        }
    }
    $action = $initialaction;
}

#
# Cleanup
#
print `rm -r tpl_messages.php`;





More information about the commits mailing list