Hello,
I made a script to ease keeping up to date with translations, and it may be useful to someone else, too, so I post it here.

What it does:
1) Connects to SVN and downloads latest translations
2) Finds the untranslated ones and copies to a folder
3) If these are already present, it runs msgmerge on them

Simply said, you get a folder with all untranslated stuff in your language, and when it changes on server, just run it again and everything is updated. The things you must still do manually include: sort out ready translations after you correct them, compress, send to commit :) and possibly also deleting after commit.

Before running this, customize the script for your system. Required: Python, msgmerge somewhere in path, for SVN also svn (anywhere in system).

And one more thing, the folders created by this are relative to working dir, so if you run it in "translations", you'll get with current values "translations/workspace" and so on.

Vladimír Slávik
#!/bin/env python
"""
Script for extracting specific language's po files from svn checkout and
organizing them in convenient way for editing and diffing.

Modify variables to adapt it for your setup.
"""

# original charset UTF-8
# Vladimír Slávik 2007
# po-file parsing based on code by Kangounator

import string, os, glob, shutil, re;

true = 1;
false = 0;

#--------------------------------------------------------------------

def PoFileNotComplete(filename) :
    # (path must be prepared before calling)
    """
    Decides if a PO file is fully translated or not.
    """
    # The function tries to find untranslated message or fuzzy mark and stops 
on first of these.
    # (Presumption of "innocence" = completely translated)
    PoFile = open(filename, 'r');
    lines = PoFile.readlines();
    PoFile.close();
    i = 0;
    needText = false; # the next line MUST be msgstr content
    reFuzzy = re.compile(r"#, fuzzy.*");
    reMsgStr = re.compile(r' *(msgstr|msgstr\[[0-9]*\]) ".+" *');
    reMsgStrNext = re.compile(r' *(msgstr|msgstr\[[0-9]*\]) "" *');
        # empty - actual content is on next line(s)
    reContent = re.compile(r' *".+"'); # the next part of ^
    reTest = re.compile(r'.*');
    reOld = re.compile(r'#~.*'); # auto-deprecated messages
    if len(lines) > 0 : # anything to work with?
        while i < len(lines) :
            line = lines[i];
            if reOld.findall(line) != [] :
                # stop on first deprecated item - all following text is not 
interesting 
                if needText :
                    return true; # if found deprecated and should be content
                else :
                    return false;
            elif reFuzzy.findall(line) != [] :
                return true; # stop on first fuzzy
            else :
                if needText :
                    if reContent.findall(line) == [] :
                        return true; # content needed and not found -> not 
complete
                    else :
                        needText = false; # content needed and found - one line 
is enough to rule out invalidity
                else :
                    if reMsgStrNext.findall(line) != []:
                        needText = true; # empty msgstr, needs content on next 
line
                    elif reMsgStr.findall(line) != [] :
                        needText = false; # just making sure ... probably 
redundant
            i = i + 1;
        return false; # if execution passed the whole loop without hit, it's OK
    return false; # if file is empty, it it not interesting to translator 
(should be actually third return state, but it isn't meaningful to this 
application)

#--------------------------------------------------------------------

# conventions: strings ending in
#   PATH are actual full paths,
#   FILE the same for files and
#   NAME are both ^ but not concatenated with preceding path,
#   TAG are parts for concatenating


#--------------------------------------------------------------------
# !!!! modify the values in this part to customize script !!!!

BufName = "pot"; # dir with starting version POTs
OldName = "backup"; # dir with backup for diffs etc
NewName = "workspace"; # actual working dir
LangTag = "cs"; # tag of language to work with
Repositories = {
    "1.2" : "D:\\Dokumenty\\Translations\\1.2-po-svn",
    "trunk" : "D:\\Dev\\wesnoth-trunk\\po"
}; # hash with file repository-dependent suffixes and paths to repositories 
(can be more than two, but, well, there are always only two...)
SVNCheckoutCommands = [
    "svn co http://svn.gna.org/svn/wesnoth/branches/1.2/po/@HEAD 1.2-po-svn",
    "svn co http://svn.gna.org/svn/wesnoth/trunk/[EMAIL PROTECTED] 
D:/Dev/wesnoth-trunk/po"
]; # commands to update svn reps (optional - see below)
DoSVNCheckout = true; # update local copies before actual update - requires 
SVNCheckoutCommands to be set
DoPots = false; # create POTs folder - good only if you use msgmerge etc.
CopyOld = false; # copy the resulting files to backup dir - for later diffing 
etc.
Backup = true; # copy already present files before applying POTs
#--------------------------------------------------------------------

# print config
print "Update script started. Setup:"
print "  Language:\n    " + LangTag;
print "  SVN repository locations:";
for RepTag in Repositories.keys() :
    print "    \"" + Repositories[RepTag] + "\"";
print "\n";

# prepare paths
BasePath = os.getcwd();
BufPath = os.path.join(BasePath, BufName);
OldPath = os.path.join(BasePath, OldName);
NewPath = os.path.join(BasePath, NewName);

# make sure target dirs are there - if needed
if not os.path.exists(BufPath) :
    if DoPots :
        os.mkdir(BufPath);
if not os.path.exists(OldPath) :
    if CopyOld :
        os.mkdir(OldPath);
if not os.path.exists(NewPath) :
    os.mkdir(NewPath);

# SVN updates
if DoSVNCheckout :
    print "Updating repositories.";
    for Command in SVNCheckoutCommands :
        os.system(Command);
    print "\n";

# browse all repositories
for RepTag in Repositories.keys() :
    SvnRootPath = Repositories[RepTag];
    print "Scanning repository \"" + RepTag + "\" located in \"" + SvnRootPath 
+ "\"";
    
    # list all translation catalogs in repository
    os.chdir(SvnRootPath);
    Catalogs = glob.glob("wesnoth*");

    # browse all catalogs
    for Catalog in Catalogs :
        print "Processing catalog " + Catalog;
        SrcPot = os.path.join(SvnRootPath, Catalog, Catalog + ".pot");
        DestPot = os.path.join(BufPath, Catalog + "-" + RepTag + ".pot");
        SrcFile = os.path.join(SvnRootPath, Catalog, LangTag + ".po");
        DestName = Catalog + "--" + LangTag + "-" + RepTag + ".po";
        OldDestFile = os.path.join(OldPath, DestName);
        NewDestFile = os.path.join(NewPath, DestName);
        if PoFileNotComplete(SrcFile) :
            print "Not complete.";
            # copy files to their new places
            if os.path.isfile(NewDestFile) : # If already exists...
                print "Updating:";
                shutil.copyfile(NewDestFile, NewDestFile + ".bak"); # ...make 
backup...
                os.system("msgmerge -U -v " + NewDestFile + " " + SrcPot); # 
...and update...
            else:
                shutil.copyfile(SrcFile, NewDestFile); # ...otherwise just copy.
                print "Copied.";
            if DoPots :
                shutil.copyfile(SrcPot, DestPot);
            if CopyOld :
                shutil.copyfile(NewDestFile, OldDestFile);
        else :
            print "Complete.";
    print "\n";
print "\nUpdate finished.";
_______________________________________________
Wesnoth-i18n mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-i18n

Reply via email to