コード例 #1
0
    def render(self, context):
        if 'user' in context:
            user = context['user']
        elif 'request' in context:
            user = getattr(context.get('request'), 'user', None)
        else:
            user = None
        if not (user and get_user_can_translate(user)):
            self.filter_expression.var.translate = not self.noop
            output = self.filter_expression.resolve(context)
            return _render_value_in_context(output, context)

        if getattr(self.filter_expression.var, 'literal'):
            msgid = self.filter_expression.var.literal
        else:
            msgid = self.filter_expression.resolve(context)
        cat = copy.copy(catalog())
        cat.add_fallback(NotTranslated)
        styles = ['translatable']
        try:
            if sys.version_info[0] == 2:
                msgstr = cat.ugettext(msgid)
            else:
                msgstr = cat.gettext(msgid)
        except (ValueError, AttributeError):
            styles.append("untranslated")
            msgstr = msgid
        return render_to_string('inlinetrans/inline_trans.html', {
            'msgid': msgid,
            'styles': ' '.join(styles),
            'value': msgstr
        })
コード例 #2
0
    def render(self, context):
        if "user" in context:
            user = context["user"]
        elif "request" in context:
            user = getattr(context.get("request"), "user", None)
        else:
            user = None
        if not (user and get_user_can_translate(user)):
            self.filter_expression.var.translate = not self.noop
            output = self.filter_expression.resolve(context)
            return _render_value_in_context(output, context)

        if getattr(self.filter_expression.var, "literal"):
            msgid = self.filter_expression.var.literal
        else:
            msgid = self.filter_expression.resolve(context)
        cat = copy.copy(catalog())
        cat.add_fallback(NotTranslated)
        styles = ["translatable"]
        try:
            if sys.version_info[0] == 2:
                msgstr = cat.ugettext(msgid)
            else:
                msgstr = cat.gettext(msgid)
        except (ValueError, AttributeError):
            styles.append("untranslated")
            msgstr = msgid
        return render_to_string(
            "inlinetrans/inline_trans.html", {"msgid": msgid, "styles": " ".join(styles), "value": msgstr}
        )
