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:

from __future__ import annotations

from typing import TYPE_CHECKING

from weblate.trans.autofixes.base import AutoFix

if TYPE_CHECKING:
    from weblate.trans.models import Unit


class ReplaceFooWithBar(AutoFix):
    """Replace foo with bar."""

    # Might be localized using gettext_lazy
    name = "Foobar"

    def fix_single_target(
        self, target: str, source: str, unit: Unit
    ) -> tuple[str, bool]:
        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, automatic suggestions 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:

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

The flags defined on a higher level can be discarded using the discard:NAME syntax. For example, if a component is configured to safe-html, you can add discard:safe-html to the string flags to skip it for this particular string. Translation flags cannot discard an explicit read-only flag set on the source string.

Here is a list of flags currently accepted:

read-only

Ovaj je izraz samo-za-čitanje i ne smije se mijenjati u Weblateu, pogledaj Izrazi samo-za-čitanje.

terminology

Used in Glosar. 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.

xml-text

Treat text as XML document, affects XML sintaksa and XML označavanje.

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.

font-monospace

Display the string in the translation editor using a monospace font. Unlike the font-family/font-size/font-weight/font-spacing flags, this does not affect rendering checks and never loads an uploaded font; it only switches the editor to the browser’s built-in monospace font stack.

icu-flags:FLAGS

Definiraj oznake za prilagođavanje ponašanja provjere kvalitete ICU MessageFormat.

icu-tag-prefix:PREFIX

Postavi obavezni prefiks za XML oznake za provjeru kvalitete ICU MessageFormat.

placeholders:NAME:NAME2:...

Placeholder strings expected in translation, see Rezervirana mjesta.

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

Replacements to perform when checking resulting text parameters (for example in Maksimalna dužina prijevoda or Maksimalna dužina prijevoda). 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

Regularni izraz za poklapanje prijevoda, pogledaj Regularni izraz.

discard:NAME

Discards flag defined on a higher level.

forbidden

Indicates forbidden translation in a glossary, see Zabranjeni prijevodi.

strict-same

Make the Nepromijenjen prijevod avoid using the built-in words exceptions.

strict-format

Make format checks enforce using format even for plural forms with a single value, see Formatted strings.

case-insensitive

Adjust checks behavior to be case-insensitive. Currently affects only Rezervirana mjesta quality check.

accelerator

Specify the single punctuation accelerator marker, for example accelerator:&, accelerator:_, or accelerator:~. Enables the Accelerator key quality check.

asciidoc-text

Treat a text as an AsciiDoc document, affects Nepromijenjen prijevod. Enables the AsciiDoc markup quality check.

bbcode-text

Treat a text as an Bulletin Board Code (BBCode) document, affects Nepromijenjen prijevod. Enables the BBCode označavanje quality check.

check-glossary

Enables the Ne odgovara glosaru quality check.

fluent-parts

Enables the Fluent dijelovi quality check.

fluent-references

Enables the Fluent reference quality check.

fluent-target-inner-html

Enables the HTML unutar Fluent prijevoda quality check.

fluent-target-syntax

Enables the Sintaksa Fluent prijevoda quality check.

angularjs-format

Enables the Znakovni niz AngularJS interpolacije quality check.

automattic-components-format

Enables the Automatsko formatiranje komponenti quality check.

c-format

Enables the C format quality check.

c-sharp-format

Enables the C# format quality check.

csharp-format

Enables the C# format quality check.

es-format

Enables the ECMAScript literali predloška quality check.

i18next-interpolation

Enables the i18next interpolacija quality check.

icu-message-format

Enables the ICU MessageFormat and ICU MessageFormat sintaksa quality checks.

java-printf-format

Enables the Java format quality check.

java-format

Enables the Java MessageFormat quality check.

auto-java-messageformat

Treat a text as conditional Java MessageFormat, enabling Java MessageFormat only when the source contains Java MessageFormat placeholders. Enables the Java MessageFormat quality check.

javascript-format

Enables the JavaScript format quality check.

laravel-format

