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.
The automatic fixes are powerful, but can also cause damage; be careful when writing one.
For example, the following automatic fixup would replace every occurrence of the string
foo in a translation with bar:
#
# Copyright © 2012 - 2020 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¶
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-textTreat a text as an reStructuredText document, affects Traducción no modificada.
md-textTreat text as a Markdown document.
dos-eolUses DOS end-of-line markers instead of Unix ones (
\r\ninstead of\n).urlThe string should consist of only a URL.
safe-htmlThe string should be HTML safe, see HTML inseguro.
read-onlyLa cadena es de solo lectura y no debe editarse en Weblate; vea Cadenas de solo lectura.
priority:NPriority 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:NLimit the maximal length for a string to N characters, see Longitud máxima de la traducción.
xml-textTreat text as XML document, affects Sintaxis XML and Marcación XML.
font-family:NOMBREDefine font-family for rendering checks, see Gestionar tipos de letra.
font-weight:PESODefine font-weight for rendering checks, see Gestionar tipos de letra.
font-size:TAMAÑODefine font-size for rendering checks, see Gestionar tipos de letra.
font-spacing:ESPACIADODefine font-spacing for rendering checks, see Gestionar tipos de letra.
placeholders:NOMBREPlaceholder 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 names, for example:
replacements:%s:"John Doe".regex:REGEXExpresión regular utilizada para relacionar traducciones; vea Expresión regular.
python-format,c-format,php-format,python-brace-format,javascript-format,c-sharp-format,java-format,java-messageformat,auto-java-messageformat,qt-format,qt-plural-format,ruby-format,vue-formatTreats all strings like format strings, affects Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Formatted strings, Traducción no modificada.
strict-sameHace que «Traducción no modificada» evite la lista de palabras incorporada; vea Traducción no modificada.
ignore-bbcodePasa por alto la comprobación de calidad «Marcación BBcode».
ignore-duplicatePasa por alto la comprobación de calidad «Palabras consecutivas duplicadas».
ignore-double-spacePasa por alto la comprobación de calidad «Espacio duplicado».
ignore-angularjs-formatPasa por alto la comprobación de calidad «Cadena de interpolación de AngularJS».
ignore-c-formatPasa por alto la comprobación de calidad «Formato C».
ignore-c-sharp-formatPasa por alto la comprobación de calidad «Formato C#».
ignore-es-formatPasa por alto la comprobación de calidad «Literales de plantilla ECMAScript».
ignore-i18next-interpolationPasa por alto la comprobación de calidad «Interpolación con i18next».
ignore-java-formatPasa por alto la comprobación de calidad «Formato Java».
ignore-java-messageformatPasa por alto la comprobación de calidad «MessageFormat de Java».
ignore-javascript-formatPasa por alto la comprobación de calidad «Formato JavaScript».
ignore-percent-placeholdersPasa por alto la comprobación de calidad «Sustitutorios con signo de porcentaje».
ignore-perl-formatPasa por alto la comprobación de calidad «Formato Perl».
ignore-php-formatPasa por alto la comprobación de calidad «Formato PHP».
ignore-python-brace-formatPasa por alto la comprobación de calidad «Formato de llaves de Python».
ignore-python-formatPasa por alto la comprobación de calidad «Formato Python».
ignore-qt-formatPasa por alto la comprobación de calidad «Formato Qt».
ignore-qt-plural-formatPasa por alto la comprobación de calidad «Formato de plurales de Qt».
ignore-ruby-formatPasa por alto la comprobación de calidad «Formato Ruby».
ignore-vue-formatSkip the «Vue I18n formatting» quality check.
ignore-translatedPasa por alto la comprobación de calidad «Se había traducido».
ignore-inconsistentPasa por alto la comprobación de calidad «Incoherente».
ignore-kashidaPasa por alto la comprobación de calidad «Kashida utilizado».
ignore-md-linkPasa por alto la comprobación de calidad «Enlaces de Markdown».
ignore-md-reflinkPasa por alto la comprobación de calidad «Referencias de Markdown».
ignore-md-syntaxPasa por alto la comprobación de calidad «Sintaxis de Markdown».
ignore-max-lengthPasa por alto la comprobación de calidad «Longitud máxima de la traducción».
ignore-max-sizePasa por alto la comprobación de calidad «Tamaño máximo de la traducción».
ignore-escaped-newlinePasa por alto la comprobación de calidad «n desiguales».
ignore-end-colonPasa por alto la comprobación de calidad «Dos puntos desiguales».
ignore-end-ellipsisPasa por alto la comprobación de calidad «Puntos suspensivos desiguales».
ignore-end-exclamationPasa por alto la comprobación de calidad «Signo de exclamación desigual».
ignore-end-stopPasa por alto la comprobación de calidad «Punto final desigual».
ignore-end-questionPasa por alto la comprobación de calidad «Signo de interrogación desigual».
ignore-end-semicolonPasa por alto la comprobación de calidad «Punto y coma desigual».
ignore-newline-countPasa por alto la comprobación de calidad «Saltos de renglón desiguales».
ignore-pluralsPasa por alto la comprobación de calidad «Faltan plurales».
ignore-placeholdersPasa por alto la comprobación de calidad «Sustitutorios».
ignore-punctuation-spacingPasa por alto la comprobación de calidad «Espaciado de puntuación».
ignore-regexPasa por alto la comprobación de calidad «Expresión regular».
ignore-same-pluralsPasa por alto la comprobación de calidad «Mismos plurales».
ignore-begin-newlinePasa por alto la comprobación de calidad «Salto de renglón al inicio».
ignore-begin-spacePasa por alto la comprobación de calidad «Espacios iniciales».
ignore-end-newlinePasa por alto la comprobación de calidad «Salto de renglón al final».
ignore-end-spacePasa por alto la comprobación de calidad «Espacio al final».
ignore-samePasa por alto la comprobación de calidad «Traducción no modificada».
ignore-safe-htmlPasa por alto la comprobación de calidad «HTML inseguro».
ignore-urlPasa por alto la comprobación de calidad «URL».
ignore-xml-tagsPasa por alto la comprobación de calidad «Marcación XML».
ignore-xml-invalidPasa por alto la comprobación de calidad «Sintaxis XML».
ignore-zero-width-spacePasa por alto la comprobación de calidad «Espacio de anchura cero».
ignore-ellipsisPasa por alto la comprobación de calidad «Puntos suspensivos».
ignore-long-untranslatedPasa por alto la comprobación de calidad «Largamente no traducida».
ignore-multiple-failuresPasa por alto la comprobación de calidad «Varias comprobaciones fallidas».
ignore-unnamed-formatPasa por alto la comprobación de calidad «Varias variables sin nombre».
ignore-optional-pluralPasa por alto la comprobación de calidad «No pluralizada».
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).
Enforcing checks¶
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 Translation states).
Gestionar tipos de letra¶
Nuevo en la versión 3.7.
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).
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:
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:
Font-family and style is automatically recognized after uploading them:
You can have a number of fonts loaded into Weblate:
To use the fonts for checking the string length, pass it the appropriate flags (see Personalizar el comportamiento). You will probably need the following ones:
max-size:500Defines maximal width.
font-family:ubuntuDefines font group to use by specifying its identifier.
font-size:22Defines font size.
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.
Subclass the weblate.checks.Check
Defina algunos atributos.
Implement either the
check(if you want to deal with plurals in your code) or thecheck_singlemethod (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 - 2020 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 - 2020 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