예제 #1
0
    def __init__(self, resxen2name, resxlocale, potemplate, out_path, code):
        if os.path.isfile(resxen2name) is False:
            raise Exception("Resx bound not found")

        if os.path.isfile(resxlocale) is False:
            raise Exception("Resx trans not found")

        if os.path.isfile(potemplate) is False:
            raise Exception("PO template not found")

        bound = resx2dict(resxen2name)
        trans = resx2dict(resxlocale)

        motable = {}
        for boundk in sorted(bound, key=len, reverse=True):
            if boundk in trans:
                motable[bound[boundk]] = trans[boundk]
            else:
                print(
                    "WARNING: {} not found in {}, wont be added into motable".
                    format(boundk, resxen2name))

        po = polib.pofile(potemplate)

        po.metadata = {
            'Project-Id-Version': '1.0',
            'Report-Msgid-Bugs-To': '*****@*****.**',
            'POT-Creation-Date': '2016-01-19 02:00+0100',
            'PO-Revision-Date': '2016-01-19 02:00+0100',
            'Last-Translator': 'Adam Schubert <*****@*****.**>',
            'Language-Team': '',
            'MIME-Version': '1.0',
            'Content-Type': 'text/plain; charset=utf-8',
            'Content-Transfer-Encoding': '8bit',
            'Language': code
        }
        for entry in po:
            if entry.msgid in motable:
                entry.msgstr = motable[entry.msgid]
            else:
                print("WARNING: {} not found in {}".format(
                    entry.msgid, 'motable'))

        po.save()
        po.save_as_mofile(os.path.join(out_path, '{}.mo'.format(code)))
        shutil.copy2(potemplate, os.path.join(out_path, '{}.po'.format(code)))
예제 #2
0
    def __init__(self, resxen2name, resxlocale, potemplate, out_path, code):
        if os.path.isfile(resxen2name) is False:
            raise Exception("Resx bound not found")

        if os.path.isfile(resxlocale) is False:
            raise Exception("Resx trans not found")

        if os.path.isfile(potemplate) is False:
            raise Exception("PO template not found")

        bound = resx2dict(resxen2name)
        trans = resx2dict(resxlocale)

        motable = {}
        for boundk in sorted(bound, key=len, reverse=True):
            if boundk in trans:
                motable[bound[boundk]] = trans[boundk]
            else:
                print("WARNING: {} not found in {}, wont be added into motable".format(boundk, resxen2name))

        po = polib.pofile(potemplate)

        po.metadata = {
            'Project-Id-Version': '1.0',
            'Report-Msgid-Bugs-To': '*****@*****.**',
            'POT-Creation-Date': '2016-01-19 02:00+0100',
            'PO-Revision-Date': '2016-01-19 02:00+0100',
            'Last-Translator': 'Adam Schubert <*****@*****.**>',
            'Language-Team': '',
            'MIME-Version': '1.0',
            'Content-Type': 'text/plain; charset=utf-8',
            'Content-Transfer-Encoding': '8bit',
            'Language': code
        }
        for entry in po:
            if entry.msgid in motable:
                entry.msgstr = motable[entry.msgid]
            else:
                print("WARNING: {} not found in {}".format(entry.msgid, 'motable'))

        po.save()
        po.save_as_mofile(os.path.join(out_path, '{}.mo'.format(code)))
        shutil.copy2(potemplate, os.path.join(out_path, '{}.po'.format(code)))
    def __init__(self, resx, pyfile, pyfileo, resclasspath):
        if os.path.isfile(resx) is False:
            raise Exception("Resx file not found")

        if os.path.isfile(pyfile) is False:
            raise Exception("Pyfile not found")

        table = resx2dict(resx)

        f = open(pyfile,'r')
        filedata = f.read()
        f.close()

        for key in sorted(table, key=len, reverse=True):
            filedata = filedata.replace("{}.{}".format('.'.join(resclasspath), key), '_("{}")'.format(table[key]))

        f = open(pyfileo + '.new' if pyfileo == pyfile else pyfileo,'w')
        f.write(filedata)
        f.close()
예제 #4
0
    def __init__(self, resx, pyfile, pyfileo, resclasspath):
        if os.path.isfile(resx) is False:
            raise Exception("Resx file not found")

        if os.path.isfile(pyfile) is False:
            raise Exception("Pyfile not found")

        table = resx2dict(resx)

        f = open(pyfile,'r')
        filedata = f.read()
        f.close()

        for key in sorted(table, key=len, reverse=True):
            filedata = filedata.replace("{}.{}".format('.'.join(resclasspath), key), '_("{}")'.format(table[key]))

        f = open(pyfileo + '.new' if pyfileo == pyfile else pyfileo,'w')
        f.write(filedata)
        f.close()