Пример #1
0
def do_compile(potfile, srcfiles):
    """
    Search C++, Lua and conf files given in srcfiles for translatable strings.
    Merge the results and write out the corresponding pot file.
    """
    files = []
    for i in srcfiles:
        files += glob(i)
    files = set(files)

    cpp_files = set([ f for f in files if
        os.path.splitext(f)[-1].lower() == '.cc' or os.path.splitext(f)[-1].lower() == '.h'])
    lua_files = set([ f for f in files if
        os.path.splitext(f)[-1].lower() == '.lua' ])
    conf_files = files - cpp_files - lua_files

    temp_potfile = potfile + ".tmp"
    if (os.path.exists(temp_potfile)):
        os.remove(temp_potfile)

    # Find translatable strings in C++ and Lua files using xgettext
    if len(cpp_files) > 0:
        run_xgettext(cpp_files, temp_potfile, XGETTEXTOPTS)
    if len(lua_files) > 0:
        if os.path.exists(temp_potfile):
            run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS + " --join-existing")
        else:
            run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS)

    xgettext_found_something_to_translate = os.path.exists(temp_potfile)

    # Find translatable strings in configuration files
    conf = Conf_GetText()
    conf.parse(conf_files)

    if not (xgettext_found_something_to_translate or conf.found_something_to_translate):
        # Found no translatable strings
        return False

    if (xgettext_found_something_to_translate):
        header_fixed = pot_modify_header(temp_potfile, potfile, HEAD)
        os.remove(temp_potfile)

        if not header_fixed:
            raise BuildcatError("Failed to fix header.")

        if (conf.found_something_to_translate):
            # Merge the conf POT with C++/Lua POT
            with open(potfile, "at") as p:
                p.write("\n" + conf.toString())

            run_msguniq(potfile)
    elif (conf.found_something_to_translate):
        with open(potfile, "wt") as p:
            p.write(HEAD + conf.toString())

        # Msguniq is run here only to sort POT entries by file
        run_msguniq(potfile)

    return True
Пример #2
0
def do_compile( potfile, srcfiles ):
    """
    Search Lua and conf files given in srcfiles for translatable strings.
    Merge the results and write out the corresponding pot file.
    """
    files = []
    for i in srcfiles:
        files += glob(i)
    files = set(files)

    lua_files = set([ f for f in files if
        os.path.splitext(f)[-1].lower() == '.lua' ])
    conf_files = files - lua_files
    
    temp_potfile = potfile + ".tmp"
    
    if (os.path.exists(temp_potfile)): os.remove(temp_potfile)
    
    # Find translatable strings in Lua files using xgettext
    xgettext = subprocess.Popen("xgettext %s --files-from=- --output=\"%s\"" % \
        (LUAXGETTEXTOPTS, temp_potfile), shell=True, stdin=subprocess.PIPE, universal_newlines=True)
    try:
        for fname in lua_files:
            xgettext.stdin.write(os.path.normpath(fname) + "\n")
        xgettext.stdin.close()
    except IOError as err_msg:
        sys.stderr.write("Failed to call xgettext: %s\n" % err_msg)
        return False
    
    xgettext_status = xgettext.wait()
    if (xgettext_status != 0):
        sys.stderr.write("xgettext exited with errorcode %i\n" % xgettext_status)
        return False
        
    xgettext_found_something_to_translate = os.path.exists(temp_potfile)
    
    # Find translatable strings in configuration files
    conf = Conf_GetText()
    conf.parse(conf_files)
    
    if not (xgettext_found_something_to_translate or conf.found_something_to_translate):
        # Found no translatable strings
        return False
    
    if (xgettext_found_something_to_translate):
        header_fixed = pot_modify_header(temp_potfile, potfile, HEAD)
        os.remove(temp_potfile)
        
        if not header_fixed:
            return False
        
        if (conf.found_something_to_translate):
            # Merge the conf POT with Lua POT
            with open(potfile, "at") as p:
                p.write("\n" + conf.toString())
                
            if not run_msguniq(potfile):
                return False
    elif (conf.found_something_to_translate):
        with open(potfile, "wt") as p:
            p.write(HEAD + conf.toString())
            
        # Msguniq is run here only to sort POT entries by file
        if not run_msguniq(potfile):
            return False

    return True
Пример #3
0
def do_compile(potfile, srcfiles):
    """Search C++, Lua and conf files given in srcfiles for translatable
    strings.

    Merge the results and write out the corresponding pot file.

    """
    files = []
    for i in srcfiles:
        files += glob(i)
    files = set(files)

    cpp_files = set([
        f for f in files if os.path.splitext(f)[-1].lower() == '.cc'
        or os.path.splitext(f)[-1].lower() == '.h'
    ])
    lua_files = set(
        [f for f in files if os.path.splitext(f)[-1].lower() == '.lua'])
    conf_files = files - cpp_files - lua_files

    temp_potfile = potfile + '.tmp'
    if (os.path.exists(temp_potfile)):
        os.remove(temp_potfile)

    # Find translatable strings in C++ and Lua files using xgettext
    if len(cpp_files) > 0:
        run_xgettext(cpp_files, temp_potfile, XGETTEXTOPTS)
    if len(lua_files) > 0:
        if os.path.exists(temp_potfile):
            run_xgettext(lua_files, temp_potfile,
                         LUAXGETTEXTOPTS + ' --join-existing')
        else:
            run_xgettext(lua_files, temp_potfile, LUAXGETTEXTOPTS)

    xgettext_found_something_to_translate = os.path.exists(temp_potfile)

    # Find translatable strings in configuration files
    conf = Conf_GetText()
    conf.parse(conf_files)

    if not (xgettext_found_something_to_translate
            or conf.found_something_to_translate):
        # Found no translatable strings
        return False

    if (xgettext_found_something_to_translate):
        header_fixed = pot_modify_header(temp_potfile, potfile, HEAD)
        os.remove(temp_potfile)

        if not header_fixed:
            raise BuildcatError('Failed to fix header.')

        if (conf.found_something_to_translate):
            # Merge the conf POT with C++/Lua POT
            with open(potfile, 'at') as p:
                p.write('\n' + conf.toString())

            run_msguniq(potfile)
    elif (conf.found_something_to_translate):
        with open(potfile, 'wt') as p:
            p.write(HEAD + conf.toString())

        # Msguniq is run here only to sort POT entries by file
        run_msguniq(potfile)

    return True