Resolve this variable against a given context.
(self, context)
| 938 | self.lookups = tuple(var.split(VARIABLE_ATTRIBUTE_SEPARATOR)) |
| 939 | |
| 940 | def resolve(self, context): |
| 941 | """Resolve this variable against a given context.""" |
| 942 | if self.lookups is not None: |
| 943 | # We're dealing with a variable that needs to be resolved |
| 944 | value = self._resolve_lookup(context) |
| 945 | else: |
| 946 | # We're dealing with a literal, so it's already been "resolved" |
| 947 | value = self.literal |
| 948 | if self.translate: |
| 949 | is_safe = isinstance(value, SafeData) |
| 950 | msgid = value.replace("%", "%%") |
| 951 | msgid = mark_safe(msgid) if is_safe else msgid |
| 952 | if self.message_context: |
| 953 | return pgettext_lazy(self.message_context, msgid) |
| 954 | else: |
| 955 | return gettext_lazy(msgid) |
| 956 | return value |
| 957 | |
| 958 | def __repr__(self): |
| 959 | return "<%s: %r>" % (self.__class__.__name__, self.var) |