Enables the Laravel format quality check.

lua-format

Enables the Lua format quality check.

object-pascal-format

Enables the Objekt u Pascal formatu quality check.

objc-format

Enables the Objective-C format quality check.

percent-placeholders

Enables the Rezervirana mjesta između znakova postotka quality check.

perl-brace-format

Enables the Perl format s vitičastim zagradama quality check.

perl-format

Enables the Perl format quality check.

php-format

Enables the PHP format quality check.

python-brace-format

Enables the Python format vitičastih zagrada quality check.

python-format

Enables the Python format quality check.

qt-format

Enables the Qt format quality check.

qt-plural-format

Enables the Oblici množine u Qt formatu quality check.

ruby-format

Enables the Ruby format quality check.

scheme-format

Enables the Format sheme quality check.

vue-format

Enables the Vue I18n formatiranje quality check.

rst-text

Treat a text as an reStructuredText document, affects Nepromijenjen prijevod. Enables the Nedosljedni reStructuredText and Greška reStructuredText sintakse quality checks.

md-text

Treat a text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables the Markdown poveznice, Markdown reference and Markdown sintaksa quality checks.

max-length

Enables the Maksimalna dužina prijevoda quality check.

max-lines

Enables the Maximum number of lines quality check.

max-size

Enables the Maksimalna dužina prijevoda quality check.

placeholders

Enables the Rezervirana mjesta quality check.

regex

Enables the Regularni izraz quality check.

safe-mdx

Enables the Safe MDX quality check.

safe-html

Enables the Nesiguran HTML quality check.

auto-safe-html

Treat a text as conditional HTML, enabling Nesiguran HTML only for plain text or source strings that contain standard HTML markup or valid custom elements. This is useful for extended Markdown variants such as MDX, where angle-bracket syntax may not be HTML. Enables the Nesiguran HTML quality check.

url

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

fluent-source-inner-html

Enables the Unutarnji HTML Fluent izvora quality check.

fluent-source-syntax

Enables the Sintaksa Fluent izvora quality check.

ignore-all-checks

Zanemari sve provjere kvalitete.

ignore-accelerator

Skip the Accelerator key quality check.

ignore-ai-accuracy

Skip the AI: Accuracy quality check.

ignore-ai-fluency

Skip the AI: Fluency quality check.

ignore-ai-formatting

Skip the AI: Formatting quality check.

ignore-ai-style

Skip the AI: Style quality check.

ignore-ai-terminology

Skip the AI: Terminology quality check.

ignore-asciidoc-markup

Skip the AsciiDoc markup quality check.

ignore-bbcode

Preskoči provjeru BBCode označavanje.

ignore-xml-chars-around-tags

Skip the Znakovi oko XML oznaka quality check.

ignore-duplicate

Preskoči provjeru Uzastopne jednake riječi.

ignore-check-glossary

Preskoči provjeru Ne odgovara glosaru.

ignore-double-space

Preskoči provjeru Dvostruki razmak.

ignore-fluent-parts

Preskoči provjeru kvalitete Fluent dijelovi.

ignore-fluent-references

Preskoči provjeru kvalitete Fluent reference.

ignore-fluent-target-inner-html

Preskoči provjeru kvalitete HTML unutar Fluent prijevoda.

ignore-fluent-target-syntax

Preskoči provjeru kvalitete Sintaksa Fluent prijevoda.

ignore-angularjs-format

Preskoči provjeru Znakovni niz AngularJS interpolacije.

ignore-automattic-components-format

Preskoči provjeru kvalitete Automatsko formatiranje komponenti.

ignore-c-format

Preskoči provjeru C format.

ignore-c-sharp-format

Preskoči provjeru C# format.

ignore-es-format

Preskoči provjeru ECMAScript literali predloška.

ignore-i18next-interpolation

Preskoči provjeru i18next interpolacija.

ignore-icu-message-format

Preskoči provjeru ICU MessageFormat.

ignore-java-printf-format

Preskoči provjeru Java format.

ignore-java-format

