Skip to content

Commit

Permalink
support other languages properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Feb 19, 2024
1 parent a890f22 commit f66dd5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
15 changes: 10 additions & 5 deletions _layouts/tutorial_hands_on.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,14 @@ <h4 class="alert-heading">Under Development!</h4>
<div><strong>{% icon purl %} <abbr title="Persistent URL">PURL</abbr>:</strong> <a href="https://gxy.io/GTN:{{ page.short_id }}">https://gxy.io/GTN:{{ page.short_id }}</a> </div>
{% endif %}

{% assign feedback_count = site | get_feedback_count: own_material.id %}
{% assign own_material_id = own_material.id %}
{% if page.lang %}
{% capture own_material_id %}{{ own_material.id }}:{{ page.lang }}{% endcapture %}
{% endif %}

{% assign feedback_count = site | get_feedback_count: own_material_id %}
{% if feedback_count > 0 %}
<div><strong>{% icon rating %} Rating:</strong> <a href="#feedback-responses">{{ site | get_rating:own_material.id }}</a> ({{ site | get_feedback_count: own_material.id }} ratings)</div>
<div><strong>{% icon rating %} Rating:</strong> <a href="#feedback-responses">{{ site | get_rating:own_material_id }}</a> ({{ site | get_feedback_count: own_material_id }} ratings)</div>
{% endif %}
<div><strong>{% icon version %} Revision:</strong> {{ page | get_version_number }} </div>

Expand Down Expand Up @@ -331,7 +336,7 @@ <h1>{{locale['feedback'] | default: "Feedback" }}</h1>
<br>{{ locale['feedback-text-learner'] | default: "Did you use this material as a learner or student? Click the form below to leave feedback." }}<i class="fas fa-hand-point-down"></i>
</p>

<a href="https://docs.google.com/forms/d/e/1FAIpQLSd4VZptFTQ03kHkMz0JyW9b6_S8geU5KjNE_tLM0dixT3ZQmA/viewform?embedded=true&entry.1235803833={{ own_material.id }}{% if page.lang %}:{{ page.lang }}{% endif %}" alt="Feedback form link">
<a href="https://docs.google.com/forms/d/e/1FAIpQLSd4VZptFTQ03kHkMz0JyW9b6_S8geU5KjNE_tLM0dixT3ZQmA/viewform?embedded=true&entry.1235803833={{ own_material_id }}" alt="Feedback form link">
<img src="/training-material/shared/images/feedback.png" alt="Preview of the google form" />
</a>

Expand Down Expand Up @@ -463,7 +468,7 @@ <h1>{{locale['citing-tutorial'] | default: "Citing this Tutorial"}}</h1>
</div>

<p>
{% assign feedback_histo = site | get_rating_histogram_chart:own_material.id %}
{% assign feedback_histo = site | get_rating_histogram_chart:own_material_id %}

<table class="charts-css bar show-labels" style="--labels-size: 8rem; overflow-y: hidden">
{% for hist in feedback_histo %}
Expand All @@ -474,7 +479,7 @@ <h1>{{locale['citing-tutorial'] | default: "Citing this Tutorial"}}</h1>
{% endfor %}
</table>
</p>
{% assign feedbacks = site | get_recent_feedbacks:own_material.id %}
{% assign feedbacks = site | get_recent_feedbacks:own_material_id %}
{% for feedback in feedbacks %}
<b>{{ feedback[0] }}</b>
<ul>
Expand Down
26 changes: 16 additions & 10 deletions _plugins/gtn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,9 @@ def get_version_number(page)
def get_rating_histogram(site, material_id)
return {} if material_id.nil?

begin
topic, tutorial = material_id.split('/')
feedbacks = site.data['feedback2'][topic][tutorial]
rescue StandardError
return {}
end
feedbacks = get_feedbacks(site, material_id)

return {} if feedbacks.nil?
return {} if feedbacks.nil? || feedbacks.empty?

ratings = feedbacks.map { |f| f['rating'] }
f = ratings.each_with_object(Hash.new(0)) { |w,counts| counts[w] += 1 }
Expand Down Expand Up @@ -431,9 +426,20 @@ def get_feedbacks(site, material_id)

begin
topic, tutorial = material_id.split('/')
feedbacks = site.data['feedback2'][topic][tutorial]
rescue StandardError
Jekyll.logger.warn "[GTN/Feedback] No feedback found for #{topic}/#{tutorial}"

if tutorial.include?(':')
language = tutorial.split(':')[1]
tutorial = tutorial.split(':')[0]
# If a language is supplied, then
feedbacks = site.data['feedback2'][topic][tutorial]
.select{|f| (f['lang'] || "").downcase == language.downcase}
else
# English is the default
feedbacks = site.data['feedback2'][topic][tutorial]
.select{|f| f['lang'].nil? }
end

rescue StandardError => e
return []
end

Expand Down

0 comments on commit f66dd5b

Please sign in to comment.