From bf116871cd2392adbe7269c7b8e08e4e071d1d12 Mon Sep 17 00:00:00 2001 From: Sami Viitanen Date: Wed, 14 Aug 2024 18:17:59 +0300 Subject: [PATCH] Fix showing non-removable translation warnings in invisible area_end paragraphs --- timApp/document/editing/routes.py | 31 +++++++++++++++++++++++++++++++ timApp/plugin/pluginControl.py | 5 +++++ 2 files changed, 36 insertions(+) diff --git a/timApp/document/editing/routes.py b/timApp/document/editing/routes.py index ab55e05aab..1990e1f674 100644 --- a/timApp/document/editing/routes.py +++ b/timApp/document/editing/routes.py @@ -328,6 +328,37 @@ def modify_paragraph_common(doc_id: int, md: str, par_id: str, par_next_id: str elif tr_opt: if p.is_translation(): deref = mark_as_translated(p) + + # Since empty area_end paragraphs are not visible, we need to set their rt-attribute + # at the same time as the area start paragraph. Otherwise, the 'Translation out of date' and + # 'Check translation' markings will remain on the area_end pars with no obvious way to remove them. + # For new area sections, the classes 'troutofdate' and 'checktr' will not be set at all for the area_end + # paragraphs if it is empty. + if p.is_area(): + area_name = ( + p.get_attr("area") + if p.get_attr("area") + else p.get_attr("area_end") + ) + if not area_name: + raise RouteException( + "Could not access paragraph attributes ['area', 'area_end']." + ) + area_end_par = doc.get_named_section(area_name)[-1] + aep_md = area_end_par.get_markdown() + aep_cache = ( + area_end_par.html_cache.get(area_end_par.attrs.get("rt")) + if area_end_par.html_cache + else None + ) + + if not aep_md and not aep_cache: + res = mark_as_translated(area_end_par) + if not res: + raise RouteException("Paragraph is not a translation.") + # Also mark the area end par as checked since it does not have any content + mark_translation_as_checked(area_end_par) + if not deref: raise RouteException("Paragraph is not a translation.") else: diff --git a/timApp/plugin/pluginControl.py b/timApp/plugin/pluginControl.py index 351657cb2e..caf87bdf6d 100644 --- a/timApp/plugin/pluginControl.py +++ b/timApp/plugin/pluginControl.py @@ -458,6 +458,11 @@ def pluginify( taketime("answ", "start") if not view_ctx.preview and has_edit_access(doc.get_docinfo()): for p in pars: + # Do not add the 'Translation out of date' and 'Check translation' markings to + # area_end pars if they are empty. + p_html_cache = p.html_cache.get(p.attrs.get("rt")) if p.html_cache else None + if p.get_attr("area_end") and not p.get_markdown() and not p_html_cache: + continue if p.is_translation_out_of_date(): p.add_class("troutofdate") else: