Comprobaciones y correcciones

Correcciones automáticas personalizadas

You can also implement your own automatic fixup in addition to the standard ones and include them in AUTOFIX_LIST.

Las correcciones automáticas son potentes pero pueden causar daños; tenga cuidado al escribir una.

For example, the following automatic fixup would replace every occurrence of the string foo in a translation with 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

To install custom checks, provide a fully-qualified path to the Python class in the AUTOFIX_LIST, see Comprobaciones de calidad, complementos y correcciones automáticas personalizadas.

Personalizar el comportamiento mediante indicadores

You can fine-tune the behavior of Weblate (mostly checks) for each source string (in source strings review, see Información adicional sobre las cadenas de origen) or in the Configuración de componentes (Indicadores de traducción). Some file formats also allow to specify flags directly in the format (see Formatos de archivo admitidos).

The flags are comma-separated, the parameters are separated with colon. You can use quotes to include whitespace or special chars in the string. For example:

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

Here is a list of flags currently accepted:

rst-text

Treat a text as an reStructuredText document, affects Traducción no modificada.

dos-eol

Uses DOS end-of-line markers instead of Unix ones (\r\n instead of \n).

read-only

La cadena es de solo lectura y no debe editarse en Weblate; vea Cadenas de solo lectura.

priority:N

Priority of the string. Higher priority strings are presented first for translation. The default priority is 100, the higher priority a string has, the earlier it is offered for translation.

max-length:N

Limit the maximal length for a string to N characters, see Longitud máxima de la traducción.

xml-text

Treat text as XML document, affects Sintaxis XML and Marcación XML.

font-family:NOMBRE

Define font-family for rendering checks, see Gestionar tipos de letra.

font-weight:PESO

Define font-weight for rendering checks, see Gestionar tipos de letra.

font-size:TAMAÑO

Define font-size for rendering checks, see Gestionar tipos de letra.

font-spacing:ESPACIADO

Define letter spacing for rendering checks, see Gestionar tipos de letra.

placeholders:NAME:NAME2:...

Placeholder strings expected in translation, see Sustitutorios.

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

Replacements to perform when checking resulting text parameters (for example in Tamaño máximo de la traducción or Longitud máxima de la traducción). The typical use case for this is to expand placeables to ensure that the text fits even with long values, for example: replacements:%s:"John Doe".

variants:SOURCE

Mark this string as a variant of string with matching source. See Variantes de cadenas.

regex:REGEX

Expresión regular utilizada para relacionar traducciones; vea Expresión regular.

forbidden

Indicates forbidden translation in a glossary, see Traducciones prohibidas.

strict-same

Hace que «Traducción no modificada» evite la lista de palabras incorporada; vea Traducción no modificada.

check-glossary

Enable the No se ajusta al glosario quality check.

angularjs-format

Enable the Cadena de interpolación de AngularJS quality check.

c-format

Enable the Formato C quality check.

c-sharp-format

Enable the Formato C# quality check.

es-format

Enable the Literales de plantilla ECMAScript quality check.

i18next-interpolation

Enable the Interpolación con i18next quality check.

java-format

Enable the Formato Java quality check.

java-messageformat

Enable the MessageFormat de Java quality check.

javascript-format

Enable the Formato JavaScript quality check.

lua-format

Enable the Formato Lua quality check.

object-pascal-format

Enable the Formato de Object Pascal quality check.

percent-placeholders

Enable the Sustitutorios con signo de porcentaje quality check.

perl-format

Enable the Formato Perl quality check.

php-format

Enable the Formato PHP quality check.

python-brace-format

Enable the Formato de llaves de Python quality check.

python-format

Enable the Formato Python quality check.

qt-format

Enable the Formato Qt quality check.

qt-plural-format

Enable the Formato de plurales de Qt quality check.

ruby-format

Enable the Formato Ruby quality check.

scheme-format

Enable the Formato Scheme quality check.

vue-format

Enable the Formato de Vue I18n quality check.

md-text

Treat text as a Markdown document. Enable Enlaces de Markdown, Referencias de Markdown, and Sintaxis de Markdown quality checks.

safe-html

Enable the HTML inseguro quality check.

url

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

ignore-bbcode

Skip the Marcación BBcode quality check.

ignore-duplicate

Skip the Palabras consecutivas duplicadas quality check.

ignore-check-glossary

Skip the No se ajusta al glosario quality check.

ignore-double-space

Skip the Espacio duplicado quality check.

ignore-angularjs-format

Skip the Cadena de interpolación de AngularJS quality check.

ignore-c-format

Skip the Formato C quality check.

ignore-c-sharp-format

Skip the Formato C# quality check.

ignore-es-format

Skip the Literales de plantilla ECMAScript quality check.

ignore-i18next-interpolation

Skip the Interpolación con i18next quality check.

ignore-java-format

Skip the Formato Java quality check.

ignore-java-messageformat

Skip the MessageFormat de Java quality check.

ignore-javascript-format

Skip the Formato JavaScript quality check.

ignore-lua-format

Skip the Formato Lua quality check.

ignore-object-pascal-format

Skip the Formato de Object Pascal quality check.

ignore-percent-placeholders

Skip the Sustitutorios con signo de porcentaje quality check.

ignore-perl-format

Skip the Formato Perl quality check.

ignore-php-format

