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 © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
from django.utils.translation import gettext_lazy
from weblate.trans.autofixes.base import AutoFix
class ReplaceFooWithBar(AutoFix):
"""Replace foo with bar."""
name = gettext_lazy("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 Weblate’s behavior by using flags. The flags provide visual feedback to the translators and help them to improve their translation. The flags are merged from following sources:
Source string, see Additional info on source strings.
Per-string flags extracted from the file format, see Formate të mbuluar kartelash.
Translation flags (currently only
read-only
flag for bilingual source string).File-format specific flags.
The flags are comma-separated; if they have parameters, they are separated with colon. You can use quotes to include whitespaces or special characters 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\''
placeholders:r"^#*"
To verify that translators do not change the heading of a Markdown document: A failing check will be triggered if the string ‹### Index› is translated as ‹# Indice›
placeholders:r"\]\([^h].*?\)"
To ensure that internal links are not being translated (i.e. [test](../checks) does not become [test](../chequeos).
Here is a list of flags currently accepted:
rst-text
Treat a text as an reStructuredText document, affects Përkthim i pandryshuar.
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 Vargje vetëm për lexim.
terminology
Used in Fjalorth. Copies the string into all glossary languages so it can be used consistently in all translations. Also useful in combination with
read-only
, for example in product names.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 Gjatësi maksimum e përkthimit.
xml-text
Treat text as XML document, affects Sintaksë XML and Markup XML.
font-family:NAME
Define font-family for rendering checks, see Administrim shkronjash.
font-weight:WEIGHT
Define font-weight for rendering checks, see Administrim shkronjash.
font-size:SIZE
Define font-size for rendering checks, see Administrim shkronjash.
font-spacing:SPACING
Define letter spacing for rendering checks, see Administrim shkronjash.
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 Vendmbajtëse.
replacements:FROM:TO:FROM2:TO2...
Replacements to perform when checking resulting text parameters (for example in Madhësi maksimum e përkthimit or Gjatësi maksimum e përkthimit). 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 Variante të vargut.
regex:REGEX
Shprehje e rregullt kundrejt të cilës duhen kërkuar përputhje te kartela përkthimi, shihni Shprehje e rregullt.
forbidden
Indicates forbidden translation in a glossary, see Forbidden translations.
strict-same
Make «Unchanged translation» avoid using built-in words blacklist, see Përkthim i pandryshuar.
strict-format
Make format checks enforce using format even for plural forms with a single value, see Vargje të formatuar.
check-glossary
Enable the S’ndjek fjalorthin quality check.
angularjs-format
Enable the Varg ndërshtënieje AngularJS quality check.
c-format
Enable the Format C quality check.
c-sharp-format
Enable the Format C# quality check.
es-format
Enable the ECMAScript template literals quality check.
i18next-interpolation
Enable the Ndërshtënie i18next quality check.
icu-message-format
Enable the ICU MessageFormat quality check.
java-printf-format
Enable the Format Java quality check.
java-format
Enable the Java MessageFormat quality check.
javascript-format
Enable the Format JavaScript quality check.
lua-format
Enable the Format Lua quality check.
object-pascal-format
Enable the Format Objektesh Pascal quality check.
percent-placeholders
Enable the Vendmbajtëse përqindjeje quality check.
perl-brace-format
Enable the Format kllapash Perl quality check.
perl-format
Enable the Format Perl quality check.
php-format
Enable the Format PHP quality check.
python-brace-format
Enable the Format kllapash Python quality check.
python-format
Enable the Format Python quality check.
qt-format
Enable the Format Qt quality check.
qt-plural-format
Enable the Format shumësi Qt quality check.
ruby-format
Enable the Format Ruby quality check.
scheme-format
Enable the Format Schema quality check.
vue-format
Enable the Formatim i18n Vue quality check.
md-text
Treat text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables Lidhje Markdown, Referenca Markdown, and Sintaksë Markdown quality checks.
case-insensitive
Adjust checks behavior to be case-insensitive. Currently affects only Vendmbajtëse quality check.
safe-html
Enable the HTML jo e parrezik quality check.
url
The string should consist of only a URL. Enable the URL quality check.
ignore-all-checks
Ignore all quality checks.
ignore-bbcode
Skip the Markup BBCode quality check.
ignore-duplicate
Skip the Fjalë të njëpasnjëshme të përsëdytura quality check.
ignore-check-glossary
Skip the S’ndjek fjalorthin quality check.
ignore-double-space
Skip the Hapësirë dyshe quality check.
ignore-angularjs-format
Skip the Varg ndërshtënieje 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 ECMAScript template literals quality check.
ignore-i18next-interpolation
Skip the Ndërshtënie i18next quality check.
ignore-icu-message-format
Skip the ICU MessageFormat quality check.
ignore-java-printf-format
Skip the Format Java quality check.
ignore-java-format
Skip the Java MessageFormat 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 Objektesh Pascal quality check.
ignore-percent-placeholders
Skip the Vendmbajtëse përqindjeje quality check.
ignore-perl-brace-format
Skip the Format kllapash Perl 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 kllapash 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 Format shumësi Qt quality check.
ignore-ruby-format
Skip the Format Ruby quality check.
ignore-scheme-format
Skip the Format Schema quality check.
ignore-vue-format
Skip the Formatim i18n Vue quality check.
ignore-translated
Skip the Është përkthyer quality check.
ignore-inconsistent
Skip the Jo i njëtrajtshëm quality check.
ignore-kashida
Skip the Është përdorur shkronjë Kashida quality check.
ignore-md-link
Skip the Lidhje Markdown quality check.
ignore-md-reflink
Skip the Referenca Markdown quality check.
ignore-md-syntax
Skip the Sintaksë Markdown quality check.
ignore-max-length
Skip the Gjatësi maksimum e përkthimit quality check.
ignore-max-size
Skip the Madhësi maksimum e përkthimit quality check.
ignore-escaped-newline
Skip the Mospërputhje n quality check.
ignore-end-colon
Skip the Mospërputhje dy pikash quality check.
ignore-end-ellipsis
Skip the Mospërputhje tre pikash quality check.
ignore-end-exclamation
Skip the Mospërputhje pikëçuditjesh quality check.
ignore-end-stop
Skip the Mospërputhje pike quality check.
ignore-end-question
Skip the Mospërputhje pikëpyetjesh quality check.
ignore-end-semicolon
Skip the Mospërputhje pikëpresjesh quality check.
ignore-newline-count
Skip the Mospërputhje ndërprerjesh rreshti quality check.
ignore-plurals
Skip the Mungon shumës quality check.
ignore-placeholders
Skip the Vendmbajtëse quality check.
ignore-punctuation-spacing
Skip the Hapësirë pikësimi quality check.
ignore-regex
Skip the Shprehje e rregullt quality check.
ignore-reused
Skip the Përkthim i ripërdorur quality check.
ignore-same-plurals
Skip the Shumës i njëjtë quality check.
ignore-begin-newline
Skip the Shenjë rresht i ri në fillim quality check.
ignore-begin-space
Skip the Hapësira fillimi quality check.
ignore-end-newline
Skip the Shenjë rresht i ri në fund quality check.
ignore-end-space
Skip the Hapësirë në fund quality check.
ignore-same
Skip the Përkthim i pandryshuar quality check.
ignore-safe-html
Skip the HTML jo e parrezik quality check.
ignore-url
Skip the URL quality check.
ignore-xml-tags
Skip the Markup XML quality check.
ignore-xml-invalid
Skip the Sintaksë XML quality check.
ignore-zero-width-space
Skip the Hapësirë me gjerësi zero quality check.
ignore-ellipsis
Skip the Tre pika quality check.
ignore-icu-message-format-syntax
Skip the Sintaksë ICU MessageFormat quality check.
ignore-long-untranslated
Skip the I papërkthyer prej kohësh quality check.
ignore-multiple-failures
Skip the Dështime të shumta kontrollesh quality check.
ignore-unnamed-format
Skip the Ndryshore të shumta të paemërtuara quality check.
ignore-optional-plural
Skip the Pa forma shumësi quality check.
Shënim
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¶
You can configure a list of checks which can not be ignored by setting Kontrolle me detyrim 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).
Shënim
Turning on check enforcing doesn’t enable it automatically. The check can be turned on by adding the corresponding flag to string or component flags.
Shihni edhe
Administrim shkronjash¶
Ndihmëz
Fonts uploaded into Weblate are used purely for purposes of the Madhësi maksimum e përkthimit check, they do not have an effect in Weblate user interface.
The Madhësi maksimum e përkthimit 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
/max-size:300:5
Defines maximal width in pixels and, optionally, the maximum number of lines (word wrapping is applied).
font-family:ubuntu
Defines font group to use by specifying its identifier.
font-size:22
Defines font size in pixels.
Si të shkruani kontrollet tuaja¶
A wide range of quality checks are built-in, (see Kontrolle cilësie), 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
Caktoni ndoca atribute.
Implement either the
check
(if you want to deal with plurals in your code) or thecheck_single
method (which does it for you).
Disa shembuj:
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 © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Simple quality check example."""
from django.utils.translation import gettext_lazy
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 = gettext_lazy("Foo check")
# Description for failing check
description = gettext_lazy("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 © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Quality check example for Czech plurals."""
from django.utils.translation import gettext_lazy
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 = gettext_lazy("Foo check")
# Description for failing check
description = gettext_lazy("Your translation is foo")
# Real check code
def check_target_unit(self, sources, targets, unit):
if unit.translation.language.is_base(("cs",)):
return targets[1] == targets[2]
return False
def check_single(self, source, target, unit) -> bool:
"""We don't check target strings here."""
return False