ABChapterize documentationv1.0.0Download

7. Languages and number recognition#

By default (--lang auto), the language used below is detected per file - see Auto language detection. An explicit --lang <code> pins the whole run to one language instead.

The chapter number in an announcement is recognized in three ways:

Language Code Example cardinal Example ordinal
English en chapter twenty-one twenty-first chapter
German de Kapitel einundzwanzig Einundzwanzigstes Kapitel
French fr chapitre vingt et un premier chapitre
Spanish es capítulo veintiuno vigésimo primer capítulo
Italian it capitolo ventuno primo capitolo
Dutch nl hoofdstuk eenentwintig eenentwintigste hoofdstuk
Turkish tr bölüm yirmi bir yirmi birinci bölüm
Portuguese pt capítulo vinte e um vigésimo primeiro capítulo
Polish pl rozdział dwadzieścia jeden rozdział dwudziesty pierwszy
Swedish sv kapitel tjugoett tjugoförsta kapitlet
Danish da kapitel enogtyve enogtyvende kapitel
Norwegian no kapittel tjueen tjueførste kapittel
Czech cs kapitola dvacet jedna dvacátá první kapitola

Cardinals are understood from 0 to 999 in every language, ordinals as far as the language spells them compositionally (see below), and the number may come after the phrase ("Chapter Seven") or before it ("Erstes Kapitel", "2. Kapitel", "premier chapitre", "Birinci Bölüm"). The parsers are exhaustively unit-tested against independent reference spellers for every cardinal number 0–999 in every language, and for every word ordinal too. Word ordinals reach 999 in most languages; Spanish and Portuguese stop at 199, and Danish at 100 standing on its own, since past that point these three reach for words ("ducentésimo") that no chapter announcement plausibly uses. Digit ordinals ("21.", "200.") work at any value regardless of language.

Spelling variants are covered rather than assumed: masculine and feminine ("vigésima primera"), fused and separate ("decimoctavo" as well as "décimo octavo"), accented and not, European and Brazilian Portuguese, and both the formal and the everyday Danish tens ("halvtredsindstyvende" and "halvtredsende" for 50th). Norwegian is read in both of the systems its books use — the modern "tjueen" for 21 and the older "enogtyve" it replaced, along with the conservative spellings that go with it ("syv" for 7, "tyve" for 20) — and Czech in both the formal "dvacet jedna" and the everyday "jedenadvacet".

Where two of the three readings would fit the same word, the language's own number words win over the Roman reading: French "dix" is ten, not 509.

For these languages, --lang also localizes the defaults of --chapter-phrase, --chapter-title, --part-title and --intro-title:

--lang Default phrase Default title word Default part word Default intro title
en /(?:^chapter ()\|^() chapter\|^chapter)/ Chapter Part Intro
de /(?:^kapitel ()\|^() kapitel\|^kapitel)/ Kapitel Teil Intro
fr /(?:^chapitre ()\|^() chapitre\|^chapitre)/ Chapitre Partie Introduction
es /(?:^cap[íi]tulo ()\|^() cap[íi]tulo\|^cap[íi]tulo)/ Capítulo Parte Introducción
it /(?:^capitolo ()\|^() capitolo\|^capitolo)/ Capitolo Parte Introduzione
nl /(?:^hoofdstuk ()\|^() hoofdstuk\|^hoofdstuk)/ Hoofdstuk Deel Intro
tr /(?:^b[öo]l[üu]m ()\|^() b[öo]l[üu]m\|^b[öo]l[üu]m)/ Bölüm Kısım Giriş
pt /(?:^cap[íi]tulo ()\|^() cap[íi]tulo\|^cap[íi]tulo)/ Capítulo Parte Introdução
pl /(?:^rozdzia[łl] ()\|^() rozdzia[łl]\|^rozdzia[łl])/ Rozdział Część Wstęp
sv /(?:^kapit(?:el\|let) ()\|^() kapit(?:el\|let)\|^kapit(?:el\|let))/ Kapitel Del Introduktion
da /(?:^kapit(?:el\|let) ()\|^() kapit(?:el\|let)\|^kapit(?:el\|let))/ Kapitel Del Introduktion
no /(?:^kapit(?:tel\|let) ()\|^() kapit(?:tel\|let)\|^kapit(?:tel\|let))/ Kapittel Del Introduksjon
cs /(?:^kapitola ()\|^() kapitola\|^kapitol)/ Kapitola Část Úvod

Every one of them is the same shape: three alternatives, the first taking the number that follows the word directly ("Kapitel 12"), the second the number that precedes it ("Erstes Kapitel", and in Turkish "Birinci Bölüm", which is that language's only order), and the third the bare word, which leaves the number to be read off whatever stands around it. All three carry a ^, since an announcement is by definition set off from what precedes it — either by a pause or by the recognizer writing it as a segment of its own.

Czech is the one row whose third alternative is shorter than its first two. The two that sit next to a number take the nominative kapitola, which is how a heading is announced, while the bare one stops at the stem so that every other case ending — kapitole, kapitoly, kapitolu — is still found.

Where two of them read the same words differently, the announcement is decided by the chapter sequence rather than by which alternative got there first: a number that cannot follow the chapters already found is put aside and the next reading of the same words is tried.

They are regular expressions so that one language's spellings are covered at once: an accent Whisper dropped (capitulo for capítulo), a letter it wrote without its diacritic (bolum for bölüm), or a stem the language itself changes (Swedish and Danish say "kapitlet" as readily as "kapitel"). Nothing else changes — the word is matched case-insensitively and as a substring exactly as a plain word would be, so an inflected ending needs no pattern of its own ("rozdziału" is found by rozdzia[łl]).

default in a --chapter-phrase value stands for whichever of these rows the file's language resolves to.

The same applies to the defaults of --prologue-phrase/--prologue-title and --epilogue-phrase/--epilogue-title (see Prologue and epilogue):

--lang Prologue phrase Prologue title Epilogue phrase Epilogue title
en /prolog/ Prologue /epilog/ Epilogue
de /prolog/ Prolog /epilog/ Epilog
fr /prologue/ Prologue /[ée]pilogue/ Épilogue
es /pr[óo]logo/ Prólogo /ep[íi]logo/ Epílogo
it /prologo/ Prologo /epilogo/ Epilogo
nl /proloog/ Proloog /epiloog/ Epiloog
tr /prolog/ Prolog /epilog/ Epilog
pt /pr[óo]logo/ Prólogo /ep[íi]logo/ Epílogo
pl /prolog/ Prolog /epilog/ Epilog
sv /prolog/ Prolog /epilog/ Epilog
da /prolog/ Prolog /epilog/ Epilog
no /prolog/ Prolog /epilog/ Epilog
cs /prolog/ Prolog /epilog/ Epilog

The English phrases cover the American "prolog"/"epilog" spellings simply by stopping short of the ending.

Each language uses its Latin-derived form rather than a native near-synonym (German "Vorwort", Turkish "Önsöz", …): those name a foreword, which is front matter about the book, whereas a prologue is part of the story and is what a narrator actually announces. Where a particular book disagrees, --prologue-phrase/--epilogue-phrase override it.

Other languages work too: give --lang for transcription and a --chapter-phrase (plain or regexp); announcements with digit numbers are then fully supported, e.g. --lang fi --chapter-phrase luku. If you would rather have your language supported properly — its spoken numbers included — doc/adding-a-language.md walks through adding one; it is a self-contained job that needs no knowledge of the rest of the codebase.