How to use the polib.POEntry function in polib

To help you get started, we’ve selected a few polib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edx / i18n-tools / tests / test_extract.py View on Github external
def test_is_keystring(self):
        """
        Verifies is_keystring predicate
        """
        entry1 = polib.POEntry()
        entry2 = polib.POEntry()
        entry1.msgid = "_.lms.admin.warning.keystring"
        entry2.msgid = "This is not a keystring"
        self.assertTrue(extract.is_key_string(entry1.msgid))
        self.assertFalse(extract.is_key_string(entry2.msgid))
github Lucas-C / dotfiles_and_notes / languages / python / twine1_localizer.py View on Github external
def po_from_tws(args):
    tws = load_tws(args.tws_filepath)
    po = polib.POFile()
    po.metadata = {
        'Content-Type': 'text/plain; charset=utf-8',
    }
    for tiddler in tws['storyPanel']['widgets']:
        passage = tiddler['passage']
        if passage.tags != ['Twine.image'] and passage.text:
            po.append(polib.POEntry(
                msgid=passage.title,
                msgstr=passage.text,
            ))
    po.save(args.out_po_filepath)
github specialunderwear / django-easymode / easymode / utils / polibext.py View on Github external
def __init__(self, stream, fpath=None, encoding='utf-8', wrapwidth=78):
        """a pofileparser that can read from a stream"""
        self.fhandle = stream
        self.instance = polib.POFile(fpath=fpath, encoding=encoding)
        self.instance.wrapwidth = wrapwidth
        self.transitions = {}
        self.current_entry = polib.POEntry()
        self.current_state = 'ST'
        self.current_token = None
        self.msgstr_index = 0
        self.entry_obsolete = 0
        all_ = ['ST', 'HE', 'GC', 'OC', 'FL', 'TC', 'MS', 'MP', 'MX', 'MI']

        self.add('TC', ['ST', 'HE'],                                     'HE')
        self.add('TC', ['GC', 'OC', 'FL', 'TC', 'MS', 'MP', 'MX', 'MI'], 'TC')
        self.add('GC', all_,                                             'GC')
        self.add('OC', all_,                                             'OC')
        self.add('FL', all_,                                             'FL')
        self.add('MI', ['ST', 'HE', 'GC', 'OC', 'FL', 'TC', 'MS', 'MX'], 'MI')
        self.add('MP', ['TC', 'GC', 'MI'],                               'MP')
        self.add('MS', ['MI', 'MP', 'TC'],                               'MS')
        self.add('MX', ['MI', 'MX', 'MP', 'TC'],                         'MX')
        self.add('MC', ['MI', 'MP', 'MS', 'MX'],                         'MC')
github Softcatala / translation-memory-tools / source-pos / recull / recull-to-po.py View on Github external
def create_po_entry(source, target):

    s = unicode(source, 'utf-8')
    source = s[0].upper() + s[1:]

    t = unicode(target, 'utf-8')
    target = t[0].upper() + t[1:]

    entry = polib.POEntry(msgid=source, msgstr=target)
    return entry
github ralphje / django-internationalflavor / scripts / mergemessages.py View on Github external
djangofile.metadata = pofile.metadata
                    djangofile.header = pofile.header

                # Merge all non-django messages to the djangofile
                django_only_messages = polib.POFile()
                for entry in pofile:
                    if cldrfile.find(entry.msgid) is None and not entry.obsolete and not 'fuzzy' in entry.flags:
                        django_only_messages.append(entry)
                djangofile.merge(django_only_messages)
                djangofile.save(os.path.join(LOCALE_PATH, lc, 'LC_MESSAGES', 'django_only.po'))

                # Add all entries from the CLDR file to the combined file
                for entry in cldrfile:
                    e = pofile.find(entry.msgid)
                    if e is None:
                        e = polib.POEntry()
                        e.msgid = entry.msgid
                        pofile.append(e)
                    elif 'manual' in e.tcomment.lower():
                        self.stdout.write("-- Skipping %s of %s" % (e.msgid, language))
                        continue

                    e.obsolete = False
                    e.msgstr = entry.msgstr
                    e.comment = entry.comment
                    if 'fuzzy' in e.flags:
                        e.flags.remove('fuzzy')

                # Add entries from the Django file to the combined file
                for entry in djangofile:
                    e = pofile.find(entry.msgid)
                    # If not in main file, then skip
