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 © 2012 - 2021 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

from django.utils.translation import gettext_lazy as _

from weblate.trans.autofixes.base import AutoFix


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

    name = _("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, addons and auto-fixes.

Customizing behavior using flags

Vous pouvez affiner le comportement de Weblate (principalement les contrôles) pour chaque chaîne de caractères source (dans la revue des chaînes de caractères source, voir additionnal) ou dans le Configuration des composants (Drapeaux de traduction). Certains formats de fichiers permettent également de spécifier des drapeaux directement dans le format (voir Formats de fichiers pris en charge).

Les drapeaux sont séparés par des virgules, les paramètres sont séparés par deux points. Vous pouvez utiliser des guillemets pour inclure des espaces ou des caractères spéciaux dans la chaîne de caractères. Par exemple :

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

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.

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

Indicates forbidden translation in a glossary, see 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.

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-format

Enable the Format Java quality check.

java-messageformat

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-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. Enable Liens Markdown, Références Markdown, and Syntaxe Markdown quality checks.

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-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-format

Skip the Format Java quality check.

ignore-java-messageformat

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-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-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

Nouveau dans la version 3.11.

Vous pouvez configurer une liste de contrôles qui ne peuvent être ignorés en définissant Vérifications forcées dans Configuration des composants. Chaque vérification listée ne peut pas être ignorée dans l’interface utilisateur et toute chaîne échouant à cette vérification est marquée comme Needs editing (voir États de traduction).

Gestion des polices

Nouveau dans la version 3.7.

Indication

Fonts uploaded into Weblate are used purely for purposes of the Taille maximale de la traduction check, they do not have an effect in Weblate user interface.

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.png

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.png

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

../_images/font-edit.png

Vous pouvez charger plusieurs polices dans Weblate :

../_images/font-list.png

To use the fonts for checking the string length, pass it the appropriate flags (see Customizing behavior using flags). You will probably need the following ones:

max-size:500

Defines maximal width in pixels.

font-family:ubuntu

Defines font group to use by specifying its identifier.

font-size:22

Defines font size in pixels.

Writing own checks

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. Set a few attributes.

  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, addons 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 © 2012 - 2021 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""Simple quality check example."""

from django.utils.translation import gettext_lazy as _

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 = _("Foo check")

    # Description for failing check
    description = _("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

Check using language info to verify the two plural forms in Czech language are not same.

#
# Copyright © 2012 - 2021 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""Quality check example for Czech plurals."""

from django.utils.translation import gettext_lazy as _

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 = _("Foo check")

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

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

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