Aller au contenu principal
Recette numéro 106

Recettes · Chapitre 2 · Caractères et texte

Un rapport bilingue arabe–anglais

Un rapport annuel en arabe avec l’anglais en regard : {dir=ltr} sur chaque bloc anglais, :ltr[…] pour les noms latins, un tableau de gauche à droite.

Sur cette page

p. ١ · 1 sur 3

  • Exemple en anglais : pas encore d’édition française
  • Format 210 × 280 mm
  • 1 colonne
  • IBM Plex Sans Arabic 11/18
  • IBM Plex Sans
  • 3 pages
  • Niveau
  • Postext 1.63.6
  • Mis en page en 197 ms
  • 143 lignes de code

En bref

Le rapport annuel d’une fondation rédigé en arabe, chaque paragraphe suivi de sa version anglaise. La page mêle les deux sens d’écriture sans que les mots, les nombres ou les tableaux se retrouvent dans le désordre.

Ce que vous allez composer

Le rapport annuel 2025 d’une fondation de traduction imaginaire, Dar al-Dad, sur une page de 210 × 280 mm à la largeur de l’A4, en IBM Plex Sans Arabic et IBM Plex Sans, les deux moitiés d’une même famille de caractères. Le rapport est en arabe : il se lit de droite à gauche et numérote ses pages ٢, ٣. Chaque paragraphe arabe est suivi de sa version anglaise, plus petite et en gris ardoise, composée de gauche à droite et en drapeau à droite ; chaque titre arabe est accompagné d’un intitulé anglais dans la marge opposée. Les noms latins insérés dans des phrases arabes gardent leur propre ordre, et les chiffres de l’année paraissent deux fois, dans un tableau arabe qui se lit depuis la droite et dans un tableau anglais qui se lit depuis la gauche. Dans l’édition espagnole, la seconde langue est l’espagnol.

Cette recette répond à

  • Comment mêler paragraphes, nombres et tableaux en arabe et en anglais sur une même page ?

La réponse courte

script.js · lignes 32–45dans le code complet
// The document is Arabic (locale 'ar'): right to left, Arabic-Indic digits. A block in the
// other language says so in the Markdown, and its style gives it its own voice:
//   :::paragraphs{style="second" dir=ltr}      a paragraph or several, set left to right
//   ### Director's note {style="second-head" dir=ltr}
// Inside an Arabic sentence, a Latin name is an isolate, :ltr[Penguin Classics]{lang=en}, so
// the words around it keep their order. 'start' and 'end' follow each block's own direction.
const second = { id: 'second', fontFamily: LATIN, fontSize: pt(9.5), lineHeight: pt(14),
  color: col('slate'), textAlign: 'start', firstLineIndent: pt(0) };
const bodyText = { fontFamily: ARABIC, fontSize: pt(11), lineHeight: pt(LEAD),
  color: col('ink'), boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  textAlign: 'start', // ragged: the right edge for Arabic, the left for an English block
  firstLineIndent: pt(0), paragraphSpacing: true,
  // The Arabic is never slanted; italics stay for the titles in the Latin blocks.
  emphasis: 'italic' };

Ingrédients

Typographie
IBM Plex Sans Arabic, IBM Plex Sans (SIL OFL 1.1)
Ressources
Aucune : chaque image est dessinée en code

Préparation

#1 · La seconde langue en blocs marqués

Le code est dans la réponse courte plus haut. Le document est en arabe : chaque bloc va donc de droite à gauche tant que le Markdown n’indique pas le contraire. {dir=ltr} sur un délimiteur :::paragraphs ou sur un titre inverse ce bloc, et textAlign: 'start' envoie chaque bloc du côté où il commence, à droite pour l’arabe et à gauche pour l’anglais (Sens du document, des blocs et du texte en ligne). Un nom latin dans une ligne arabe, :ltr[Harbour Modern Classics], est un isolat : l’algorithme bidi le traite comme un seul élément neutre, et les mots arabes et la virgule qui l’entourent gardent leur place (Isolats). emphasis: 'italic' garde Middlemarch en italique dans le texte anglais ; le moteur n’incline jamais une lettre arabe, quel que soit le réglage.

#2 · Un tableau pour chaque sens

script.js · lignes 49–82dans le code complet
const cell = (content, extra = {}) => ({ content, ...extra });
const tableOf = (head, rows) => ({ headerRowCount: 1, columnWidths: [46, 18, 18, 18],
  rows: [head.map((h, i) => cell(h, { isHeader: true, align: i ? 'end' : 'start' })),
    ...rows.map((r) => r.map((c, i) => cell(c, { align: i ? 'end' : 'start' })))] });
const FIGURES = [ // programme, 2024, 2025, change: the Foundation's own counts
  ['كتب مترجمة إلى العربية', 'Books translated into Arabic', 28, 34],
  ['كتب مترجمة من العربية', 'Books translated from Arabic', 9, 14],
  ['منح للمترجمين', 'Translator grants', 41, 52],
  ['ورشات تدريب', 'Training workshops', 12, 18],
  ['مشاركون في الورشات', 'Workshop participants', 310, 466]];
