Пример #1
0
def makeMO(applicationDirectoryPath, targetDir=None, applicationDomain=None, verbose=0, forceEnglish=0):
    """Compile the Portable Object files into the Machine Object stored in the right location.
    makeMO converts all translated language-specific PO files located inside 
    the  application directory into the binary .MO files stored inside the 
    LC_MESSAGES sub-directory for the found locale files.
    makeMO searches for all files that have a name of the form 'app_xx.po' 
    inside the application directory specified by the first argument.  The 
    'app' is the application domain name (that can be specified by the 
    applicationDomain argument or is taken from the directory name). The 'xx' 
    corresponds to one of the ISO 639 two-letter language codes.
    makeMo stores the resulting files inside a sub-directory of `targetDir` 
    called xx/LC_MESSAGES where 'xx' corresponds to the 2-letter language 
    code.
    """
    if targetDir is None:
        targetDir = "exe/locale"
    if verbose:
        print "Target directory for .mo files is: %s" % targetDir
    targetDir = Path(targetDir)
    if applicationDomain is None:
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
    else:
        applicationName = applicationDomain
    currentDir = os.getcwd()
    os.chdir(applicationDirectoryPath)
    for filename in targetDir.glob("*_*.po"):
        langCode = filename.split("_", 1)[1].split(".", 1)[0]
        mo_targetDir = Path("%s/%s/LC_MESSAGES" % (targetDir, langCode))
        if not mo_targetDir.exists():
            mo_targetDir.makedirs()
        cmd = "msgfmt --output-file=%s.mo %s" % (mo_targetDir / applicationName, filename)
        if verbose:
            print cmd
        os.system(cmd)
    os.chdir(currentDir)
Пример #2
0
def makePO(applicationDirectoryPath, applicationDomain=None, verbose=1):
    """Build the Portable Object Template file for the application.
    makePO builds the .pot file for the application stored inside 
    a specified directory by running xgettext for all application source 
    files.  It finds the name of all files by looking for a file called 'app.fil'. 
    If this file does not exists, makePo raises an IOError exception.
    By default the application domain (the application
    name) is the same as the directory name but it can be overridden by the 
    'applicationDomain' argument.
    makePO always creates a new file called messages.pot.  If it finds files 
    of the form app_xx.po where 'app' is the application name and 'xx' is one 
    of the ISO 639 two-letter language codes, makePO resynchronizes those 
    files with the latest extracted strings (now contained in messages.pot). 
    This process updates all line location number in the language-specific
    .po files and may also create new entries for translation (or comment out 
    some).  The .po file is not changed, instead a new file is created with 
    the .new extension appended to the name of the .po file.
    By default the function does not display what it is doing.  Set the 
    verbose argument to 1 to force it to print its commands.
    """
    if applicationDomain is None:
        applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
    else:
        applicationName = applicationDomain
    currentDir = os.getcwd()
    os.chdir(applicationDirectoryPath)
    if not os.path.exists("app.fil"):
        raise IOError(2, "No module file: app.fil")
    cmd = "xgettext -kx_ -s --no-wrap --files-from=app.fil " "--output=messages.pot --from-code=utf8"
    if verbose:
        print cmd
    os.system(cmd)
    os.chdir(currentDir)
    makeXulPO(applicationDirectoryPath, applicationDomain, verbose)
    localeDirs = Path("exe/locale")
    for filename in localeDirs.glob("*_*.po"):
        cmd = "msgmerge -U --no-wrap %s messages.pot" % filename
        if verbose:
            print cmd
        os.system(cmd)