How to use the polib.escape 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 transifex / transifex / transifex / webtrans / fields.py View on Github external
def _calculate_rows(entry):
    """Return the estimated number of rows for a textarea based on string size."""
    text = getattr(entry, 'msgid', entry)
    if isinstance(text, str):
        text = text.decode(getattr(entry, 'encoding', 'UTF-8'))
    replacement = polib.escape(text).replace(r'\n','<br>\n')
    lines = mark_safe(replacement).split(u'\n')
    return sum(len(line)/40 for k, line in enumerate(lines)) + 1
github transifex / transifex / transifex / webtrans / forms.py View on Github external
if 'fuzzy' in entry.flags:
                    fuzzy=True
                else:
                    fuzzy=False

                if entry.msgid_plural:
                    message_keys = entry.msgstr_plural.keys()
                    message_keys.sort()
                    messages = [entry.msgstr_plural[key] for key in message_keys]
                    msgstr_field = PluralMessageField(
                        entry=entry,
                        initial=messages,
                        help_text=self.help_text(entry),
                        label=_get_label([polib.escape(entry.msgid),
                            polib.escape(entry.msgid_plural)]),
                        attrs=attrs,
                        required=False,
                    )
                else:
                    msgstr_field = MessageField(
                        entry=entry,
                        initial=polib.escape(entry.msgstr),
                        help_text=self.help_text(entry),
                        attrs=attrs,
                        label=_get_label([polib.escape(entry.msgid)]),
                        required=False,
                        )
                msgid_field = MessageField(entry=entry, widget=forms.HiddenInput,
                    initial=polib.escape(entry.msgid))
                fuzzy_field = forms.BooleanField(required=False, initial=fuzzy)
github ilius / pyglossary / pyglossary / plugins / gettext_po.py View on Github external
def write(glos, filename, resources=True):
	from polib import escape as po_escape
	with open(filename, "w") as toFile:
		toFile.write("#\nmsgid ""\nmsgstr ""\n")
		for key, value in glos.iterInfo():
			toFile.write('"%s: %s\\n"\n' % (key, value))
		for entry in glos:
			if entry.isData():
				if resources:
					entry.save(filename + "_res")
				continue
			word = entry.getWord()
			defi = entry.getDefi()
			toFile.write("msgid %s\nmsgstr %s\n\n" % (
				po_escape(word),
				po_escape(defi),
			))
