Kontrole i korekty

Niestandardowe automatyczne korekty

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 weblate.trans.autofixes.base import AutoFix


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

    # Might be localized using gettext_lazy
    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, automatic suggestions and auto-fixes.

Dostosowywanie zachowania za pomocą flag

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.

Here is a list of flags currently accepted:

read-only

The string is read-only and should not be edited in Weblate, see Ciągi tylko do odczytu.

terminology

Used in Słownik. 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 Maksymalna długość tłumaczenia.

xml-text

Treat text as XML document, affects Składnia XML and Znaczniki XML.

font-family:NAME

Define font-family for rendering checks, see Zarządzanie czcionkami.

font-weight:WEIGHT

Define font-weight for rendering checks, see Zarządzanie czcionkami.

font-size:SIZE

Define font-size for rendering checks, see Zarządzanie czcionkami.

font-spacing:SPACING

Define letter spacing for rendering checks, see Zarządzanie czcionkami.

icu-flags:FLAGS

Zdefiniuj flagi do dostosowywania zachowania kontroli jakości ICU MessageFormat.

icu-tag-prefix:PREFIX

Ustaw wymagany prefiks dla tagów XML dla kontroli jakości ICU MessageFormat.

placeholders:NAME:NAME2:...

Placeholder strings expected in translation, see Symbole zastępcze.

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

Replacements to perform when checking resulting text parameters (for example in Maksymalny rozmiar tłumaczenia or Maksymalna długość tłumaczenia). 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 Warianty ciągów.

regex:REGEX

Wyrażenie regularne pasujące do tłumaczenia, zobacz Wyrażenie regularne.

discard:NAME

Discards flag defined on a higher level.

forbidden

Indicates forbidden translation in a glossary, see Zabronione tłumaczenia.

strict-same

Make the Niezmienione tłumaczenie avoid using the built-in words exceptions.

strict-format

Make format checks enforce using format even for plural forms with a single value, see Formatowanie ciągów.

case-insensitive

Adjust checks behavior to be case-insensitive. Currently affects only Symbole zastępcze quality check.

bbcode-text

Treat a text as an Bulletin Board Code (BBCode) document, affects Niezmienione tłumaczenie. Enables the Znaczniki BBCode quality check.

check-glossary

Enables the Nie jest zgodny z słownikiem quality check.

fluent-parts

Enables the Części Fluent quality check.

fluent-references

Enables the Odnośniki Fluent quality check.

fluent-target-inner-html

Enables the Wewnętrzny HTML tłumaczenia Fluent quality check.

fluent-target-syntax

Enables the Składnia tłumaczenia Fluent quality check.

angularjs-format

Enables the Ciąg znaków interpolacji AngularJS quality check.

automattic-components-format

Enables the Automatyczne formatowanie komponentów quality check.

c-format

Enables the Format C quality check.

c-sharp-format

Enables the Format C# quality check.

csharp-format

Enables the Format C# quality check.

es-format

Enables the Literały szablonu ECMAScript quality check.

i18next-interpolation

Enables the interpolacja i18next quality check.

icu-message-format

Enables the ICU MessageFormat and Składnia ICU MessageFormat quality checks.

java-printf-format

Enables the Format Java quality check.

java-format

Enables the Format Java Message quality check.

auto-java-messageformat

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

javascript-format

Enables the Format JavaScript quality check.

laravel-format

Enables the Format Laravel quality check.

lua-format

Enables the Format Lua quality check.

object-pascal-format

Enables the Format Object Pascal quality check.

objc-format

Enables the Format Objective-C quality check.

percent-placeholders

Enables the Procent symboli zastępczych quality check.

perl-brace-format

Enables the Format nawiasów klamrowych Perla quality check.

perl-format

Enables the Format języka Perl quality check.

php-format

Enables the Format PHP quality check.

python-brace-format

Enables the Format klamrowy Python quality check.

python-format

Enables the Format Python quality check.

qt-format

Enables the Format Qt quality check.

qt-plural-format

Enables the Forma liczby mnogiej Qt quality check.

ruby-format

Enables the Format Ruby quality check.

scheme-format

Enables the Format Scheme quality check.

vue-format

Enables the Formatowanie Vue I18n quality check.

rst-text

Treat a text as an reStructuredText document, affects Niezmienione tłumaczenie. Enables the Niespójny reStructuredText and Błąd składniowy reStructuredText quality checks.

md-text

Treat a text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables the Łącza Markdown, Odniesienia do Markdown and Składnia Markdown quality checks.

