Checks and fixups
Custom automatic fixups
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–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.
Customizing behavior using flags
You can fine-tune the Weblate behavior by using flags. This can be done on the source string level (see Additional info on source strings), or in the Component configuration (Übersetzungsmarkierungen). Some file formats also allow to specify flags directly in the format (see Supported file formats).
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:.*
Both single and double quotes are accepted, special characters are being escaped using backslash:
placeholders:"quoted \"string\"":'single \'quoted\''
Here is a list of flags currently accepted:
rst-text
Treat a text as an reStructuredText document, affects Unveränderte Übersetzung.
dos-eol
Uses DOS end-of-line markers instead of Unix ones (
\r\n
instead of\n
).read-only
The string is read-only and should not be edited in Weblate, see Schreibgeschützte Zeichenketten.
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 Maximale Länge der Übersetzung.
xml-text
Treat text as XML document, affects XML-Syntax and XML-Auszeichnung.
font-family:NAME
Define font-family for rendering checks, see Managing fonts.
font-weight:WEIGHT
Define font-weight for rendering checks, see Managing fonts.
font-size:SIZE
Define font-size for rendering checks, see Managing fonts.
font-spacing:SPACING
Define letter spacing for rendering checks, see Managing fonts.
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:...
Placeholder strings expected in translation, see Platzhalter.
replacements:FROM:TO:FROM2:TO2...
Replacements to perform when checking resulting text parameters (for example in Maximaler Umfang der Übersetzung or Maximale Länge der Übersetzung). 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 String variants.
regex:REGEX
Regulärer Ausdruck zum Abgleich mit der Übersetzung, siehe Regulärer Ausdruck.
forbidden
Indicates forbidden translation in a glossary, see Forbidden translations.
strict-same
Make „Unchanged translation“ avoid using built-in words blacklist, see Unveränderte Übersetzung.
check-glossary
Aktiviere Qualitätsprüfung Folgt nicht dem Glossar.
angularjs-format
Aktiviere Qualitätsprüfung AngularJS-Interpolations-Zeichenkette.
c-format
Aktiviere Qualitätsprüfung C-Format.
c-sharp-format
Aktiviere Qualitätsprüfung C#-Format.
es-format
Aktiviere Qualitätsprüfung ECMAScript-Buchstabenvorlagen.
i18next-interpolation
Aktiviere Qualitätsprüfung i18next Interpolation.
icu-message-format
Aktiviere Qualitätsprüfung ICU MessageFormat.
java-printf-format
Enable the Java-Format quality check.
java-format
Aktiviere Qualitätsprüfung Java-MessageFormat.
javascript-format
Aktiviere Qualitätsprüfung JavaScript-Format.
lua-format
Aktiviere Qualitätsprüfung Lua-Format.
object-pascal-format
Aktiviere Qualitätsprüfung Object Pascal-Format.
percent-placeholders
Aktiviere Qualitätsprüfung Platzhalter in Prozent.
perl-format
Aktiviere Qualitätsprüfung Perl-Format.
php-format
Aktiviere Qualitätsprüfung PHP-Format.
python-brace-format
Aktiviere Qualitätsprüfung Python-Brace-Format.
python-format
Aktiviere Qualitätsprüfung Python-Format.
qt-format
Aktiviere Qualitätsprüfung Qt-Format.
qt-plural-format
Aktiviere Qualitätsprüfung Qt-Plural-Format.
ruby-format
Aktiviere Qualitätsprüfung Ruby-Format.
scheme-format
Aktiviere Qualitätsprüfung Scheme-Format.
vue-format
Aktiviere Qualitätsprüfung Vue I18n-Formatierung.
md-text
Text wie ein Markdown-Dokument behandeln. Aktivieren Sie die Qualitätsprüfungen Markdown-Links, Markdown-Referenzen, und Markdown-Syntax.
case-insensitive
Adjust checks behavior to be case-insensitive. Currently affects only Platzhalter quality check.
safe-html
Aktiviere Qualitätsprüfung Unsicheres HTML.
url
Die Zeichenkette sollte nur aus einer URL bestehen. Aktivieren Sie die Qualitätsprüfung URL.
ignore-all-checks
Ignoriere alle Qualitätsprüfungen.
ignore-bbcode
Überspringe Qualitätsprüfung BBCode-Markup.
ignore-duplicate
Überspringe Qualitätsprüfung Aufeinanderfolgende doppelte Wörter.
ignore-check-glossary
Überspringe Qualitätsprüfung Folgt nicht dem Glossar.
ignore-double-space
Überspringe Qualitätsprüfung Doppeltes Leerzeichen.
ignore-angularjs-format
Überspringe Qualitätsprüfung AngularJS-Interpolations-Zeichenkette.
ignore-c-format
Überspringe Qualitätsprüfung C-Format.
ignore-c-sharp-format
Überspringe Qualitätsprüfung C#-Format.
ignore-es-format
Überspringe Qualitätsprüfung ECMAScript-Buchstabenvorlagen.
ignore-i18next-interpolation
Überspringe Qualitätsprüfung i18next Interpolation.
ignore-icu-message-format
Überspringe Qualitätsprüfung ICU MessageFormat.
ignore-java-format
Überspringe Qualitätsprüfung Java-MessageFormat.
ignore-java-printf-format
Skip the Java-Format quality check.
ignore-javascript-format
Überspringe Qualitätsprüfung JavaScript-Format.
ignore-lua-format
Überspringe Qualitätsprüfung Lua-Format.
ignore-object-pascal-format
Überspringe Qualitätsprüfung Object Pascal-Format.
ignore-percent-placeholders
Überspringe Qualitätsprüfung Platzhalter in Prozent.
ignore-perl-format
Überspringe Qualitätsprüfung Perl-Format.
ignore-php-format
Überspringe Qualitätsprüfung PHP-Format.
ignore-python-brace-format
Überspringe Qualitätsprüfung Python-Brace-Format.
ignore-python-format
Überspringe Qualitätsprüfung Python-Format.
ignore-qt-format
Überspringe Qualitätsprüfung Qt-Format.
ignore-qt-plural-format
Überspringe Qualitätsprüfung Qt-Plural-Format.
ignore-ruby-format
Überspringe Qualitätsprüfung Ruby-Format.
ignore-scheme-format
Überspringe Qualitätsprüfung Scheme-Format.
ignore-vue-format
Überspringe Qualitätsprüfung Vue I18n-Formatierung.
ignore-translated
Überspringe Qualitätsprüfung Ist übersetzt worden.
ignore-inconsistent
Überspringe Qualitätsprüfung Inkonsistent.
ignore-kashida
Überspringe Qualitätsprüfung Kashida-Buchstabe verwendet.
ignore-md-link
Überspringe Qualitätsprüfung Markdown-Links.
ignore-md-reflink
Überspringe Qualitätsprüfung Markdown-Referenzen.
ignore-md-syntax
Überspringe Qualitätsprüfung Markdown-Syntax.
ignore-max-length
Überspringe Qualitätsprüfung Maximale Länge der Übersetzung.
ignore-max-size
Überspringe Qualitätsprüfung Maximaler Umfang der Übersetzung.
ignore-escaped-newline
Überspringe Qualitätsprüfung Mismatched \n.
ignore-end-colon
Überspringe Qualitätsprüfung Nicht übereinstimmender Doppelpunkt.
ignore-end-ellipsis
Überspringe Qualitätsprüfung Nicht übereinstimmende Auslassungspunkte.
ignore-end-exclamation
Überspringe Qualitätsprüfung Nicht übereinstimmendes Ausrufezeichen.
ignore-end-stop
Überspringe Qualitätsprüfung Nicht übereinstimmender Punkt.
ignore-end-question
Überspringe Qualitätsprüfung Nicht übereinstimmendes Fragezeichen.
ignore-end-semicolon
Überspringe Qualitätsprüfung Nicht übereinstimmendes Semikolon.
ignore-newline-count
Überspringe Qualitätsprüfung Nicht übereinstimmende Zeilenumbrüche.
ignore-plurals
Überspringe Qualitätsprüfung Fehlende Pluralformen.
ignore-placeholders
Überspringe Qualitätsprüfung Platzhalter.
ignore-punctuation-spacing
Überspringe Qualitätsprüfung Satzzeichenabstand.
ignore-regex
Überspringe Qualitätsprüfung Regulärer Ausdruck.
ignore-same-plurals
Überspringe Qualitätsprüfung Identische Pluralformen.
ignore-begin-newline
Überspringe Qualitätsprüfung Zeilenumbruch am Anfang.
ignore-begin-space
Überspringe Qualitätsprüfung Leerzeichen am Anfang.
ignore-end-newline
Überspringe Qualitätsprüfung Zeilenumbruch am Ende.
ignore-end-space
Überspringe Qualitätsprüfung Leerzeichen am Ende.
ignore-same
Überspringe Qualitätsprüfung Unveränderte Übersetzung.
ignore-safe-html
Überspringe Qualitätsprüfung Unsicheres HTML.
ignore-url
Überspringe Qualitätsprüfung URL.
ignore-xml-tags
Überspringe Qualitätsprüfung XML-Auszeichnung.
ignore-xml-invalid
Überspringe Qualitätsprüfung XML-Syntax.
ignore-zero-width-space
Überspringe Qualitätsprüfung Leerzeichen ohne Breite.
ignore-ellipsis
Überspringe Qualitätsprüfung Auslassungspunkte.
ignore-icu-message-format-syntax
Überspringe Qualitätsprüfung ICU MessageFormat-Syntax.
ignore-long-untranslated
Überspringe Qualitätsprüfung Lange nicht übersetzt.
ignore-multiple-failures
Überspringe Qualitätsprüfung Mehrfach fehlgeschlagene Überpüfungen.
ignore-unnamed-format
Überspringe Qualitätsprüfung Mehrere unbenannte Variablen.
ignore-optional-plural
Überspringe Qualitätsprüfung Ohne Pluralformen.
Bemerkung
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 Component configuration settings, per source string settings and in the translation file itself (for example in GNU gettext).
Enforcing checks
Neu in Version 3.11.
You can configure a list of checks which can not be ignored by setting Erzwungene Qualitätsprüfungen in Component configuration. Each listed check can not be dismissed in the user interface and any string failing this check is marked as Needs editing (see Translation states).
Managing fonts
Neu in Version 3.7.
Hinweis
Fonts uploaded into Weblate are used purely for purposes of the Maximaler Umfang der Übersetzung check, they do not have an effect in Weblate user interface.
The Maximaler Umfang der Übersetzung check used to calculate dimensions of the rendered text needs font to be loaded into Weblate and selected using a translation flag (see Customizing behavior using flags).
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 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 Qualitätsprüfungen), 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
Set a few attributes.
Implement either the
check
(if you want to deal with plurals in your code) or thecheck_single
method (which does it for you).
Some examples:
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 © 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
Prüfen, ob sich die Pluralformen des tschechischen Übersetzungstextes unterscheiden
Prüfen Sie anhand der Sprachinfo, ob die beiden Pluralformen im Tschechischen nicht gleich sind.
#
# 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