github transifex / transifex / transifex / addons / lotte / views.py View on Github external
# similar langs, all in a dictionary (see also below)
                _get_source_strings(s, source_language, language.code, more_languages),
                # 4. Get all the Translation strings mapped with plural rules
                # in a single dictionary (see docstring of function)
                _get_strings(translated_strings, language, s.source_entity),
                # 5. A number which indicates the number of Suggestion objects
                # attached to this row of the table.
                Suggestion.objects.filter(source_entity=s.source_entity, language__code=language.code).count(),
                # 6. save buttons and hidden context (ready to inject snippet)
                # It includes the following content, wrapped in span tags:
                # * SourceEntity object's "context" value
                # * SourceEntity object's "id" value
                ('<span title="' + _(" style="border:0" id="save_' + str(counter) + '" class="save edit-panel inactive"></span>'
                 '<span title="' + _(" style="border:0" id="spellcheck_' + str(counter) + '" class="spellcheck edit-panel inactive"></span>'
                 '<span title="' + _(" style="border:0" id="undo_' + str(counter) + '" class="undo edit-panel inactive"></span>'
                 '<span style="display:none;" id="context_' + str(counter) + '" class="context">' + escape(str(s.source_entity.context_string.encode('UTF-8'))) + '</span>'
                 '<span style="display:none;" id="sourceid_' + str(counter) + '" class="source_id">' + str(s.source_entity.id) + '</span>'),
            ] for counter,s in enumerate(source_strings[dstart:dstart+dlength])
        ],
    }

    if review:
        for counter, s in enumerate(source_strings[dstart:dstart+dlength]):
            try:
                translation = Translation.objects.get(
                    source_entity__id=s.source_entity.id,
                    language__code=language.code, rule=5
                )
                review_snippet = '<span><input value="Review" name="review" type="checkbox" id="review_source_' + str(s.source_entity.id) + '" title="' + _(" class="review-check"></span>',
            except Translation.DoesNotExist:
                review_snippet = '<span><input value="Review" disabled="disabled" name="review" type="checkbox" id="review_source_' + str(s.source_entity.id) + '" title="' + _(" class="review-check"></span>',
github transifex / transifex / transifex / webtrans / forms.py View on Github external
label=_get_label([polib.escape(entry.msgid),
                            polib.escape(entry.msgid_plural)]),
                        attrs=attrs,
                        required=False,
                    )
                else:
                    msgstr_field = MessageField(
                        entry=entry,
                        initial=polib.escape(entry.msgstr),
                        help_text=self.help_text(entry),
                        attrs=attrs,
                        label=_get_label([polib.escape(entry.msgid)]),
                        required=False,
                        )
                msgid_field = MessageField(entry=entry, widget=forms.HiddenInput,
                    initial=polib.escape(entry.msgid))
                fuzzy_field = forms.BooleanField(required=False, initial=fuzzy)

                self.fields['msgid_field_%s' % k] = msgid_field
                self.fields['fuzzy_field_%s' % k] = fuzzy_field
                self.fields['msgstr_field_%s' % k] = msgstr_field
github transifex / transifex / transifex / webtrans / forms.py View on Github external
def help_text(self, entry):
        """Return the comments of a field."""
        occurrences = ["%s (line %s)" % (file, line) for (file, line) in entry.occurrences]
        return render_to_string('webtrans/comments.html', {
            'comment': polib.escape(entry.comment),
            'msgctxt': entry.msgctxt,
            'occurrences': '%s' % ('\n'.join(occurrences)),})
github transifex / transifex / transifex / webtrans / forms.py View on Github external
msgstr_field = PluralMessageField(
                        entry=entry,
                        initial=messages,
                        help_text=self.help_text(entry),
                        label=_get_label([polib.escape(entry.msgid),
                            polib.escape(entry.msgid_plural)]),
                        attrs=attrs,
                        required=False,
                    )
                else:
                    msgstr_field = MessageField(
                        entry=entry,
                        initial=polib.escape(entry.msgstr),
                        help_text=self.help_text(entry),
                        attrs=attrs,
                        label=_get_label([polib.escape(entry.msgid)]),
                        required=False,
                        )
                msgid_field = MessageField(entry=entry, widget=forms.HiddenInput,
                    initial=polib.escape(entry.msgid))
                fuzzy_field = forms.BooleanField(required=False, initial=fuzzy)

                self.fields['msgid_field_%s' % k] = msgid_field
                self.fields['fuzzy_field_%s' % k] = fuzzy_field
                self.fields['msgstr_field_%s' % k] = msgstr_field
github transifex / transifex / transifex / addons / lotte / views.py View on Github external
def spellcheck(request, project_slug, lang_code, resource_slug=None):
    """
    Shows mispelled words along with suggestions
    """
    data = simplejson.loads(request.raw_post_data)
    lang_code = lang_code.encode('utf-8')
    string = escape(data["text"])
    string_ = string
    string = string.encode('utf-8')
    lang_codes = SPELLCHECK_SUPPORTED_LANGS
    if lang_code in lang_codes:
        xmlData = '''
                        
                            
                        '''%(lang_code, string)
        headers = {"Content-type": "text/xml; charset=utf-8",
                   "Request-number":"1",
                   "Document-type":"Request",
                   "Connection":"close"}
        con = httplib.HTTPSConnection('www.google.com')
        con.request('POST', '/tbproxy/spell?lang=%s'%(lang_code), xmlData, headers)
        response = con.getresponse().read().decode('utf-8')
        pattern = re.compile(r'(?P[^&lt;]*)&lt;\/c&gt;', re.UNICODE)