Beispiel #1
0
def jinja2_cleaner(fileobj, *args, **kw):
    """
    This function take badly formatted html with strings etc and make it beautiful
    generally remove surlus whitespace and kill \n this will break <code><pre>
    tags but they should not be being translated.

    This code is based on CKAN
    Copyright (C) 2007 Open Knowledge Foundation
    license: AGPL V3.

    :param fileobj:
    :param args:
    :param kw:
    :return:
    """

    kw['options']['extensions'] = jinja_extensions

    raw_extract = extract_jinja2(fileobj, *args, **kw)

    for lineno, func, message, finder in raw_extract:

        if isinstance(message, str):
            message = je.regularise_html(message)
        elif message is not None:
            message = (je.regularise_html(message[0]),
                       je.regularise_html(message[1]))

        yield lineno, func, message, finder
def jinja2_cleaner(fileobj, *args, **kw):

    # Take badly formatted html with strings etc before goes to the translation .pot file

    # This code is based on CKAN code which is licensed as follows
    #
    # CKAN - Data Catalogue Software
    # Copyright (C) 2007 Open Knowledge Foundation
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, or (at your option) any later version.
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU Affero General Public License for more details.
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <http://www.gnu.org/licenses/>.

    kw['options']['extensions'] = jinja_extensions

    raw_extract = extract_jinja2(fileobj, *args, **kw)

    for lineno, func, message, finder in raw_extract:

        if isinstance(message, basestring):
            message = je.regularise_html(message)
        elif message is not None:
            message = (je.regularise_html(message[0])
                       ,je.regularise_html(message[1]))

        yield lineno, func, message, finder
Beispiel #3
0
def jinja2_cleaner(fileobj, *args, **kw):
    # We want to format the messages correctly and intercepting here seems
    # the best location
    # add our custom tags
    kw['options']['extensions'] = jinja_extensions

    raw_extract = extract_jinja2(fileobj, *args, **kw)

    for lineno, func, message, finder in raw_extract:

        if isinstance(message, basestring):
            message = lib.jinja_extensions.regularise_html(message)
        elif message is not None:
            message = (lib.jinja_extensions.regularise_html(message[0])
                       ,lib.jinja_extensions.regularise_html(message[1]))

        yield lineno, func, message, finder
Beispiel #4
0
def jinja2_cleaner(fileobj, *args, **kw):
    # We want to format the messages correctly and intercepting here seems
    # the best location
    # add our custom tags
    kw['options']['extensions'] = jinja_extensions

    raw_extract = extract_jinja2(fileobj, *args, **kw)

    for lineno, func, message, finder in raw_extract:

        if isinstance(message, string_types):
            message = ckan.lib.jinja_extensions.regularise_html(message)
        elif message is not None:
            message = (ckan.lib.jinja_extensions.regularise_html(message[0]),
                       ckan.lib.jinja_extensions.regularise_html(message[1]))

        yield lineno, func, message, finder
Beispiel #5
0
def jinja2_cleaner(fileobj, *args, **kw):

    # Extract the messages from jinja2 files but taking into consideration custom extensions

    # This code is based on CKAN
    # :Copyright (C) 2007 Open Knowledge Foundation
    # :license: AGPL V3, see LICENSE for more details.

    kw["options"]["extensions"] = jinja_extensions

    raw_extract = extract_jinja2(fileobj, *args, **kw)

    for lineno, func, message, finder in raw_extract:

        if isinstance(message, str):
            message = je.regularise_html(message)
        elif message is not None:
            message = (je.regularise_html(message[0]),
                       je.regularise_html(message[1]))

        yield lineno, func, message, finder
Beispiel #6
0
def extract_jade(fileobj, keywords, comment_tags, options):
    jinja = compile_jade(fileobj.read(), fileobj.name,
                         compiler=Jinja2Compiler)

    return extract_jinja2(BytesIO(jinja.encode('UTF-8')),
                          keywords, comment_tags, options)