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 translation warnings in area_end paragraphs #3691

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions timApp/document/editing/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']."
)
saviit marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down
5 changes: 5 additions & 0 deletions timApp/plugin/pluginControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
saviit marked this conversation as resolved.
Show resolved Hide resolved
if p.is_translation_out_of_date():
p.add_class("troutofdate")
else:
Expand Down
Loading