From 14294369e2ee7e4914757054693fe77b450f7405 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Thu, 30 Mar 2023 14:21:51 -0400 Subject: Display content language in status info --- src/archive_parser.cpp | 21 +++++++++++++++++++++ src/templates/status_info.html | 1 + 2 files changed, 22 insertions(+) diff --git a/src/archive_parser.cpp b/src/archive_parser.cpp index d677f84..d16cd49 100644 --- a/src/archive_parser.cpp +++ b/src/archive_parser.cpp @@ -209,6 +209,25 @@ QString get_html_status_object_as_list(QJsonObject obj, QString element_name) { return text; } +QString get_html_status_object_languages(QJsonObject obj, QString element_name = "contentMap") { + QString text; + + if (obj.contains(element_name) and obj.value(element_name).isObject()) { + QJsonObject content_map = obj.value(element_name).toObject(); + QStringList languages = content_map.keys(); + + for (auto lang : languages) + text.append(lang + ", "); + } + + if (text.isEmpty()) + text = "(unknown)"; + else + text.chop(2); // remove leftover ", " + + return text; +} + QString Archive::get_html_status_attachments(QJsonValueRef attachments_ref, int text_zone_width) { QString text; QJsonArray attachments = attachments_ref.toArray(); @@ -278,6 +297,7 @@ QString Archive::get_html_status_info(int status_index, int text_zone_width, Sta if (activity["content"].isString()) { info_text.replace("{{content}}", activity["content"].toString()); + info_text.replace("{{lang}}", get_html_status_object_languages(activity)); } } else if (obj["object"].isString()) { QString text = obj["object"].toString(); @@ -292,6 +312,7 @@ QString Archive::get_html_status_info(int status_index, int text_zone_width, Sta info_text.replace("{{content}}", content_text); info_text.replace("{{summary}}", "(empty)"); + info_text.replace("{{lang}}", "(not applicable)"); info_text.replace("{{attachment-div}}", ""); } diff --git a/src/templates/status_info.html b/src/templates/status_info.html index a51c066..9ff5ec5 100644 --- a/src/templates/status_info.html +++ b/src/templates/status_info.html @@ -10,6 +10,7 @@