github multitheftauto / mtasa-blue / utils / src / build_gettext_catalog_nsi.py View on Github external
LangStringCache[value] = []
            # Note down our file and line number
            LangStringCache[value].append([options.input,lineNo])

            if not value in LangStringLabels:
                LangStringLabels[value] = []
            # Note down our label
            LangStringLabels[value].append(label)
            
    line=NSIWorkingFile.readline()
    lineNo += 1

# Now, we loop through our cache and build PO entries for each
# We use PO comment field to store our NSIS labels, so we can decode it back later
for msgid,lineOccurances in LangStringCache.iteritems():
    entry = polib.POEntry(
        msgid=msgid,
        msgstr='',
        occurrences=lineOccurances,
        comment=(" ").join(LangStringLabels[msgid])
    )
    poFile.append(entry)


NSIWorkingFile.close()

# Finally, let's generate our POT file
poFile.save(options.output)

print ( "NSI POT Export Operation complete" )
github manylegged / outlaws-core / scripts / langtool.py View on Github external
def lua2po(luaf, pof):
    with open(luaf) as fil:
        luadata = fil.read()
    newpo = polib.POFile()
    if "web_header" in luadata:
        luadata = luadata[:luadata.index("web_header")]
    luadata = re.sub("--.*\n", "", luadata)
    for st in re.findall('"[^"]+"', luadata):
        st = st[1:-1].replace("\\\n", "")
        if len(st) > 2:
            newpo.append(polib.POEntry(msgid=st))

    if os.path.exists(pof):
        pofil = open_po(pof)
        pofil.merge(newpo)
    else:
        pofil = newpo
    pofil.header = header(luaf)
    pofil.save(pof)
github hsoft / moneyguru / hscommon / loc.py View on Github external
def strings2pot(target, dest):
    with open(target, 'rt', encoding='utf-8') as fp:
        contents = fp.read()
    # We're reading an en.lproj file. We only care about the righthand part of the translation.
    re_trans = re.compile(r'".*" = "(.*)";')
    strings = re_trans.findall(contents)
    if op.exists(dest):
        po = polib.pofile(dest)
    else:
        po = polib.POFile()
    for s in dedupe(strings):
        s = unescape_cocoa_strings(s)
        entry = po.find(s)
        if entry is None:
            entry = polib.POEntry(msgid=s)
            po.append(entry)
        # we don't know or care about a line number so we put 0
        entry.occurrences.append((target, '0'))
        entry.occurrences = dedupe(entry.occurrences)
    po.save(dest)
github dolphin-emu / www / dolweb / docs / views.py View on Github external
po = polib.POFile()
    po.metadata = {
        'Project-Id-Version': '1.0',
        'Report-Msgid-Bugs-To': 'contact@dolphin-emu.org',
        'MIME-Version': '1.0',
        'Content-Type': 'text/plain; charset=utf-8',
        'Content-Transfer-Encoding': '8bit',
    }

    for cat in FAQCategory.objects.order_by('display_order'):
        po.append(polib.POEntry(msgid=cat.title, msgstr='', msgctxt='Category title'))
        for q in cat.sorted_questions():
            po.append(polib.POEntry(msgid=q.title, msgstr='', msgctxt='Question title'))
            po.append(polib.POEntry(msgid=q.short_title, msgstr='',
                                    msgctxt='Question short title (displayed in the left column)'))
            po.append(polib.POEntry(msgid=q.text, msgstr='', msgctxt='Answer'))
    return HttpResponse(str(po), content_type='text/plain')