Contrôles de qualité et corrections#

Personnaliser les réparations automatiques#

Vous pouvez aussi implémenter vos propres réparations automatiques en plus de celles standards et les inclure dans AUTOFIX_LIST.

Les réparations automatiques sont puissantes, mais peuvent aussi causer des dommages ; soyez prudent quand vous en écrivez.

Par exemple, la réparation automatique suivante remplacerait chaque occurence de la chaîne foo dans une traduction par bar :

# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

from django.utils.translation import gettext_lazy

from weblate.trans.autofixes.base import AutoFix


class ReplaceFooWithBar(AutoFix):
    """Replace foo with bar."""

    name = gettext_lazy("Foobar")

    def fix_single_target(self, target, source, unit):
        if "foo" in target:
            return target.replace("foo", "bar"), True
        return target, False

Pour installer des contrôles personnalisés, fournissez un chemin d’accès complet à la classe Python dans le fichier AUTOFIX_LIST, voir Custom quality checks, add-ons and auto-fixes.

Customizing behavior using flags#

You can fine-tune Weblate’s behavior by using flags. The flags provide visual feedback to the translators and help them to improve their translation. The flags are merged from following sources:

The flags are comma-separated; if they have parameters, they are separated with colon. You can use quotes to include whitespaces or special characters in the string. For example:

placeholders:"special:value":"other value", regex:.*

Both single and double quotes are accepted, special characters are being escaped using backslash:

placeholders:"quoted \"string\"":'single \'quoted\''
placeholders:r"^#*"

To verify that translators do not change the heading of a Markdown document: A failing check will be triggered if the string “### Index” is translated as “# Indice”

placeholders:r"\]\([^h].*?\)"