const SPANISH = { 'Books translated into Arabic': 'Libros traducidos al árabe',
  'Books translated from Arabic': 'Libros traducidos del árabe',
  'Translator grants': 'Becas para traductores', 'Training workshops': 'Talleres de formación',
  'Workshop participants': 'Participantes en los talleres' };
const change = (a, b) => `${b > a ? '+' : ''}${Math.round((100 * (b - a)) / a)}%`;
const AR = (n) => String(n).replace(/\d/g, (d) => '٠١٢٣٤٥٦٧٨٩'[d]); // the author's ٠–٩
const tableAr = tableOf(['البرنامج', '٢٠٢٤', '٢٠٢٥', 'التغيّر'], FIGURES.map(([ar, , a, b]) =>
  [ar, AR(a), AR(b), AR(change(a, b)).replaceAll('%', '٪')]));
const tableEn = tableOf(t({ en: ['Programme', '2024', '2025', 'Change'],
  es: ['Programa', '2024', '2025', 'Cambio'] }), FIGURES.map(([, en, a, b]) =>
  [t({ en, es: SPANISH[en] }), String(a), String(b), change(a, b)]));
// The English table has a heading of its own and no number: a generated number would print in
// the document's digits, ٢, inside the English block.
const resourceTypes = [...defaultResourceTypes('ar'), { id: 'data', name: 'Data',
  shortLabel: 'Data', captionPrefix: '', numberingTemplate: '', resetOn: 'never',
  counterFormat: 'decimal' }];
const resources = [
  { id: 'figures-ar', typeId: 'table', kind: 'table', createdAt: 0, updatedAt: 0,
    table: { model: tableAr }, placement: { position: 'here' },
    caption: 'أرقام البرامج في عامي ٢٠٢٤ و٢٠٢٥' },
  { id: 'figures-en', typeId: 'data', kind: 'table', createdAt: 0, updatedAt: 0,
    table: { model: tableEn, direction: 'ltr', styleId: 'second' },
    placement: { position: 'here' } },
];

Le tableau arabe suit le sens du document : sa première colonne, le programme, est à droite, et align: 'end' place les nombres contre le bord gauche de leurs cellules. Le tableau anglais règle direction: 'ltr' : sa première colonne est donc à gauche, et 'end' désigne le bord droit (Ce que signifient gauche, droite, début et fin). Les chiffres arabes sont saisis en ٠–٩, les anglais en 0–9 : les chiffres du document ne s’appliquent qu’aux nombres que le moteur écrit lui-même, comme le numéro du tableau dans sa légende, جدول ١-١. C’est aussi pour cela que le tableau anglais a un type à lui, sans compteur, puisqu’un numéro s’y imprimerait ٢.

#3 · Deux titres sur un bandeau

script.js · lignes 86–102dans le code complet
const band = { enabled: true, minHeight: mm(70), slot: { elements: [
  { kind: 'box', id: 'band', style: { backgroundColor: col('teal') },
    placement: { anchor: { to: 'bleed', edge: 'top-left' },
      size: { width: mm(216), height: mm(86) } } },
  // A heading's design is set in the flow and mirrored with the page: 'left' is the side the
  // text starts on, the sheet's right in this book, and 'right' its left. Design text takes
  // the document's direction; the English title says 'ltr' and starts from the sheet's left.
  { kind: 'text', id: 'org', content: '{attr.org}', fontFamily: ARABIC, fontSize: pt(13),
    fontWeight: 600, color: col('tint'), align: 'start',
    placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(SIDE), y: mm(18) } } },
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: ARABIC, fontSize: pt(50),
    fontWeight: 700, lineHeight: 1.15, color: col('paper'), align: 'start',
    placement: { anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(SIDE), y: mm(30) } } },
  { kind: 'text', id: 'title-2', content: '{attr.second}', direction: 'ltr', fontFamily: LATIN,
    fontSize: pt(18), fontWeight: 300, color: col('tint'), align: 'start',
    placement: { anchor: { to: 'page', edge: 'top-right' }, offset: { x: mm(-SIDE), y: mm(66) } } },
] } };

La couverture est la maquette du titre de niveau 1. La maquette d’un titre se place dans le flux et se reflète avec la page : ses ancrages désignent donc les côtés du texte. top-left est la droite de la feuille, où commencent le nom et le titre arabes, et top-right sa gauche, où commence le titre anglais. Le texte de maquette prend le sens du document : les lignes arabes n’ont besoin de rien d’autre, et le titre anglais règle direction: 'ltr'. Le bandeau est un bloc ancré au fond perdu, haut de 86 mm, et le minHeight de l’ouverture amène le mot du directeur dessous.

La recette complète