Preskoči provjeru Java MessageFormat.

ignore-javascript-format

Preskoči provjeru JavaScript format.

ignore-laravel-format

Skip the Laravel format quality check.

ignore-lua-format

Preskoči provjeru Lua format.

ignore-object-pascal-format

Preskoči provjeru Objekt u Pascal formatu.

ignore-objc-format

Skip the Objective-C format quality check.

ignore-percent-placeholders

Preskoči provjeru Rezervirana mjesta između znakova postotka.

ignore-perl-brace-format

Preskoči provjeru Perl format s vitičastim zagradama.

ignore-perl-format

Preskoči provjeru Perl format.

ignore-php-format

Preskoči provjeru PHP format.

ignore-python-brace-format

Preskoči provjeru Python format vitičastih zagrada.

ignore-python-format

Preskoči provjeru Python format.

ignore-qt-format

Preskoči provjeru Qt format.

ignore-qt-plural-format

Preskoči provjeru Oblici množine u Qt formatu.

ignore-ruby-format

Preskoči provjeru Ruby format.

ignore-scheme-format

Preskoči provjeru Format sheme.

ignore-vue-format

Preskoči provjeru Vue I18n formatiranje.

ignore-translated

Preskoči provjeru Prevedeno.

ignore-inconsistent

Preskoči provjeru Nedosljednost.

ignore-rst-references

Preskoči provjeru kvalitete Nedosljedni reStructuredText.

ignore-kashida

Preskoči provjeru Koristi se kashida znak.

ignore-md-link

Preskoči provjeru Markdown poveznice.

ignore-md-reflink

Preskoči provjeru Markdown reference.

ignore-md-syntax

Preskoči provjeru Markdown sintaksa.

ignore-max-length

Preskoči provjeru Maksimalna dužina prijevoda.

ignore-max-lines

Skip the Maximum number of lines quality check.

ignore-max-size

Preskoči provjeru Maksimalna dužina prijevoda.

ignore-escaped-newline

Preskoči provjeru Mismatched \n.

ignore-end-colon

Preskoči provjeru Nepoklapanje dvotočke.

ignore-end-ellipsis

Preskoči provjeru Nepoklapanje trotočke.

ignore-end-exclamation

Preskoči provjeru Nepoklapanje uskličnika.

ignore-end-stop

Preskoči provjeru Nepoklapanje točke.

ignore-end-interrobang

Preskoči kvalitativnu provjeru Nepoklapanje interrobang znaka.

ignore-end-question

Preskoči provjeru Nepoklapanje upitnika.

ignore-end-semicolon

Preskoči provjeru Nepoklapanje točka-zareza.

ignore-newline-count

Preskoči provjeru Nepoklapanje prekida redaka.

ignore-plurals

Preskoči provjeru Nedostaju oblici množine.

ignore-multiple-capital

Skip the Višestruka velika slova quality check.

ignore-kabyle-characters

Preskoči provjeru kvalitete Nestandardni znakovi u kabilskom jeziku.

ignore-placeholders

Preskoči provjeru Rezervirana mjesta.

ignore-prohibited-initial-character

Preskoči provjeru kvalitete Zabranjen početni znak.

ignore-punctuation-spacing

Preskoči provjeru Razmaci interpunkcija.

ignore-regex

Preskoči provjeru Regularni izraz.

ignore-rst-syntax

Preskoči provjeru kvalitete Greška reStructuredText sintakse.

ignore-reused

Preskoči provjeru Ponovo korišten prijevod.

ignore-safe-mdx

Skip the Safe MDX quality check.

ignore-same-plurals

Preskoči provjeru Jednake množine.

ignore-begin-newline

Preskoči provjeru Početni novi redak.

ignore-begin-space

Preskoči provjeru Početni razmaci.

ignore-end-newline

Preskoči provjeru Završni novi redak.

ignore-end-space

Preskoči provjeru Završni razmaci.

ignore-same

Preskoči provjeru Nepromijenjen prijevod.

ignore-safe-html

Preskoči provjeru Nesiguran HTML.

ignore-url

Preskoči provjeru URL.

ignore-xml-tags

Preskoči provjeru XML označavanje.

ignore-xml-invalid

Preskoči provjeru XML sintaksa.

ignore-zero-width-space

Preskoči provjeru Razmak bez širine.

ignore-ellipsis

Preskoči provjeru Trotočka.

ignore-fluent-source-inner-html

Preskoči provjeru kvalitete Unutarnji HTML Fluent izvora.

ignore-fluent-source-syntax

Preskoči provjeru kvalitete Sintaksa Fluent izvora.

ignore-icu-message-format

Preskoči provjeru ICU MessageFormat sintaksa.

ignore-long-untranslated

Preskoči provjeru Dugo neprevedeno.

ignore-multiple-failures

Preskoči provjeru Višestruke neuspjele provjere.

ignore-unnamed-format

Preskoči provjeru Višestruke neimenovane varijable.

ignore-source-max-length

Skip the Duljina izvornog izraza quality check.

ignore-optional-plural

Preskoči provjeru Bez množine.

Napomena

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 Konfiguracija komponente settings, per source string settings and in the translation file itself (for example in GNU gettext).

Location-based flags

Some flags are added to strings by default, based on their locations. This means that certain checks will be automatically enabled depending on where the string is used.

  • rst-text: This flag is automatically added to strings in reStructuredText files, if location extension is .rst.

  • md-text: This flag is automatically added to strings in Markdown and MDX files, if location extension is .md, .markdown, or .mdx.

Enforcing checks

The enforced checks cannot be dismissed and mark string as Needs editing (see Translation states). This prevents translators from hiding such checks.

Savjet

Turning on check enforcing doesn’t enable it automatically. Some checks have to be turned on by adding the corresponding flag to the string or component flags.

This is best used with checks that can cause serious issues when used like checks for Formatted strings. Using for style checks like Nepromijenjen prijevod is not recommended because dismissal is sometimes a reasonable approach in these.

The Filtar za kvalitetu prijevoda can then be used to exclude strings needing editing from being committed to the version control.

Managing fonts

Savjet

Fonts uploaded into Weblate are used purely for purposes of the Maksimalna dužina prijevoda check, they do not have an effect in Weblate user interface.

Provjera Maksimalna dužina prijevoda koja se koristi za izračunavanje dimenzija prikazanog teksta, zahtijeva da se font učita u Weblate i da se odabere korištenjem prevodilačke oznake (pogledaj Customizing behavior using flags).

Weblate font management tool in Fonts under the Operations 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.webp

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

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

../_images/font-edit.webp

You can have a number of fonts loaded into Weblate:

../_images/font-list.webp

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 when more than one line is configured.

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 Provjere kvalitete), 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. Set a few attributes.

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

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, automatic suggestions and auto-fixes.

Checks declaring propagates = "source" or propagates = "target" update related strings in the background after a save. They can override evaluate_propagated(units) to evaluate a matching group in bulk. Yield a (unit, failed) pair for every string, including passing strings so stale warnings can be removed. Without this override, Weblate evaluates the check on each matching string in chunks.

Checking translation text does not contain „foo”

This is a pretty simple check which just checks whether the translation is missing the string „foo”.

"""Simple quality check example."""

from __future__ import annotations

from typing import TYPE_CHECKING

from django.utils.translation import gettext_lazy

from weblate.checks.base import TargetCheck

if TYPE_CHECKING:
    from weblate.trans.models import Unit


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
    # Might be localized using gettext_lazy
    name = "Foo check"

    # Description for failing check
    description = gettext_lazy("Your translation is foo")

    # Real check code
    def check_single(self, source: str, target: str, unit: Unit) -> bool:
        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.

"""Quality check example for Czech plurals."""

from __future__ import annotations

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
    # Might be localized using gettext_lazy
    name = "Foo check"

    # Description for failing check
    description = gettext_lazy("Your translation is foo")

    # Real check code
    def check_target_unit(self, sources, targets, unit) -> bool:
        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