To ensure that internal links are not being translated (i.e. [test](../checks) does not become [test](../chequeos).

Voici une liste des drapeaux actuellement acceptés :

rst-text

Traiter le texte comme document reStructuredText, affecte Traduction inchangée.

dos-eol

Utilise les marqueurs de fin de ligne DOS au lieu de ceux d’Unix (\r\n au lieu de \n).

read-only

La chaîne est en lecture seule et ne devrait pas être modifiée dans Weblate, voir Chaînes en lecture seule.

terminology

Used in Glossaire. Copies the string into all glossary languages so it can be used consistently in all translations. Also useful in combination with read-only, for example in product names.

priority:N

Priorité de la chaîne. Les chaînes de priorité plus élevée sont présentées en premier lieu pour la traduction. La priorité par défaut est de 100, plus une chaîne est prioritaire, plus elle est proposée tôt pour la traduction.

max-length:N

Limiter la longueur maximale d’une chaîne à N caractères, voir Taille maximum de la traduction.

xml-text

Traiter le texte comme document XML, affecte Syntaxe XML et Balisage XML.

font-family:NAME

Définir la famille de polices pour les contrôles de rendu, voir Gestion des polices.

font-weight:WEIGHT

Définir le poids des polices pour les contrôles de rendu, voir Gestion des polices.

font-size:SIZE

Définir la taille des polices pour les contrôles de rendu, voir Gestion des polices.

font-spacing:SPACING

Définir l’espacement des caractères pour les contrôles du rendu, voir Gestion des polices.

icu-flags:FLAGS

Define flags for customizing the behavior of the ICU MessageFormat quality check.

icu-tag-prefix:PREFIX

Set a required prefix for XML tags for the ICU MessageFormat quality check.

placeholders:NAME:NAME2:...

Chaînes de caractères de remplacement attendues dans la traduction, voir Balises de remplacement.

replacements:FROM:TO:FROM2:TO2...

Remplacements à effectuer lors de la vérification des paramètres du texte résultant (par exemple dans Taille maximale de la traduction ou Taille maximum de la traduction). Le cas d’utilisation typique est l’expansion des caractères à placer pour s’assurer que le texte s’adapte même aux grandes valeurs, par exemple : replacements:%s : "John Doe".

variants:SOURCE

Marquez cette chaîne en tant que variante de la chaîne avec la source correspondante. Voir String variants.

regex:REGEX

Expression rationnelle correspondant à la traduction, voir Expression rationnelle.

forbidden

Indique une traduction interdite dans un glossaire, voir Forbidden translations.

strict-same

Faire en sorte que les « Traductions inchangées » évitent d’utiliser la liste noire de mots intégrés, voir Traduction inchangée.

strict-format

Make format checks enforce using format even for plural forms with a single value, see Formatted strings.

check-glossary

Enable the Non conforme au glossaire quality check.

angularjs-format

Enable the Chaîne d’interpolation AngularJS quality check.

c-format

Enable the Format C quality check.

c-sharp-format

Enable the Format C# quality check.

es-format

Enable the Modèle de littéraux ECMAScript quality check.

i18next-interpolation

Enable the Interpolation i18next quality check.

icu-message-format

Enable the ICU MessageFormat quality check.

java-printf-format

Enable the Format Java quality check.

java-format

Enable the MessageFormat Java quality check.

javascript-format

Enable the Format JavaScript quality check.

lua-format

Enable the Format Lua quality check.

object-pascal-format

Enable the Format Pascal objet quality check.

percent-placeholders

Enable the Balises de remplacement par caractères pour cent quality check.

perl-brace-format

Enable the Perl brace format quality check.

perl-format

Enable the Format Perl quality check.

php-format

Enable the Format PHP quality check.

python-brace-format

Enable the Format d’accolade Python quality check.

python-format

Enable the Format Python quality check.

qt-format

Enable the Format Qt quality check.

qt-plural-format

Enable the Forme plurielle Qt quality check.

ruby-format

Enable the Format Ruby quality check.

scheme-format

Enable the Format Scheme quality check.

vue-format

Enable the Formatage Vue I18n quality check.

md-text

Treat text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables Liens Markdown, Références Markdown, and Syntaxe Markdown quality checks.

case-insensitive

Adjust checks behavior to be case-insensitive. Currently affects only Balises de remplacement quality check.

safe-html

Enable the HTML non sûr quality check.

url

The string should consist of only a URL. Enable the URL quality check.

ignore-all-checks

Ignorer toutes les vérifications de qualité.

ignore-bbcode

Skip the Balisage BBCode quality check.

ignore-duplicate

Skip the Répétition de mots quality check.

ignore-check-glossary

Skip the Non conforme au glossaire quality check.

ignore-double-space

Skip the Double espace quality check.

ignore-angularjs-format

Skip the Chaîne d’interpolation AngularJS quality check.

ignore-c-format

Skip the Format C quality check.

ignore-c-sharp-format

Skip the Format C# quality check.

ignore-es-format

Skip the Modèle de littéraux ECMAScript quality check.

ignore-i18next-interpolation

Skip the Interpolation i18next quality check.

ignore-icu-message-format

Skip the ICU MessageFormat quality check.

ignore-java-printf-format

Skip the Format Java quality check.

ignore-java-format

Skip the MessageFormat Java quality check.

ignore-javascript-format

Skip the Format JavaScript quality check.

ignore-lua-format

Skip the Format Lua quality check.

ignore-object-pascal-format

Skip the Format Pascal objet quality check.

ignore-percent-placeholders

Skip the Balises de remplacement par caractères pour cent quality check.

ignore-perl-brace-format

Skip the Perl brace format quality check.

ignore-perl-format

Skip the Format Perl quality check.

ignore-php-format

Skip the Format PHP quality check.

ignore-python-brace-format

Skip the Format d’accolade Python quality check.

ignore-python-format

Skip the Format Python quality check.

ignore-qt-format

Skip the Format Qt quality check.

ignore-qt-plural-format

Skip the Forme plurielle Qt quality check.

ignore-ruby-format

Skip the Format Ruby quality check.

ignore-scheme-format

Skip the Format Scheme quality check.

ignore-vue-format

Skip the Formatage Vue I18n quality check.

ignore-translated

Skip the A déjà été traduit quality check.

ignore-inconsistent

Skip the Incohérence quality check.

ignore-kashida

Skip the Présence d’un caractère kashida quality check.

ignore-md-link

Skip the Liens Markdown quality check.

ignore-md-reflink

Skip the Références Markdown quality check.

ignore-md-syntax

Skip the Syntaxe Markdown quality check.

ignore-max-length

Skip the Taille maximum de la traduction quality check.

ignore-max-size

Skip the Taille maximale de la traduction quality check.

ignore-escaped-newline

Skip the Pas de correspondance \n quality check.

ignore-end-colon

Skip the Incohérence de caractère deux-points quality check.

ignore-end-ellipsis

Skip the Incohérence de points de suspension quality check.

ignore-end-exclamation

Skip the Incohérence de point d’exclamation quality check.

ignore-end-stop

Skip the Incohérence de point final quality check.

ignore-end-question

Skip the Incohérence de point d’interrogation quality check.

ignore-end-semicolon

Skip the Incohérence de point-virgule quality check.

ignore-newline-count

Skip the Incohérence dans les sauts de ligne quality check.

ignore-plurals

Skip the Pluriels manquants quality check.

ignore-placeholders

Skip the Balises de remplacement quality check.

ignore-punctuation-spacing

Skip the Espacement de ponctuation quality check.

ignore-regex

Skip the Expression rationnelle quality check.

ignore-reused

Skip the Traduction réutilisée quality check.

ignore-same-plurals

Skip the Pluriel identique quality check.

ignore-begin-newline

Skip the Nouvelle ligne au début quality check.

ignore-begin-space

Skip the Espaces au début quality check.

ignore-end-newline

Skip the Saut de ligne à la fin quality check.

ignore-end-space

Skip the Espace à la fin quality check.

ignore-same

Skip the Traduction inchangée quality check.

ignore-safe-html

Skip the HTML non sûr quality check.

ignore-url

Skip the URL quality check.

ignore-xml-tags

Skip the Balisage XML quality check.

ignore-xml-invalid

Skip the Syntaxe XML quality check.

ignore-zero-width-space

Skip the Espace sans chasse quality check.

ignore-ellipsis

Skip the Points de suspension quality check.

ignore-icu-message-format-syntax

Skip the Syntaxe ICU MessageFormat quality check.

ignore-long-untranslated

Skip the Ancienne chaîne non traduite quality check.

ignore-multiple-failures

Skip the Plusieurs vérifications en échec quality check.

ignore-unnamed-format

Skip the Multiples variables non nommées quality check.

ignore-optional-plural

Skip the Non pluralisé quality check.

Note

En général, la règle est nommée ignore-* pour tout contrôle, en utilisant son identifiant, de sorte que vous pouvez l’utiliser, même pour vos contrôles personnalisés.

Ces drapeaux sont compris à la fois dans les paramètres des Configuration des composants, par chaîne source et dans le fichier de traduction lui-même (par exemple dans GNU gettext).

Exécution des contrôles#

You can configure a list of checks which can not be ignored by setting Vérifications forcées in Configuration des composants. Each listed check can not be dismissed in the user interface and any string failing this check is marked as Needs editing (see États de traduction).

Note

Turning on check enforcing doesn’t enable it automatically. The check can be turned on by adding the corresponding flag to string or component flags.

Gestion des polices#

Indication

Les polices téléchargées dans Weblate sont utilisées uniquement pour la vérification Taille maximale de la traduction, elles n’ont pas d’effet sur l’interface utilisateur de Weblate.

La vérification check-max-size`est utilisée pour calculer les dimensions du texte rendu, la police doit être chargée dans Weblate et sélectionnée à l’aide d’une marque de traduction (voir :ref:`custom-checks).