Sandbox
// ═══ Postext Cookbook · Nº 106 · A bilingual Arabic–English report ═══════════════════
// https://postext.dev/en/cookbook/bilingual-arabic-english-report
// Code: MIT · Text: original Arabic, English and Spanish prose (CC BY 4.0) · Pictures: none
// Fonts: IBM Plex Sans Arabic, IBM Plex Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, defaultResourceTypes,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the second language of the report: English, or Spanish in 'es'
const RECIPE = 'bilingual-arabic-english-report';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a deep teal for the Arabic, a slate for the second language
const palette = {
  ink: '#1b1f22', // the Arabic text
  teal: '#0e5a5c', // the accent: the cover band, headings, table heads
  slate: '#45535c', // the English (or Spanish) text: a voice of its own, a step lighter
  tint: '#e4eeec', // the second language's panels
  rule: '#b9c4c2', // hairlines
  paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.teal })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [ARABIC, LATIN] = ['IBM Plex Sans Arabic', 'IBM Plex Sans']; // one superfamily
const LEAD = 18; // pt: the Arabic leading
const SIDE = 20; // mm: the side margins

// #region answer: one Arabic document, its English blocks marked {dir=ltr}
// The document is Arabic (locale 'ar'): right to left, Arabic-Indic digits. A block in the
// other language says so in the Markdown, and its style gives it its own voice:
//   :::paragraphs{style="second" dir=ltr}      a paragraph or several, set left to right
//   ### Director's note {style="second-head" dir=ltr}
// Inside an Arabic sentence, a Latin name is an isolate, :ltr[Penguin Classics]{lang=en}, so
// the words around it keep their order. 'start' and 'end' follow each block's own direction.
const second = { id: 'second', fontFamily: LATIN, fontSize: pt(9.5), lineHeight: pt(14),
  color: col('slate'), textAlign: 'start', firstLineIndent: pt(0) };
const bodyText = { fontFamily: ARABIC, fontSize: pt(11), lineHeight: pt(LEAD),
  color: col('ink'), boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  textAlign: 'start', // ragged: the right edge for Arabic, the left for an English block
  firstLineIndent: pt(0), paragraphSpacing: true,
  // The Arabic is never slanted; italics stay for the titles in the Latin blocks.
  emphasis: 'italic' };
// #endregion

// #region tables: the Arabic table runs with the page; the English one runs left to right

Le script.js composé s’exécute tel quel : collez-le dans le script de module de n’importe quelle page, ou ouvrez la recette sur CodePen. Dossier de la recette sur GitHub ↗ (s’ouvre dans un nouvel onglet)

Variantes

#Mettre l’anglais en premier

Un rapport destiné à un conseil qui ne lit pas l’arabe inverse les rôles : un document anglais, aux blocs non marqués, et les blocs arabes marqués {dir=rtl}.

-  locale: 'ar', // written out, never LANG (gotcha: arabic-locale-tag)
+  locale: 'en-us', // Arabic blocks then carry {dir=rtl}

Erreurs fréquentes

Erreur fréquente

Balisez un livre arabe 'ar', pas avec LANG

Les éditions d’une recette sont en et es, mais un exemple arabe est en arabe dans les deux : `locale: LANG` le composerait de gauche à droite, le relierait à gauche, numéroterait ses pages 1 2 3 et légenderait ses figures Figure ou Figura. Depuis postext 1.30, la balise est aussi la langue dans laquelle le texte est mis en forme (mesuré, peint et incorporé) : sous une balise anglaise ou espagnole, une police comme Markazi Text ne dessine pas les formes arabes de ses guillemets et de ses points, et les lignes se coupent ailleurs. Écrivez la balise vous-même : 'ar' (chiffres arabes orientaux, convention du Machrek), une région comme 'ar-EG' ou 'ar-SA', ou 'ar-MA', 'ar-DZ' ou 'ar-TN' pour une édition maghrébine avec chiffres européens. Une page latine qui ne fait que citer de l’arabe garde sa propre langue. Texte de droite à gauche →

Erreur fréquente

Les polices arabes ont besoin de leur fichier arabic, avec le bloc arabic

Fontsource sert Amiri, Noto Naskh Arabic ou Scheherazade New sous la forme d’un fichier par sous-ensemble, et les lettres arabes se trouvent dans le fichier arabic. loadFonts ne récupère que latin (et latin-ext) : à l’écran, l’arabe vient d’une police système et est mal mesuré, et fontsourceProvider remet ce fichier latin au PDF, qui imprime des cases vides. Listez le bloc arabic du kit, appelez loadArabicFonts(FONTS, markdown) après loadFonts, avec dans FONTS chaque graisse que les pages composent en arabe, et donnez à renderToPdf fontProvider: arabicPdfProvider. Polices arabes →

  • Un nombre que le moteur écrit dans un bloc anglais, numéro de liste ou étiquette de légende, prend quand même les chiffres du document (٢ dans un rapport arabe). Donnez à ces tableaux un type de ressource sans compteur, ou écrivez les numéros vous-même.

Crédits

Texte
  • The annual report of an invented translation foundation, written in Arabic, English and Spanish for the recipe · Postext Cookbook · original
Polices
IBM Plex Sans Arabic (SIL OFL 1.1) · IBM Plex Sans (SIL OFL 1.1)
SandboxPDF