Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add trans filter to html templates #41

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from xblock.core import XBlock
from xblock.fields import Scope, Integer, String, List, Float, Boolean
from web_fragments.fragment import Fragment
from feedback.utils import _
try:
from xblock.utils.resources import ResourceLoader
except ModuleNotFoundError: # For backward compatibility with releases older than Quince.
Expand All @@ -24,30 +25,27 @@
# We provide default text which is designed to elicit student thought. We'd
# like instructors to customize this to something highly structured (not
# "What did you think?" and "How did you like it?".
DEFAULT_FREEFORM = "What did you learn from this? What was missing?"
DEFAULT_LIKERT = "How would you rate this as a learning experience?"
DEFAULT_DEFAULT = "Think about the material, and try to synthesize key " \
"lessons learned, as well as key gaps in our presentation."
DEFAULT_PLACEHOLDER = "Take a little bit of time to reflect here. " \
"Research shows that a meaningful synthesis will help " \
"you better understand and remember material from " \
"this course."
DEFAULT_FREEFORM = _("What did you learn from this? What was missing?")
DEFAULT_LIKERT = _("How would you rate this as a learning experience?")
DEFAULT_DEFAULT = _(
"Think about the material, and try to synthesize key "
"lessons learned, as well as key gaps in our presentation."
)
DEFAULT_PLACEHOLDER = _(
"Take a little bit of time to reflect here. "
"Research shows that a meaningful synthesis will help "
"you better understand and remember material from "
"this course."
)
DEFAULT_ICON = "face"
DEFAULT_SCALETEXT = ["Excellent", "Good", "Average", "Fair", "Poor"]
DEFAULT_SCALETEXT = [_("Excellent"), _("Good"), _("Average"), _("Fair"), _("Poor")]

# Unicode alt faces are cute, but we do nulls instead for a11y.
ICON_SETS = {'face': [""]*5, # u"😁😊😐😞😭",
'num': "12345",
'midface': [""]*5} # u"😞😐😊😐😞"}


def _(text):
"""
Make '_' a no-op, so we can scrape strings
"""
return text


