.. _developer-readability-calculators: ======================= Readability Calculators ======================= The :guilabel:`DeepL Write` overlay shows a Flesch reading-ease score for the edited text (see :ref:`the feature description `). The score is computed by small, language specific *readability calculators* that can be extended by third-party extensions. How it works ============ Each calculator implements ``WebVision\DeeplWrite\Readability\ReadabilityCalculatorInterface`` – usually by extending ``WebVision\DeeplWrite\Readability\Calculator\AbstractReadabilityCalculator`` – and is registered through the ``deepl.readability`` service tag. At runtime ``ReadabilityCalculatorRegistry`` selects the calculator whose language matches the primary subtag of the editor content language, so ``en-US`` and ``en-GB`` both resolve to the English calculator. If no calculator matches, or the text contains no countable words, no score is reported and the overlay keeps working. The base class provides the shared text metrics – counting sentences, words (unicode aware) and syllables (via ``org_heigl/hyphenator``) – guards against empty input and caps the score at the maximum of 100. A concrete calculator therefore only has to provide the language specific formula. Supported languages =================== The following languages ship with a documented Flesch reading-ease adaptation, where ``ASL`` is the average sentence length (words / sentences) and ``ASW`` the average number of syllables per word (syllables / words): .. list-table:: :header-rows: 1 * - Language - Formula - Adaptation * - English (``en``) - ``206.835 - 1.015 * ASL - 84.6 * ASW`` - Flesch * - German (``de``) - ``180 - ASL - 58.5 * ASW`` - Amstad * - French (``fr``) - ``207 - 1.015 * ASL - 73.6 * ASW`` - Kandel & Moles * - Italian (``it``) - ``206 - ASL - 65 * ASW`` - Franchina & Vacca * - Portuguese (``pt``) - ``248.835 - 1.015 * ASL - 84.6 * ASW`` - Martins et al. Adding a language ================= To support an additional language, add a class that extends ``AbstractReadabilityCalculator``, declare the language it serves (``LANGUAGE``) and the hyphenation locale used for syllable counting (``HYPHENATION_LOCALE``, matching a dictionary shipped by ``org_heigl/hyphenator`` such as ``de``, ``en``, ``es``, ``fr``, ``it`` or ``pt``), and implement the language specific formula in ``calculateScore()``. Tag it with ``#[AutoconfigureTag('deepl.readability')]`` so it is picked up automatically: .. code-block:: php