本文へスキップ
レシピ番号106

レシピ集 · 第2章 · 文字と本文

アラビア語と英語の対訳報告書

英語を併記したアラビア語の年次報告書。英語のブロックに{dir=ltr}、アラビア語の行内のラテン文字名に:ltr[…]、表は左から右へ組みます。

このページの内容
ジャンル
報告書
出力
Canvas · PDF
レベル
中級
Postext
Postext 1.65.0で検証済み
1.25.0以上が必要 · postext-pdf ≥ 1.25.0
ライセンス
2026年10月10日更新
コードMIT · 本文CC BY 4.0
  • 英語の見本:日本語版はまだありません
  • 仕上がり210 × 280 mm
  • 1段
  • IBM Plex Sans Arabic 11/18
  • IBM Plex Sans
  • 3ページ
  • レベル
  • Postext 1.63.6
  • 組版時間197 ms
  • コード143行

かんたんな説明

ある財団の年次報告書をアラビア語で書き、各段落のあとに英語版を添えます。ひとつのページに2つの書字方向が混ざっても、語も数字も表も順序が崩れません。

できあがり

架空の翻訳財団Dar al-Dadの2025年度年次報告書です。ページは幅をA4にそろえた210 × 280 mm、書体はひとつの書体ファミリーの両半分にあたるIBM Plex Sans ArabicとIBM Plex Sansです。報告書の本体はアラビア語で、右から左へ進み、ノンブルも٢、٣と振ります。アラビア語の各段落のあとには、ひと回り小さいスレートグレーの英語版が続き、左から右へ、行末不ぞろいで組まれます。アラビア語の見出しには、反対側の端に英語のラベルが付きます。アラビア語の文中のラテン文字の名前は自分の語順を保ち、年度の数字は2回、右から読むアラビア語の表と左から読む英語の表に出てきます。スペイン語版では、2つ目の言語がスペイン語になります。

このレシピが答える質問

  • 1つのページに、アラビア語と英語の段落、数字、表を混在させるには?

手短な答え

script.js · 32〜45行コード全体で見る
// 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' };

材料

種類
IBM Plex Sans Arabic, IBM Plex Sans (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · 2つ目の言語は印を付けたブロックで

コードは上の手短な答えにあります。文書はアラビア語なので、Markdownで指定しないかぎり、どのブロックも右から左です。:::paragraphsの開始行や見出しに{dir=ltr}を付けると、そのブロックの向きが反転します。textAlign: 'start'は各ブロックを書き始める側へ寄せ、アラビア語なら右、英語なら左にそろえます(文書、ブロック、インラインの方向)。アラビア語の行内にあるラテン文字の名前、:ltr[Harbour Modern Classics]はアイソレートです。bidiアルゴリズムはこれをひとかたまりの中立的な要素として扱うので、まわりのアラビア語の語やカンマは位置を変えません(アイソレート)。emphasis: 'italic'で、英語の文中の『Middlemarch』はイタリックのまま残ります。設定がどうであれ、エンジンがアラビア文字をイタリックにすることはありません。

#2 · 方向ごとに表をひとつずつ

script.js · 49〜82行コード全体で見る
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' } },
];

アラビア語の表は文書の方向に従います。最初の列(事業名)が右にあり、align: 'end'で数字はセルの左端に寄ります。英語の表はdirection: 'ltr'を指定しているので、最初の列が左に来て、'end'はセルの右端を指します(左・右・始端・終端の意味)。アラビア語の表の数字は٠–٩で、英語の表の数字は0–9で入力します。文書の数字の設定が効くのは、キャプション中の表番号جدول ١-١のように、エンジンが自分で書く数字だけです。英語の表に番号を振らない専用の種類を与えているのも同じ理由で、番号を振ると٢と印字されてしまいます。

#3 · 1本の帯に2つの表題

script.js · 86〜102行コード全体で見る
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) } } },
] } };

表紙は第1レベルの見出しのデザインです。見出しのデザインは本文の流れの中で組まれ、ページとともに鏡像になるので、アンカーは文字の側を指します。top-leftは紙面の右で、アラビア語の名称と表題がそこから始まり、top-rightは紙面の左で、英語の表題がそこから始まります。デザイン要素の文字は文書の方向をとるので、アラビア語の行にはそれ以上何も指定しません。英語の表題はdirection: 'ltr'を指定します。帯は塗り足しに固定した深さ86 mmのボックスで、章扉のminHeightによって理事長のあいさつがその下に来ます。

レシピの全体

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

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#英語を先にする

アラビア語を読まない理事会向けの報告書なら、役割を入れ替えます。文書を英語にしてそのブロックには印を付けず、アラビア語のブロックに{dir=rtl}を付けます。

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

よくあるつまずき

つまずき

アラビア語の本のタグはLANGではなく'ar'にする

レシピの版はenとesですが、アラビア語のサンプルはどちらの版でもアラビア語です。`locale: LANG`では左から右に組まれ、左綴じになり、ページ番号は1 2 3となり、図のキャプションにはFigureやFiguraが付きます。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、英語やスペイン語のタグでは、Markazi Textのようなフォントがギュメ(« »)や終止符をアラビア語の字形で描かず、改行の位置も変わります。タグは自分で書いてください。'ar'(アラビア・インド数字、マシュリク地域の慣習)、'ar-EG'や'ar-SA'のような地域付きのタグ、ヨーロッパ式数字を使うマグレブ版なら'ar-MA'、'ar-DZ'、'ar-TN'です。アラビア語を引用するだけのラテン文字のページは、自分のロケールのままにします。 右から左のテキスト →

つまずき

アラビア語の書体にはarabicブロックを通じてarabicファイルが必要

FontsourceはAmiri、Noto Naskh Arabic、Scheherazade Newをサブセットごとに1ファイルとして配信し、アラビア文字はarabicファイルに入っています。loadFontsが取得するのはlatin(とlatin-ext)だけなので、画面ではアラビア文字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、空の四角が印字されます。キットのarabicブロックを挙げ、loadFontsのあとにloadArabicFonts(FONTS, markdown)を呼び(ページでアラビア文字に使うすべてのウェイトをFONTSに挙げておきます)、renderToPdfにfontProvider: arabicPdfProviderを渡してください。 アラビア語のフォント →

  • 英語のブロックの中でも、リストの番号やキャプションのラベルなど、エンジンが書く数字は文書の数字をとります(アラビア語の報告書なら٢)。こうした表には番号を振らないリソースの種類を与えるか、数字を自分で書いてください。

クレジット

レシピ
Ignacio Ferro
本文
  • The annual report of an invented translation foundation, written in Arabic, English and Spanish for the recipe · Postext Cookbook · オリジナル
フォント
IBM Plex Sans Arabic (SIL OFL 1.1) · IBM Plex Sans (SIL OFL 1.1)
SandboxPDF