Skip to content

Commit

Permalink
add track-record value translation tag (#5305)
Browse files Browse the repository at this point in the history
* add track-record value translation tag

* add context to the track record tag labels

* Update bg_selector_tags.py
  • Loading branch information
Pomax committed Sep 28, 2020
1 parent ec3ac8e commit c8e3079
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load yes_no i18n %}
{% load bg_selector_tags i18n %}

<div class="it-uses d-flex flex-column">
<div class="title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load yes_no i18n %}
{% load bg_selector_tags i18n %}

<div class="signup-requirement d-flex flex-column">
<div class="title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "./bg_base.html" %}

{% load yes_no env cloudinary l10n i18n static %}
{% load bg_selector_tags env cloudinary l10n i18n static %}

{% block head_extra %}
<meta property="og:title" content="{% blocktrans context "This can be localized. This is a reference to the “*batteries not included” mention on toys." %}privacy not included - {{ product.name }}{% endblocktrans %}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django import template
from django.utils.translation import gettext, pgettext

register = template.Library()


@register.filter
def yes_no(value):
"""Converts boolean to yes or no string"""
if value is None:
return gettext('Unknown')
# Python doesn't have a ternary, so we rely on
# type coercion to turn False into 0 and True
# into 1, and using that as list index.
return (gettext('No'), gettext('Yes'))[value]


@register.filter
def extended_yes_no(value):
"""Converts quad-state to human readable string"""
if value == 'U':
return gettext('Unknown')
if value == 'NA':
return gettext('N/A')
if value == 'Yes':
return gettext('Yes')
if value == 'No':
return gettext('No')
return value


@register.filter
def track_record(value):
"""
effects localization for company track records. While it might
seem easier to just return gettext(value), we want to be explicit
about the possible options, and the context in which to apply
this tag, rather than a generic "localize" tag.
"""
lcontext = "This is a rating for a company's history concerning privacy"
if value == 'Great':
return pgettext(lcontext, 'Great')
if value == 'Average':
return pgettext(lcontext, 'Average')
if value == 'Needs Improvement':
return pgettext(lcontext, 'Needs Improvement')
if value == 'Bad':
return pgettext(lcontext, 'Bad')
return value
29 changes: 0 additions & 29 deletions network-api/networkapi/buyersguide/templatetags/yes_no.py

This file was deleted.

0 comments on commit c8e3079

Please sign in to comment.