Exemplo n.º 1
0
    def create(msgid):
        entry = catalog.dict.get(msgid, None)
        # is_valid_translation = True if entry and entry.translated() else False
        # is_valid_translation = True if entry and entry.msgstr is not u"" or None \
        #     and not entry.obsolete else False
        is_valid_translation = utils.is_translated(entry)

        # if translated:
        #    print "\n\n", str(is_valid_translation), ", "
        #    print "Test= ", msg, translated, "==", encode(translated.msgstr), \
        #        ", file=", str(translated.pfile), "obs=", str(translated.obsolete), "\n"

        if is_valid_translation:
            msg_target = entry.msgstr
        else:
            msg_target = _(msgid)

        if not is_valid_translation:
            css_class = 'rosetta-inpage-todo'
        elif entry and 'fuzzy' in entry.flags:
            css_class = 'rosetta-inpage-fuzzy'
        else:
            css_class = 'rosetta-inpage-foo'

        return {
            'show': show_message(msgid, view_locale),
            'hash': rosetta_inpage.hash_text(msgid),
            'source': mark_safe(msg),       # the source message
            'msg': mark_safe(msg_target),   # the translated message
            'translated': is_valid_translation,
            'fuzzy': False if entry and 'fuzzy' not in entry.flags else True,
            'css_class': css_class
        }
Exemplo n.º 2
0
def _new_ugettext(message):
    mode = getattr(THREAD_LOCAL_STORAGE, EDIT_MODE, False)

    if mode:
        from rosetta_inpage.utils import get_message, is_translated
        locale = getattr(THREAD_LOCAL_STORAGE, REQUEST_LOCALE)
        messages = getattr(THREAD_LOCAL_STORAGE, MESSAGES)
        messages.add(message)

        #id = hash_text(message)
        #return mark_safe('<span contenteditable="false" id="' + id + '">' + original(message) + '</span>')
        entry = get_message(message, locale)

        # if entry and entry.translated():
        if is_translated(entry):
            return mark_safe(entry.msgstr)
        else:
            return original(message)
    else:
        return original(message)