Skip the Formato PHP quality check.

ignore-python-brace-format

Skip the Formato de llaves de Python quality check.

ignore-python-format

Skip the Formato Python quality check.

ignore-qt-format

Skip the Formato Qt quality check.

ignore-qt-plural-format

Skip the Formato de plurales de Qt quality check.

ignore-ruby-format

Skip the Formato Ruby quality check.

ignore-scheme-format

Skip the Formato Scheme quality check.

ignore-vue-format

Skip the Formato de Vue I18n quality check.

ignore-translated

Skip the Se había traducido quality check.

ignore-inconsistent

Skip the Incoherente quality check.

ignore-kashida

Skip the Kashida utilizado quality check.

ignore-md-link

Skip the Enlaces de Markdown quality check.

ignore-md-reflink

Skip the Referencias de Markdown quality check.

ignore-md-syntax

Skip the Sintaxis de Markdown quality check.

ignore-max-length

Skip the Longitud máxima de la traducción quality check.

ignore-max-size

Skip the Tamaño máximo de la traducción quality check.

ignore-escaped-newline

Skip the \n desiguales quality check.

ignore-end-colon

Skip the Dos puntos desiguales quality check.

ignore-end-ellipsis

Skip the Puntos suspensivos desiguales quality check.

ignore-end-exclamation

Skip the Signo de exclamación desigual quality check.

ignore-end-stop

Skip the Punto final desigual quality check.

ignore-end-question

Skip the Signo de interrogación desigual quality check.

ignore-end-semicolon

Skip the Punto y coma desigual quality check.

ignore-newline-count

Skip the Saltos de renglón desiguales quality check.

ignore-plurals

Skip the Faltan plurales quality check.

ignore-placeholders

Skip the Sustitutorios quality check.

ignore-punctuation-spacing

Skip the Espaciado de puntuación quality check.

ignore-regex

Skip the Expresión regular quality check.

ignore-same-plurals

Skip the Mismos plurales quality check.

ignore-begin-newline

Skip the Salto de renglón al inicio quality check.

ignore-begin-space

Skip the Espacios iniciales quality check.

ignore-end-newline

Skip the Salto de renglón al final quality check.

ignore-end-space

Skip the Espacio al final quality check.

ignore-same

Skip the Traducción no modificada quality check.

ignore-safe-html

Skip the HTML inseguro quality check.

ignore-url

Skip the URL quality check.

ignore-xml-tags

Skip the Marcación XML quality check.

ignore-xml-invalid

Skip the Sintaxis XML quality check.

ignore-zero-width-space

Skip the Espacio de anchura cero quality check.

ignore-ellipsis

Skip the Puntos suspensivos quality check.

ignore-long-untranslated

Skip the Largamente no traducida quality check.

ignore-multiple-failures

Skip the Varias comprobaciones fallidas quality check.

ignore-unnamed-format

Skip the Varias variables sin nombre quality check.

ignore-optional-plural

Skip the No pluralizada quality check.

Nota

Generally the rule is named ignore-* for any check, using its identifier, so you can use this even for your custom checks.

These flags are understood both in Configuración de componentes settings, per source string settings and in the translation file itself (for example in GNU gettext).

Forzar comprobaciones

Nuevo en la versión 3.11.

You can configure a list of checks which can not be ignored by setting Comprobaciones obligatorias in Configuración de componentes. Each listed check can not be ignored in the user interface and any string failing this check is marked as Needs editing (see Estados de traducción).

Gestionar tipos de letra

Nuevo en la versión 3.7.

Consejo

Fonts uploaded into Weblate are used purely for purposes of the Tamaño máximo de la traducción check, they do not have an effect in Weblate user interface.

The Tamaño máximo de la traducción check used to calculate dimensions of the rendered text needs font to be loaded into Weblate and selected using a translation flag (see Personalizar el comportamiento mediante indicadores).

Weblate font management tool in Fonts under the Manage menu of your translation project provides interface to upload and manage fonts. TrueType or OpenType fonts can be uploaded, set up font-groups and use those in the check.

The font-groups allow you to define different fonts for different languages, which is typically needed for non-latin languages:

../_images/font-group-edit.png

The font-groups are identified by name, which can not contain whitespace or special characters, so that it can be easily used in the check definition:

../_images/font-group-list.png

Font-family and style is automatically recognized after uploading them:

../_images/font-edit.png

You can have a number of fonts loaded into Weblate:

../_images/font-list.png

To use the fonts for checking the string length, pass it the appropriate flags (see Personalizar el comportamiento mediante indicadores). You will probably need the following ones:

max-size:500

Define la anchura máxima.

font-family:ubuntu

Defines font group to use by specifying its identifier.

font-size:22

Define el tamaño del texto.

Writing own checks

A wide range of quality checks are built-in, (see Comprobaciones de calidad), 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. Defina algunos atributos.

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

He aquí algunos ejemplos:

To install custom checks, provide a fully-qualified path to the Python class in the CHECK_LIST, see Comprobaciones de calidad, complementos y correcciones automáticas personalizadas.

Checking translation text does not contain «foo»

Esta es una comprobación bastante simple que se limita a revisar si a la traducción le falta la cadena «tal».

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

Comprobación que utiliza la información de idioma para cerciorarse de que las dos formas de plural en checo no sean iguales.

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