max-length

Enables the Maksymalna długość tłumaczenia quality check.

max-size

Enables the Maksymalny rozmiar tłumaczenia quality check.

placeholders

Enables the Symbole zastępcze quality check.

regex

Enables the Wyrażenie regularne quality check.

safe-html

Enables the Niebezpieczny HTML quality check.

auto-safe-html

Treat a text as conditional HTML, enabling Niebezpieczny 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 Niebezpieczny HTML quality check.

url

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

fluent-source-inner-html

Enables the Wewnętrzny HTML źródła Fluent quality check.

fluent-source-syntax

Enables the Składnia źródła Fluent quality check.

ignore-all-checks

Ignoruj wszystkie kontrole jakości.

ignore-bbcode

Pomiń kontrolę jakości Znaczniki BBCode.

ignore-xml-chars-around-tags

Skip the Znaki wokół tagów XML quality check.

ignore-duplicate

Pomiń kontrolę jakości Kolejne zduplikowane wyrazy.

ignore-check-glossary

Pomiń kontrolę jakości Nie jest zgodny z słownikiem.

ignore-double-space

Pomiń kontrolę jakości Podwójna spacja.

ignore-fluent-parts

Skip the Części Fluent quality check.

ignore-fluent-references

Skip the Odnośniki Fluent quality check.

ignore-fluent-target-inner-html

Skip the Wewnętrzny HTML tłumaczenia Fluent quality check.

ignore-fluent-target-syntax

Skip the Składnia tłumaczenia Fluent quality check.

ignore-angularjs-format

Pomiń kontrolę jakości Ciąg znaków interpolacji AngularJS.

ignore-automattic-components-format

Skip the Automatyczne formatowanie komponentów quality check.

ignore-c-format

Pomiń kontrolę jakości Format C.

ignore-c-sharp-format

Pomiń kontrolę jakości Format C#.

ignore-es-format

Pomiń kontrolę jakości Literały szablonu ECMAScript.

ignore-i18next-interpolation

Pomiń kontrolę jakości interpolacja i18next.

ignore-icu-message-format

Pomiń kontrolę jakości ICU MessageFormat.

ignore-java-printf-format

Skip the Format Java quality check.

ignore-java-format

Pomiń kontrolę jakości Format Java Message.

ignore-javascript-format

Pomiń kontrolę jakości Format JavaScript.

ignore-laravel-format

Skip the Format Laravel quality check.

ignore-lua-format

Pomiń kontrolę jakości Format Lua.

ignore-object-pascal-format

Pomiń kontrolę jakości Format Object Pascal.

ignore-objc-format

Skip the Format Objective-C quality check.

ignore-percent-placeholders

Pomiń kontrolę jakości Procent symboli zastępczych.

ignore-perl-brace-format

Skip the Format nawiasów klamrowych Perla quality check.

ignore-perl-format

Pomiń kontrolę jakości Format języka Perl.

ignore-php-format

Pomiń kontrolę jakości Format PHP.

ignore-python-brace-format

Pomiń kontrolę jakości Format klamrowy Python.

ignore-python-format

Pomiń kontrolę jakości Format Python.

ignore-qt-format

Pomiń kontrolę jakości Format Qt.

ignore-qt-plural-format

Pomiń kontrolę jakości Forma liczby mnogiej Qt.

ignore-ruby-format

Pomiń kontrolę jakości Format Ruby.

ignore-scheme-format

Pomiń kontrolę jakości Format Scheme.

ignore-vue-format

Pomiń kontrolę jakości Formatowanie Vue I18n.

ignore-translated

Pomiń kontrolę jakości Zostało przetłumaczone.

ignore-inconsistent

Pomiń kontrolę jakości Niespójność.

ignore-rst-references

Skip the Niespójny reStructuredText quality check.

ignore-kashida

Pomiń kontrolę jakości Użyto litery Kashida.

ignore-md-link

Pomiń kontrolę jakości Łącza Markdown.

ignore-md-reflink

Pomiń kontrolę jakości Odniesienia do Markdown.

ignore-md-syntax

Pomiń kontrolę jakości Składnia Markdown.

ignore-max-length

Pomiń kontrolę jakości Maksymalna długość tłumaczenia.

ignore-max-size

Pomiń kontrolę jakości Maksymalny rozmiar tłumaczenia.

ignore-escaped-newline

Pomiń kontrolę jakości Niedopasowane \n.

ignore-end-colon

