From f66dd5bf7eec289f0e9c517fec715b11f0a180b0 Mon Sep 17 00:00:00 2001
From: Helena Rasche
Date: Mon, 19 Feb 2024 18:15:18 +0100
Subject: [PATCH] support other languages properly
---
_layouts/tutorial_hands_on.html | 15 ++++++++++-----
_plugins/gtn.rb | 26 ++++++++++++++++----------
2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/_layouts/tutorial_hands_on.html b/_layouts/tutorial_hands_on.html
index a24f33bf3c52f7..f3f603070a7c4f 100644
--- a/_layouts/tutorial_hands_on.html
+++ b/_layouts/tutorial_hands_on.html
@@ -167,9 +167,14 @@ Under Development!
{% 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 %}
-
+
{% endif %}
{% icon version %} Revision: {{ page | get_version_number }}
@@ -331,7 +336,7 @@ {{locale['feedback'] | default: "Feedback" }}
{{ locale['feedback-text-learner'] | default: "Did you use this material as a learner or student? Click the form below to leave feedback." }}
-
+
@@ -463,7 +468,7 @@ {{locale['citing-tutorial'] | default: "Citing this Tutorial"}}
- {% assign feedback_histo = site | get_rating_histogram_chart:own_material.id %}
+ {% assign feedback_histo = site | get_rating_histogram_chart:own_material_id %}
{% for hist in feedback_histo %}
@@ -474,7 +479,7 @@ {{locale['citing-tutorial'] | default: "Citing this Tutorial"}}
{% endfor %}
- {% assign feedbacks = site | get_recent_feedbacks:own_material.id %}
+ {% assign feedbacks = site | get_recent_feedbacks:own_material_id %}
{% for feedback in feedbacks %}
{{ feedback[0] }}
diff --git a/_plugins/gtn.rb b/_plugins/gtn.rb
index 5de5fc73b7b85f..02201e34e391ab 100644
--- a/_plugins/gtn.rb
+++ b/_plugins/gtn.rb
@@ -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 }
@@ -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