L’outil de gestion des polices Weblate dans Police de caractères du menu Gérer de votre projet de traduction fournit une interface pour télécharger et gérer les polices. Vous pouvez téléverser des polices TrueType et OpenType, configurer des groupes de polices et les utiliser fans la vérification.

Les groupes de polices vous permettent de définir différentes polices pour différentes langues, ce qui est généralement nécessaire pour les langues non latines :

../_images/font-group-edit.webp

Les groupes de polices sont identifiés par leur nom, qui ne peut pas contenir d’espace ni de caractères spéciaux, afin qu’il puisse être facilement utilisé dans la définition du contrôle :

../_images/font-group-list.webp

La famille de caractères et le style sont automatiquement reconnus après leur téléchargement :

../_images/font-edit.webp

Vous pouvez charger plusieurs polices dans Weblate :

../_images/font-list.webp

Pour utiliser les polices afin de vérifier la longueur des chaînes, passez-lui les drapeaux appropriés (voir Customizing behavior using flags). Vous aurez probablement besoin des drapeaux suivants :

max-size:500 / max-size:300:5

Defines maximal width in pixels and, optionally, the maximum number of lines (word wrapping is applied).

font-family:ubuntu

Définit le groupe de polices à utiliser en spécifiant son identifiant.

font-size:22

Définit la taille de la police en pixels.

Rédiger ses propres contrôles#

A wide range of quality checks are built-in, (see Quality checks), though they might not cover everything you want to check. The list of performed checks can be adjusted using CHECK_LIST, and you can also add custom checks.

  1. Subclass the weblate.checks.Check

  2. Définir certains attributs.

  3. Implement either the check (if you want to deal with plurals in your code) or the check_single method (which does it for you).

Quelques exemples :

To install custom checks, provide a fully-qualified path to the Python class in the CHECK_LIST, see Custom quality checks, add-ons and auto-fixes.

Checking translation text does not contain « foo »#

This is a pretty simple check which just checks whether the translation is missing the string « foo ».

# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""Simple quality check example."""

from django.utils.translation import gettext_lazy

from weblate.checks.base import TargetCheck


class FooCheck(TargetCheck):
    # Used as identifier for check, should be unique
    # Has to be shorter than 50 characters
    check_id = "foo"

    # Short name used to display failing check
    name = gettext_lazy("Foo check")

    # Description for failing check
    description = gettext_lazy("Your translation is foo")

    # Real check code
    def check_single(self, source, target, unit):
        return "foo" in target

Checking that Czech translation text plurals differ#

Vérifie à l’aide des infos de la langue que les deux formes plurielles en Tchèque ne sont pas les mêmes.

# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""Quality check example for Czech plurals."""

from django.utils.translation import gettext_lazy

from weblate.checks.base import TargetCheck


class PluralCzechCheck(TargetCheck):
    # Used as identifier for check, should be unique
    # Has to be shorter than 50 characters
    check_id = "foo"

    # Short name used to display failing check
    name = gettext_lazy("Foo check")

    # Description for failing check
    description = gettext_lazy("Your translation is foo")

    # Real check code
    def check_target_unit(self, sources, targets, unit):
        if unit.translation.language.is_base(("cs",)):
            return targets[1] == targets[2]
        return False

    def check_single(self, source, target, unit):
        """We don't check target strings here."""
        return False