Pomiń kontrolę jakości Niedopasowany dwukropek.

ignore-end-ellipsis

Pomiń kontrolę jakości Niedopasowane wielokropki.

ignore-end-exclamation

Pomiń kontrolę jakości Niedopasowany wykrzyknik.

ignore-end-stop

Pomiń kontrolę jakości Niedopasowana kropka.

ignore-end-interrobang

Skip the Niedopasowany interrobang quality check.

ignore-end-question

Pomiń kontrolę jakości Niedopasowany znak zapytania.

ignore-end-semicolon

Pomiń kontrolę jakości Niedopasowany średnik.

ignore-newline-count

Pomiń kontrolę jakości Niedopasowanie podziałów wierszy.

ignore-plurals

Pomiń kontrolę jakości Brakująca forma liczby mnogiej.

ignore-multiple-capital

Skip the Wiele wielkich liter quality check.

ignore-kabyle-characters

Skip the Niestandardowe znaki w języku kabylskim quality check.

ignore-placeholders

Pomiń kontrolę jakości Symbole zastępcze.

ignore-prohibited-initial-character

Skip the Zabroniony znak początkowy quality check.

ignore-punctuation-spacing

Pomiń kontrolę jakości Odstępy między czcionkami.

ignore-regex

Pomiń kontrolę jakości Wyrażenie regularne.

ignore-rst-syntax

Skip the Błąd składniowy reStructuredText quality check.

ignore-reused

Skip the Ponownie użyte tłumaczenie quality check.

ignore-same-plurals

Pomiń kontrolę jakości Te same liczby mnogie.

ignore-begin-newline

Pomiń kontrolę jakości Początek od nowej linii.

ignore-begin-space

Pomiń kontrolę jakości Spacje początkowe.

ignore-end-newline

Pomiń kontrolę jakości Zakończenie nową linią.

ignore-end-space

Pomiń kontrolę jakości Końcowa spacja.

ignore-same

Pomiń kontrolę jakości Niezmienione tłumaczenie.

ignore-safe-html

Pomiń kontrolę jakości Niebezpieczny HTML.

ignore-url

Pomiń kontrolę jakości URL.

ignore-xml-tags

Pomiń kontrolę jakości Znaczniki XML.

ignore-xml-invalid

Pomiń kontrolę jakości Składnia XML.

ignore-zero-width-space

Pomiń kontrolę jakości Znak spacji o zerowej szerokości.

ignore-ellipsis

Pomiń kontrolę jakości Wielokropek.

ignore-fluent-source-inner-html

Skip the Wewnętrzny HTML źródła Fluent quality check.

ignore-fluent-source-syntax

Skip the Składnia źródła Fluent quality check.

ignore-icu-message-format

Pomiń kontrolę jakości Składnia ICU MessageFormat.

ignore-long-untranslated

Pomiń kontrolę jakości Długo nieprzetłumaczone.

ignore-multiple-failures

Pomiń kontrolę jakości Wiele nieudanych kontroli.

ignore-unnamed-format

Pomiń kontrolę jakości Wiele nienazwanych zmiennych.

ignore-optional-plural

Pomiń kontrolę jakości Niespluralizowane.

Informacja

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 Konfiguracja komponentu 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.

Wymuszanie kontroli

The enforced checks cannot be dismissed and mark string as Needs editing (see Stan tłumaczenia). This prevents translators from hiding such checks.

Podpowiedź

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 Formatowanie ciągów. Using for style checks like Niezmienione tłumaczenie is not recommended because dismissal is sometimes a reasonable approach in these.

The Filtr jakości tłumaczeń can then be used to exclude strings needing editing from being committed to the version control.

Zarządzanie czcionkami

Podpowiedź

Fonts uploaded into Weblate are used purely for purposes of the Maksymalny rozmiar tłumaczenia check, they do not have an effect in Weblate user interface.

The Maksymalny rozmiar tłumaczenia check used to calculate dimensions of the rendered text needs font to be loaded into Weblate and selected using a translation flag (see Dostosowywanie zachowania za pomocą flag).

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 Dostosowywanie zachowania za pomocą flag). 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

Określa rozmiar czcionki w pikselach.

Pisanie własnych kontroli

A wide range of quality checks are built-in, (see Kontrole jakości), 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. Podklasa weblate.checks.Check

  2. Ustaw kilka atrybutów.

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

Kilka przykładów:

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.

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 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
    # 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, 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.

"""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
    # 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):
        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