def loadTemplate(fName="template.trn"):
    """Load the template fName file in the global template variable.
    Returns the template."""
    global template
    global trnHeader
    global strNum
    fName = os.path.join(getLangPath(), fName)
    if os.access(fName, os.F_OK) and os.path.isfile(fName) and os.access(fName, os.R_OK):
        oldData = codecs.open(fName, "r", "utf-8").read() + buildTemplateMarker
        trnHeader = u""
        # find the first oXX
        start = re.search(ur"^o\d+[ ]", oldData, re.M|re.S)
        if start:
            start = start.start()
        else:
            print "*** %s malformed. Could not find entry point.\n    Template not loaded."%os.path.split(fName)[-1]
        trnHeader += oldData[:max(0, start - 1)]
        trnPattern = re.compile(ur"^o\d+[ ]|^t\d+[ ]", re.M|re.S)
        grps = re.finditer(trnPattern, oldData)
        oStart = -1
        oEnd = -1
        tStart = -1
        tEnd = -1
        org = None
        num = 0
        oNum = -1
        tNum = -1
        for grp in grps:
            g = grp.group()
            if g.startswith(u"o"):
                oStart = grp.end()
                tEnd = grp.start() - 1
                oNum = int(g[1:])
            elif g.startswith(u"t"):
                oEnd = grp.start() - 1
                tStart = grp.end()
                tNum = int(g[1:])
            if oNum == tNum:
                org = oldData[oStart:oEnd]
            if tStart > -1 and (tEnd > -1):
                if tEnd >= tStart:
                    template[num] = (org, oldData[tStart:tEnd])
                    num += 1
                    tStart = -1
                    tEnd = -1
        template[num] = (org, oldData[tStart:tEnd])
        strNum = num
    return template
Load the template fName file in the global template variable.
    Returns the template.
albow/translate.py