fix(direction): le sens du document traduit suit la langue cible, dans les deux sens
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 3m3s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 3m3s
Persan -> francais : le document traduit restait en lecture de droite a gauche, heritee de la source. Trois causes : - PDF : regression du renommage precedent — le choix d'alignement testait la fonction is_rtl (toujours vraie) au lieu du parametre : tout texte traduit s'alignait a droite, quelle que soit la cible. Corrige + test epinglant l'alignement gauche pour une cible latine. - Word : les marques RTL heritees (bidi, rtl, bidiVisual, notes et commentaires compris) sont desormais retirees quand la cible est latine ; retrait fait sur une liste figee (l'iterateur lxml sautait des elements pendant la suppression). - Excel : les feuilles heritees d'un affichage droite-a-gauche sont remises en lecture gauche-a-droite pour une cible latine. - PowerPoint : les attributs rtl herites sont retires pour une cible latine (alignements visuels conserves). 3 tests de bout en bout nouveaux : document RTL traduit vers le francais ressort en lecture gauche-a-droite dans les trois formats.
This commit is contained in:
@@ -355,25 +355,35 @@ class ExcelTranslator:
|
||||
except Exception as e:
|
||||
_log_error("excel_sheet_images_failed", sheet_name=sheet_name, error=str(e))
|
||||
|
||||
# RTL targets: flip the sheet view so every sheet reads
|
||||
# right-to-left (column A renders rightmost). Content and
|
||||
# formatting are untouched — only the reading direction.
|
||||
# Normalize the sheet reading direction to the TARGET language.
|
||||
# RTL targets: flip every sheet so column A renders rightmost.
|
||||
# Latin targets: restore left-to-right on sheets inherited from
|
||||
# an RTL source (Persian → French must not keep the RTL view).
|
||||
# Content and formatting are untouched — only the direction.
|
||||
# Chartsheets have no `sheet_view` and must never break the
|
||||
# save: each sheet is guarded individually.
|
||||
if is_rtl(target_language):
|
||||
flipped = 0
|
||||
for sheet_name in workbook.sheetnames:
|
||||
ws = workbook[sheet_name]
|
||||
try:
|
||||
if getattr(ws, "sheet_view", None) is not None:
|
||||
ws.sheet_view.rightToLeft = True
|
||||
flipped += 1
|
||||
except Exception as e:
|
||||
_log_error(
|
||||
"excel_rtl_view_failed", sheet=sheet_name, error=str(e)
|
||||
)
|
||||
if flipped:
|
||||
_log_info("excel_rtl_view_applied", sheets=flipped)
|
||||
rtl_target = is_rtl(target_language)
|
||||
flipped = 0
|
||||
for sheet_name in workbook.sheetnames:
|
||||
ws = workbook[sheet_name]
|
||||
try:
|
||||
if getattr(ws, "sheet_view", None) is None:
|
||||
continue
|
||||
if rtl_target:
|
||||
ws.sheet_view.rightToLeft = True
|
||||
flipped += 1
|
||||
elif getattr(ws.sheet_view, "rightToLeft", False):
|
||||
ws.sheet_view.rightToLeft = False
|
||||
flipped += 1
|
||||
except Exception as e:
|
||||
_log_error(
|
||||
"excel_direction_view_failed", sheet=sheet_name, error=str(e)
|
||||
)
|
||||
if flipped:
|
||||
_log_info(
|
||||
"excel_rtl_view_applied" if rtl_target else "excel_ltr_view_restored",
|
||||
sheets=flipped,
|
||||
)
|
||||
|
||||
try:
|
||||
workbook.save(output_path)
|
||||
|
||||
Reference in New Issue
Block a user