fix(translate): apply Excel chart text setters (were silently dropped)
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m35s

Chart <a:t> elements (title, axis labels, series names) were collected and
sent to the LLM, but the apply loop never invoked their setters. Reason:
the apply loop iterated only text_elements[:sheet_name_offset], which
excluded the chart-text positions (sheet names were inserted in the
middle, pushing chart texts past sheet_name_offset). The LLM correctly
returned French for "Revenue by Product" / "Quantity Trend" / "Order #"
but the result was thrown away.

Fix: include the chart-text slice [sheet_name_offset + N .. total_texts]
in the apply loop. Setters for sheet names are still None, so they are
naturally skipped.

Add test_excel_chart_text_applied.py (2 end-to-end tests) using a fixed
provider that pre-translates every known chart text; the test asserts
all chart <a:t> values in the output .xlsx come from the FR table, not
the original English source.
This commit is contained in:
2026-07-15 22:21:53 +02:00
parent 07c4c12e6a
commit 992f13d53c
2 changed files with 123 additions and 3 deletions

View File

@@ -264,11 +264,20 @@ class ExcelTranslator:
}
)
# Apply cell translations
# Apply cell + chart translations. The structure of
# text_elements is:
# [0 .. sheet_name_offset) -> cell/header/footer setters
# [sheet_name_offset .. +N) -> sheet names (setter=None)
# [sheet_name_offset + N .. total_texts) -> chart setters
# The old code only iterated the first slice, silently skipping
# every chart setter. We now concatenate the two non-None slices.
_n_sheet_names = len(sheet_names_to_translate)
_chart_slice = text_elements[sheet_name_offset + _n_sheet_names:]
_chart_trans_slice = translated_texts[sheet_name_offset + _n_sheet_names:]
for i, ((original_text, setter), translated) in enumerate(
zip(
text_elements[:sheet_name_offset],
translated_texts[:sheet_name_offset],
text_elements[:sheet_name_offset] + _chart_slice,
translated_texts[:sheet_name_offset] + _chart_trans_slice,
)
):
if translated is not None and setter is not None: