Python django.utils.translation.pgettext_lazy() Examples
The following are 15
code examples of django.utils.translation.pgettext_lazy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.translation
, or try the search function
.
Example #1
Source File: base.py From bioforum with MIT License | 6 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: is_safe = isinstance(value, SafeData) msgid = value.replace('%', '%%') msgid = mark_safe(msgid) if is_safe else msgid if self.message_context: return pgettext_lazy(self.message_context, msgid) else: return gettext_lazy(msgid) return value
Example #2
Source File: views.py From pasportaservo with GNU Affero General Public License v3.0 | 6 votes |
def dispatch(self, request, *args, **kwargs): code_from_kwarg = {v: k for k, v in self.book_codes.items()} code_from_kwarg.update({None: False}) self.in_book_status = code_from_kwarg[kwargs['in_book']] if self.in_book_status and not request.user.has_perm(PERM_SUPERVISOR): return HttpResponseRedirect(format_lazy( "{supervisors_url}#{section_countries}", supervisors_url=reverse_lazy('supervisors'), section_countries=pgettext_lazy("URL", "countries-list"), )) return super().dispatch(request, *args, **kwargs)
Example #3
Source File: base.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: is_safe = isinstance(value, SafeData) msgid = value.replace('%', '%%') msgid = mark_safe(msgid) if is_safe else msgid if self.message_context: return pgettext_lazy(self.message_context, msgid) else: return gettext_lazy(msgid) return value
Example #4
Source File: base.py From python with Apache License 2.0 | 6 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: is_safe = isinstance(value, SafeData) msgid = value.replace('%', '%%') msgid = mark_safe(msgid) if is_safe else msgid if self.message_context: return pgettext_lazy(self.message_context, msgid) else: return ugettext_lazy(msgid) return value
Example #5
Source File: base.py From openhgsenti with Apache License 2.0 | 6 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: is_safe = isinstance(value, SafeData) msgid = value.replace('%', '%%') msgid = mark_safe(msgid) if is_safe else msgid if self.message_context: return pgettext_lazy(self.message_context, msgid) else: return ugettext_lazy(msgid) return value
Example #6
Source File: base.py From python2017 with MIT License | 6 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: is_safe = isinstance(value, SafeData) msgid = value.replace('%', '%%') msgid = mark_safe(msgid) if is_safe else msgid if self.message_context: return pgettext_lazy(self.message_context, msgid) else: return ugettext_lazy(msgid) return value
Example #7
Source File: views.py From avos with Apache License 2.0 | 6 votes |
def _set_external_network(self, router, ext_net_dict): gateway_info = router.external_gateway_info if gateway_info: ext_net_id = gateway_info['network_id'] if ext_net_id in ext_net_dict: gateway_info['network'] = ext_net_dict[ext_net_id] else: msg_params = {'ext_net_id': ext_net_id, 'router_id': router.id} msg = _('External network "%(ext_net_id)s" expected but not ' 'found for router "%(router_id)s".') % msg_params messages.error(self.request, msg) # gateway_info['network'] is just the network name, so putting # in a smallish error message in the table is reasonable. gateway_info['network'] = pgettext_lazy( 'External network not found', # Translators: The usage is "<UUID of ext_net> (Not Found)" u'%s (Not Found)') % ext_net_id
Example #8
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: if self.message_context: return pgettext_lazy(self.message_context, value) else: return ugettext_lazy(value) return value
Example #9
Source File: admin.py From FIR with GNU General Public License v3.0 | 5 votes |
def business_lines_list(self, obj): bls = obj.business_lines.all() if bls.count(): return ', '.join([bl.name for bl in bls]) return pgettext_lazy('business lines', 'All')
Example #10
Source File: views.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
def get(self, request, *args, **kwargs): try: return HttpResponseRedirect(format_lazy( "{settings_url}#{section_email}", settings_url=reverse_lazy('profile_settings', kwargs={ 'pk': request.user.profile.pk, 'slug': request.user.profile.autoslug}), section_email=pgettext_lazy("URL", "email-addr"), )) except Profile.DoesNotExist: return HttpResponseRedirect(reverse_lazy('email_update'))
Example #11
Source File: base.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def resolve(self, context): """Resolve this variable against a given context.""" if self.lookups is not None: # We're dealing with a variable that needs to be resolved value = self._resolve_lookup(context) else: # We're dealing with a literal, so it's already been "resolved" value = self.literal if self.translate: if self.message_context: return pgettext_lazy(self.message_context, value) else: return ugettext_lazy(value) return value
Example #12
Source File: forms.py From PonyConf with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): site = kwargs.pop('site') super().__init__(*args, **kwargs) activities = Activity.objects.filter(site=site) self.fields['activity'].choices = [('none', pgettext_lazy('activity', 'None'))] + list(activities.values_list('slug', 'name'))
Example #13
Source File: validators.py From django-email-confirm-la with MIT License | 5 votes |
def __call__(self, value): super(AuthUserEmailValidator, self).__call__(value) from django.contrib.auth.models import User if User.objects.filter(email__iexact=value).exists(): raise ValidationError(_('ecla', 'This email has already been taken.'))
Example #14
Source File: validators.py From django-email-confirm-la with MIT License | 5 votes |
def __call__(self, value): super(EmailConfirmationValidator, self).__call__(value) email_exists = EmailConfirmation.objects \ .filter(content_type=self.content_type, email_field_name=self.email_field_name) \ .filter(email__iexact=value) \ .exists() if email_exists: raise ValidationError(_('ecla', 'This email has already been taken.'))
Example #15
Source File: actions.py From avos with Apache License 2.0 | 4 votes |
def _get_action_name(self, items=None, past=False): """Builds combinations like 'Delete Object' and 'Deleted Objects' based on the number of items and `past` flag. :param items: A list or tuple of items (or container with a __len__ method) to count the number of concerned items for which this method is called. When this method is called for a single item (by the BatchAction itself), this parameter can be omitted and the number of items will be considered as "one". If we want to evaluate to "zero" this parameter must not be omitted (and should be an empty container). :param past: Boolean flag indicating if the action took place in the past. By default a present action is considered. """ action_type = "past" if past else "present" if items is None: # Called without items parameter (by a single instance.) count = 1 else: count = len(items) # TODO(ygbo): get rid of self.use_action_method once action_present and # action_past are changed to methods handling plurals. action_attr = getattr(self, "action_%s" % action_type) if self.use_action_method: action_attr = action_attr(count) if isinstance(action_attr, (basestring, Promise)): action = action_attr else: toggle_selection = getattr(self, "current_%s_action" % action_type) action = action_attr[toggle_selection] if self.use_action_method: return action # TODO(ygbo): get rid of all this bellow once action_present and # action_past are changed to methods handling plurals. data_type = ungettext_lazy( self.data_type_singular, self.data_type_plural, count ) if '%(data_type)s' in action: # If full action string is specified, use action as format string. msgstr = action else: if action_type == "past": msgstr = pgettext_lazy("past", "%(action)s %(data_type)s") else: msgstr = pgettext_lazy("present", "%(action)s %(data_type)s") return msgstr % {'action': action, 'data_type': data_type}