コード例 #3
0
ファイル: i18n.py プロジェクト: EKMeyerson/django
 def render(self, context):
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     # Escape all isolated '%'
     singular = re.sub(u'%(?!\()', u'%%', singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         plural = re.sub(u'%(?!\()', u'%%', plural)
         result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         result = translation.ugettext(singular)
     data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
     context.pop()
     try:
         result = result % data
     except KeyError:
         with translation.override(None):
             result = self.render(context)
     return result
コード例 #4
0
    def render(self, context):
        if 'user' in context:
            user = context['user']
        elif 'request' in context:
            user = getattr(context.get('request'), 'user', None)
        else:
            user = None
        if not (user and user.is_staff):
            self.filter_expression.var.translate = not self.noop
            output = self.filter_expression.resolve(context)
            return _render_value_in_context(output, context)

        if getattr(self.filter_expression.var, 'literal'):
            msgid = self.filter_expression.var.literal
        else:
            msgid = self.filter_expression.resolve(context)
        cat = copy.copy(catalog())
        cat.add_fallback(NotTranslated)
        styles = ['translatable']
        try:
            msgstr = cat.ugettext(msgid)
        except ValueError:
            styles.append("untranslated")
            msgstr = msgid
        return render_to_string('inlinetrans/inline_trans.html',
                                {'msgid': msgid,
                                 'styles': ' '.join(styles),
                                 'value': msgstr})
コード例 #5
0
ファイル: defaulttags.py プロジェクト: bheesink/django
 def render(self, context):
     for var in self.vars:
         value = var.resolve(context, True)
         if value:
             if not self.escape:
                 value = mark_safe(value)
             return _render_value_in_context(value, context)
     return ''
コード例 #6
0
ファイル: defaulttags.py プロジェクト: AndBicScadMedia/django
 def render(self, context):
     for var in self.vars:
         value = var.resolve(context, True)
         if value:
             if not self.escape:
                 value = mark_safe(value)
             return _render_value_in_context(value, context)
     return ''
コード例 #7
0
ファイル: i18n.py プロジェクト: VasiliyZaytsev/django
 def render(self, context):
     self.filter_expression.var.translate = not self.noop
     output = self.filter_expression.resolve(context)
     value = _render_value_in_context(output, context)
     if self.asvar:
         context[self.asvar] = value
         return ''
     else:
         return value
コード例 #8
0
 def render(self, context):
     self.filter_expression.var.translate = not self.noop
     if self.message_context:
         self.filter_expression.var.message_context = (
             self.message_context.resolve(context))
     output = self.filter_expression.resolve(context)
     value = _render_value_in_context(output, context)
     if self.asvar:
         context[self.asvar] = value
         return ''
     else:
         return value
コード例 #9
0
ファイル: defaulttags.py プロジェクト: AndBicScadMedia/django
 def render(self, context):
     if self not in context.render_context:
         # First time the node is rendered in template
         context.render_context[self] = itertools_cycle(self.cyclevars)
     cycle_iter = context.render_context[self]
     value = next(cycle_iter).resolve(context)
     if self.variable_name:
         context[self.variable_name] = value
     if self.silent:
         return ''
     if not self.escape:
         value = mark_safe(value)
     return _render_value_in_context(value, context)
コード例 #10
0
ファイル: defaulttags.py プロジェクト: bheesink/django
 def render(self, context):
     if self not in context.render_context:
         # First time the node is rendered in template
         context.render_context[self] = itertools_cycle(self.cyclevars)
     cycle_iter = context.render_context[self]
     value = next(cycle_iter).resolve(context)
     if self.variable_name:
         context[self.variable_name] = value
     if self.silent:
         return ''
     if not self.escape:
         value = mark_safe(value)
     return _render_value_in_context(value, context)
コード例 #11
0
 def render(self, context, nested=False):
     if self.message_context:
         message_context = self.message_context.resolve(context)
     else:
         message_context = None
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         if message_context:
             result = translation.npgettext(message_context, singular,
                                            plural, count)
         else:
             result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         if message_context:
             result = translation.pgettext(message_context, singular)
         else:
             result = translation.ugettext(singular)
     data = dict([(v, _render_value_in_context(context.get(v, ''), context))
                  for v in vars])
     context.pop()
     try:
         result = result % data
     except (KeyError, ValueError):
         if nested:
             # Either string is malformed, or it's a bug
             raise TemplateSyntaxError(
                 "'blocktrans' is unable to format "
                 "string returned by gettext: %r using %r" % (result, data))
         with translation.override(None):
             result = self.render(context, nested=True)
     return result
コード例 #12
0
ファイル: i18n.py プロジェクト: 32bitfloat/intellij-community
 def render(self, context):
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         result = translation.ugettext(singular)
     # Escape all isolated '%' before substituting in the context.
     result = re.sub(u'%(?!\()', u'%%', result)
     data = dict([(v, _render_value_in_context(context[v], context)) for v in vars])
     context.pop()
     return result % data
コード例 #13
0
ファイル: i18n.py プロジェクト: Myxir20/django
 def render(self, context):
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         result = translation.ugettext(singular)
     # Escape all isolated '%' before substituting in the context.
     result = re.sub(u'%(?!\()', u'%%', result)
     data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
     context.pop()
     return result % data
コード例 #14
0
 def render(self, context):
     if self.message_context:
         message_context = self.message_context.resolve(context)
     else:
         message_context = None
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     # Escape all isolated '%'
     singular = re.sub(u'%(?!\()', u'%%', singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         plural = re.sub(u'%(?!\()', u'%%', plural)
         if message_context:
             result = translation.npgettext(message_context, singular,
                                            plural, count)
         else:
             result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         if message_context:
             result = translation.pgettext(message_context, singular)
         else:
             result = translation.ugettext(singular)
     data = dict([(v, _render_value_in_context(context.get(v, ''), context))
                  for v in vars])
     context.pop()
     try:
         result = result % data
     except KeyError:
         with translation.override(None):
             result = self.render(context)
     return result
コード例 #15
0
ファイル: i18n.py プロジェクト: adamjberg/finna-be-octo-ninja
 def render(self, context, nested=False):
     if self.message_context:
         message_context = self.message_context.resolve(context)
     else:
         message_context = None
     tmp_context = {}
     for var, val in self.extra_context.items():
         tmp_context[var] = val.resolve(context)
     # Update() works like a push(), so corresponding context.pop() is at
     # the end of function
     context.update(tmp_context)
     singular, vars = self.render_token_list(self.singular)
     if self.plural and self.countervar and self.counter:
         count = self.counter.resolve(context)
         context[self.countervar] = count
         plural, plural_vars = self.render_token_list(self.plural)
         if message_context:
             result = translation.npgettext(message_context, singular,
                                            plural, count)
         else:
             result = translation.ungettext(singular, plural, count)
         vars.extend(plural_vars)
     else:
         if message_context:
             result = translation.pgettext(message_context, singular)
         else:
             result = translation.ugettext(singular)
     data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
     context.pop()
     try:
         result = result % data
     except (KeyError, ValueError):
         if nested:
             # Either string is malformed, or it's a bug
             raise TemplateSyntaxError("'blocktrans' is unable to format "
                 "string returned by gettext: %r using %r" % (result, data))
         with translation.override(None):
             result = self.render(context, nested=True)
     return result
コード例 #16
0
    def render(self, context):
        # get the user
        if 'user' in context:
            user = context['user']
        elif 'request' in context:
            user = getattr(context.get('request'), 'user', None)
        else:
            user = None

        # if the user is no translator just render the translated value
        user_is_translator = user and (user.groups.filter(name=app_settings.TRANSLATORS_GROUP).count() > 0)
        if not (user and user_is_translator):
            self.filter_expression.var.translate = not self.noop
            output = self.filter_expression.resolve(context)

            return _render_value_in_context(output, context)

        if getattr(self.filter_expression.var, 'literal'):
            msgid = self.filter_expression.var.literal
        else:
            msgid = self.filter_expression.resolve(context)

        cat = copy.copy(catalog())
        cat.add_fallback(NotTranslated)
        styles = ['translatable']

        try:
            msgstr = cat.ugettext(msgid)

        except ValueError:
            styles.append("untranslated")
            msgstr = msgid

        return render_to_string('inlinetrans/inline_trans.html',{
            'msgid': msgid,
            'styles': ' '.join(styles),
            'value': msgstr
        })
コード例 #17
0
ファイル: i18n.py プロジェクト: 32bitfloat/intellij-community
 def render(self, context):
     self.filter_expression.var.translate = not self.noop
     output = self.filter_expression.resolve(context)
     return _render_value_in_context(output, context)
コード例 #18
0
 def render(self, context):
     self.filter_expression.var.translate = not self.noop
     output = self.filter_expression.resolve(context)
     return _render_value_in_context(output, context)