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–2022 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 Custom quality checks, add-ons and auto-fixes.

Personalizar el comportamiento mediante indicadores

You can fine-tune the Weblate behavior by using flags. This can be done on the source string level (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.

icu-flags:FLAGS

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

icu-tag-prefix:PREFIX

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

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

Marcar esta cadena como una variante de cadena con origen coincidente. Ver Variantes de cadenas.

regex:REGEX

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

forbidden

Indica una traducción prohibida en un glosario, ver Traducciones prohibidas.

strict-same

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

check-glossary

Activar el control de calidad No se ajusta al glosario.

angularjs-format

Activar el control de calidad Cadena de interpolación de AngularJS.

c-format

Activar el control de calidad Formato C.

c-sharp-format

Activar el control de calidad Formato C#.

es-format

Activar el control de calidad Literales de plantilla ECMAScript.

i18next-interpolation

Activar el control de calidad Interpolación con i18next.

icu-message-format

Enable the MessageFormat de ICU quality check.

java-format

Activar el control de calidad Formato Java.

java-messageformat

Activar el control de calidad MessageFormat de Java.

javascript-format

Activar el control de calidad Formato JavaScript.

lua-format

Activar el control de calidad Formato Lua.

object-pascal-format

Activar el control de calidad Formato de Object Pascal.

percent-placeholders

Activar el control de calidad Sustitutorios con signo de porcentaje.

perl-format

Activar el control de calidad Formato Perl.

php-format

Activar el control de calidad Formato PHP.

python-brace-format

Activar el control de calidad Formato de llaves de Python.

python-format

Activar el control de calidad Formato Python.

qt-format

Activa el control de calidad Formato Qt.

qt-plural-format

Activa el control de calidad Formato de plurales de Qt.

ruby-format

Activa el control de calidad Formato Ruby.

scheme-format

Activa el control de calidad Formato Scheme.

vue-format

Activa el control de calidad Formato de Vue I18n.

md-text

Trata el texto como un documento Markdown. Activa el control de calidad Enlaces de Markdown, Referencias de Markdown, y Sintaxis de Markdown.

safe-html

Activa el control de calidad HTML inseguro.

url

La cadena debe consistir de solo una URL. Activa el control de calidad URL.

ignore-all-checks

Ignore all quality checks.

ignore-bbcode

Saltar el control de calidad Marcación BBCode.

ignore-duplicate

Omite el control de calidad Palabras consecutivas duplicadas.

ignore-check-glossary

Omite el control de calidad No se ajusta al glosario.

ignore-double-space

Omite el control de calidad Espacio duplicado.

ignore-angularjs-format

Omite el control de calidad Cadena de interpolación de AngularJS.

ignore-c-format

Omite el control de calidad Formato C.

ignore-c-sharp-format

Omite el control de calidad Formato C#.

ignore-es-format

Omite el control de calidad Literales de plantilla ECMAScript.

ignore-i18next-interpolation

Omite el control de calidad Interpolación con i18next.

ignore-icu-message-format

Skip the MessageFormat de ICU quality check.

ignore-java-format

Omite el control de calidad Formato Java.

ignore-java-messageformat

Omite el control de calidad MessageFormat de Java.

ignore-javascript-format

Omite el control de calidad Formato JavaScript.

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

Omite la comprobación de calidad HTML inseguro.

ignore-url

Omite la comprobación de calidad URL.

ignore-xml-tags

Omite la comprobación de calidad Marcación XML.

ignore-xml-invalid

Omite la comprobación de calidad Sintaxis XML.

ignore-zero-width-space

Omite la comprobación de calidad Espacio de anchura cero.

ignore-ellipsis

Omite la comprobación de calidad Puntos suspensivos.

ignore-icu-message-format-syntax

Skip the Sintaxis MessageFormat de ICU quality check.

ignore-long-untranslated

Omite la comprobación de calidad Largamente no traducida.

ignore-multiple-failures

Omite la comprobación de calidad Varias comprobaciones fallidas.

ignore-unnamed-format

Omite la comprobación de calidad:ref:check-unnamed-format.

ignore-optional-plural

Omite la comprobación de calidad No pluralizada.

Nota

Generalmente la regla se denomina ignore-* para cualquier comprobación, usa su identificador, así puedes utilizarlo incluso para tus comprobaciones personalizadas.

Estas flags se entienden tanto en la configuración de Configuración de componentes, por la configuración de la cadena de origen y en el propio archivo de traducción (por ejemplo en GNU gettext).

Forzar comprobaciones

Nuevo en la versión 3.11.

Puedes configurar una lista de comprobaciones que no se pueden ignoradar estableciendo Comprobaciones obligatorias en Configuración de componentes. No se pueden ignorar cada una de las comprobaciones enumeradas en la interfaz de usuario y cualquier cadena que falle esta comprobación se marca como:Needs editing (ver Estados de traducción).

Gestionar tipos de letra

Nuevo en la versión 3.7.

Consejo

Las fuentes cargadas en Weblate se usan únicamente a efectos de comprobación Tamaño máximo de la traducción, no tienen efecto en la interfaz de usuario de Weblate.

La comprobación Tamaño máximo de la traducción utilizada para calcular las dimensiones del texto renderizado necesita que la fuente se cargue en Weblate y se seleccione mediante una flag de traducción (ver Personalizar el comportamiento mediante indicadores).

La herramienta de gestión de fuentes de Weblate en Fonts bajo el menú Manage de tu proyecto de traducción proporciona una interfaz para cargar y gestionar las fuentes. Se pueden cargar fuentes TrueType u OpenType, configurar grupos de fuentes y utilizarlas en la comprobación.

Los grupos de fuentes permiten definir diferentes fuentes para distintos idiomas, lo que suele ser necesario para los idiomas no latinos:

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

Los grupos de fuentes se identifican por su nombre, que no puede contener espacios en blanco ni caracteres especiales, para que pueda utilizarse fácilmente en la definición de la comprobación:

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

El tipo de letra y el estilo se reconocen automáticamente después de cargarlos:

../_images/font-edit.png

Puedes tener varias fuentes cargadas en Weblate:

../_images/font-list.png

Para utilizar las fuentes que comprueban la longitud de la cadena, pásale los indicadores adecuados (ver Personalizar el comportamiento mediante indicadores). Posiblemente necesitarás los siguientes:

max-size:500

Defines maximal width in pixels.

font-family:ubuntu

Define el grupo de fuentes a utilizar especificando su identificador.

font-size:22

Defines font size in pixels.

Escribir los propios controles

Se han incorporado una amplia gama de controles de calidad, (ver Comprobaciones de calidad), aunque es posible que no cubran todo lo que quieres comprobar. Se puede ajustar la lista de comprobaciones realizadas mediante CHECK_LIST, y también puedes añadir controles personalizados.

  1. Subclase del weblate.checks.Check

  2. Defina algunos atributos.

  3. Implementa el ``check``(si quieres tratar los plurales en tu código) o el método ``check_single``(que lo hace por ti).

He aquí algunos ejemplos:

Para instalar controles personalizados, proporciona una ruta muy clara de clase Python en CHECK_LIST, ver Custom quality checks, add-ons and auto-fixes.

Comprueba que el texto de la traducción no contiene «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–2022 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

Comprueba que los plurales del texto traducido al checo son diferentes

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