@XBlock.needs('i18n')
class FeedbackXBlock(XBlock):
"""
Expand All @@ -62,12 +60,14 @@ class FeedbackXBlock(XBlock):
# will default to the ones in default_prompt.
prompts = List(
default=[
{'freeform': DEFAULT_FREEFORM,
'default_text': DEFAULT_DEFAULT,
'likert': DEFAULT_LIKERT,
'placeholder': DEFAULT_PLACEHOLDER,
'scale_text': DEFAULT_SCALETEXT,
'icon_set': DEFAULT_ICON}
{
"freeform": DEFAULT_FREEFORM,
"default_text": DEFAULT_DEFAULT,
"likert": DEFAULT_LIKERT,
"placeholder": DEFAULT_PLACEHOLDER,
"scale_text": DEFAULT_SCALETEXT,
"icon_set": DEFAULT_ICON,
}
],
scope=Scope.settings,
help=_("Freeform user prompt"),
Expand Down Expand Up @@ -163,7 +163,7 @@ def get_prompt(self, index=-1):
_("Fair"),
_("Poor")],
'icon_set': 'num',
'placeholder': "Please take a moment to thoughtfully reflect."
'placeholder': _("Please take a moment to thoughtfully reflect.")
}

prompt.update(self.prompts[index])
Expand Down
6 changes: 3 additions & 3 deletions feedback/templates/html/feedback.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<div class="feedback_block">
<form action="" onsubmit="return false;">
<fieldset class="feedback_likert_field">
<legend class="feedback_likert_header">{{likert_prompt}}</legend>
<legend class="feedback_likert_header">{% trans likert_prompt %}</legend>
<div class="feedback_likert_scale">{{scale|safe}}</div>
</fieldset>

<div class="feedback_header_div">
<label class="feedback_header" for="feedback_freeform_textarea">{{freeform_prompt}}</label>
<label class="feedback_header" for="feedback_freeform_textarea">{% trans freeform_prompt %}</label>
</div>
<div class="feedback_freeform_input">
<textarea name="feedback_freeform_textarea" class="feedback_freeform_area" rows="6" cols="45" placeholder="{{placeholder}}">{{self.user_freeform}}</textarea>
<textarea name="feedback_freeform_textarea" class="feedback_freeform_area" rows="6" cols="45" placeholder="{% trans placeholder %}">{% trans self.user_freeform %}</textarea>
<div class="feedback_thank_you" aria-live=polite>{{response}}</div>
</div>
<button type="submit" class="feedback_submit_feedback">{% trans "Submit Feedback" %}</button>
Expand Down
4 changes: 3 additions & 1 deletion feedback/templates/html/scale_item.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% load i18n %}

<div class="feedback_likert_rating">
<label title="{{scale_text}}" class="feedback_likert_label">
<input data-id="radio_{{idx}}" name="feedback_scale" class="feedback_radio" type="radio" {{active}}/>
Expand All @@ -8,6 +10,6 @@
<img src="{{act_icon}}" alt="{{unicode_icon}}"/>
</span>
<br/>
<span>{{scale_text}}</span>
<span>{% trans scale_text %}</span>
</label>
</div>
4 changes: 3 additions & 1 deletion feedback/templates/html/staff_item.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% load i18n %}

<div class="feedback_likert_rating">
<label title="{{scale_text}}" class="feedback_likert_label">
<input data-id="radio_{{idx}}" name="feedback_scale" class="feedback_radio" type="radio" {{active}}/>
Expand All @@ -8,7 +10,7 @@
<img src="{{act_icon}}" alt="{{unicode_icon}}"/>
</span>
<br/>
<span>{{scale_text}}</span>
<span>{% trans scale_text %}</span>
<br/>
({{vote_cnt}})
</label>
Expand Down
14 changes: 7 additions & 7 deletions feedback/templates/html/studio_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="placeholder" aria-describedby="placeholder_span">{% trans "Freeform placeholder"%}</label>
<input class="input setting-input" name="placeholder" id="placeholder" value="{{placeholder}}" type="text" />
<input class="input setting-input" name="placeholder" id="placeholder" value="{% trans placeholder %}" type="text" />
</div>
<span id="placeholder_span" class="tip setting-help">{% trans "This is shown as grayed out text before the student has answered." %}</span>
</li>
Expand All @@ -70,47 +70,47 @@
<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="likert" aria-describedby="lik_example">{% trans "Likert prompt" %}</label>
<input class="input setting-input" name="likert" id="likert" value="{{likert}}" type="text" />
<input class="input setting-input" name="likert" id="likert" value="{% trans likert %}" type="text" />
</div>
<span id="lik_example" class="tip setting-help">{% trans "Example: Please rate your overall experience with this section." %}</span>
</li>

<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="likert0" aria-describedby="lik_excel">{% trans "Likert option 1" %}</label>
<input class="input setting-input" name="likert0" id="likert0" value="{{likert0}}" type="text" />
<input class="input setting-input" name="likert0" id="likert0" value="{% trans likert0 %}" type="text" />
</div>
<span id="lik_excel" class="tip setting-help">{% trans "Example: Excellent!" %}</span>
</li>

<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="likert1" aria-describedby="lik_good">{% trans "Likert option 2" %}</label>
<input class="input setting-input" name="likert1" id="likert1" value="{{likert1}}" type="text" />
<input class="input setting-input" name="likert1" id="likert1" value="{% trans likert1 %}" type="text" />
</div>
<span id="lik_good" class="tip setting-help">{% trans "Example: Good" %}</span>
</li>

<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="likert2" aria-describedby="lik_ave">{% trans "Likert option 3" %}</label>
<input class="input setting-input" name="likert2" id="likert2" value="{{likert2}}" type="text" />
<input class="input setting-input" name="likert2" id="likert2" value="{% trans likert2 %}" type="text" />
</div>
<span id="lik_ave" class="tip setting-help">{% trans "Example: Average" %}</span>
</li>

<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="likert3" aria-describedby="lik_fair">{% trans "Likert option 4" %}</label>
<input class="input setting-input" name="likert3" id="likert3" value="{{likert3}}" type="text" />
<input class="input setting-input" name="likert3" id="likert3" value="{% trans likert3 %}" type="text" />
</div>
<span id="lik_fair" class="tip setting-help">{% trans "Example: Fair" %}</span>
</li>

<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="likert4" aria-describedby="lik_poor">{% trans "Likert option 5" %}</label>
<input class="input setting-input" name="likert4" id="likert4" value="{{likert4}}" type="text" />
<input class="input setting-input" name="likert4" id="likert4" value="{% trans likert4 %}" type="text" />
</div>
<span id="lik_poor" class="tip setting-help">{% trans "Example: Poor" %}</span>
</li>
Expand Down
6 changes: 6 additions & 0 deletions feedback/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Utilities for feedback app"""


def _(text):
"""Dummy `gettext` replacement to make string extraction tools scrape strings marked for translation"""
return text