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 - 2021 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, addons and auto-fixes.

Customizing behavior using flags

You can fine-tune the behavior of Weblate (mostly checks) for each source string (in source strings review, see Additional info on source strings) or in the Component configuration (Flamuj përkthimi). Some file formats also allow to specify flags directly in the format (see Formate të mbuluar kartelash).

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-text

Treat a text as an reStructuredText document, affects Përkthim i pandryshuar.

md-text

Trajtojeni tekstin si një dokument Markdown.

dos-eol

Uses DOS end-of-line markers instead of Unix ones (\r\n instead of \n).

url

Vargu duhet të përbëhet vetëm nga një URL.

safe-html

The string should be HTML safe, see HTML jo e parrezik.

read-only

The string is read-only and should not be edited in Weblate, see Vargje vetëm për lexim.

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.

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.

python-format, c-format, object-pascal-format, php-format, python-brace-format, javascript-format, c-sharp-format, java-format, java-messageformat, lua-format, auto-java-messageformat, qt-format, qt-plural-format, ruby-format, scheme-format, vue-format

Treats all strings like format strings, affects Format Python, Format C, Object Pascal format, Format PHP, Format Qt, Format shumësi Qt, Format Ruby, Formatim i18n Vue, Format kllapash Python, Format JavaScript, Format C#, Format Java, Java MessageFormat, Format Lua, Format Schema, Përkthim i pandryshuar.

strict-same

Make «Unchanged translation» avoid using built-in words blacklist, see Përkthim i pandryshuar.

check-glossary

Enable the «Does not follow glossary» quality check.

ignore-bbcode

Anashkalo kontroll cilësie për «elementë shkrimi BBcode».

ignore-duplicate

Skip the «Consecutive duplicated words» quality check.

ignore-check-glossary

Skip the «Does not follow glossary» quality check.

ignore-double-space

Anashkalo kontroll cilësie për «Hapësirë dyshe».

ignore-angularjs-format

Skip the «AngularJS interpolation string» quality check.

ignore-c-format

Anashkalo kontroll cilësie për «format C».

ignore-c-sharp-format

Anashkalo kontroll cilësie për «format #C».

ignore-es-format

Anashkalo kontroll «ECMAScript template literals» cilësie.

ignore-i18next-interpolation

Anashkalo kontroll cilësie për «Ndërshtënie i18next».

ignore-java-format

Anashkalo kontroll cilësie për «Format Java».

ignore-java-messageformat

Anashkalo kontroll cilësie për «Java MessageFormat».

ignore-javascript-format

Anashkalo kontroll cilësie për «Format JavaScript».

ignore-lua-format

Skip the «Lua format» quality check.

ignore-object-pascal-format

Skip the «Object Pascal format» quality check.

ignore-percent-placeholders

Anashkalo kontroll cilësie për «Vendmbajtëse përqindje».

ignore-perl-format

Anashkalo kontroll cilësie për «Format Perl».

ignore-php-format

Anashkalo kontroll cilësie për «Format PHP».

ignore-python-brace-format

Anashkalo kontroll cilësie për «Format kllapash Python».

ignore-python-format

Anashkalo kontroll cilësie për «Format Python».

ignore-qt-format

Anashkalo kontroll cilësie për «Format Qt».

ignore-qt-plural-format

Anashkalo kontroll cilësie për «Format shumësi Qt».

ignore-ruby-format

Anashkalo kontroll cilësie për «Format Ruby».

ignore-vue-format

Skip the «Vue I18n formatting» quality check.

ignore-translated

Skip the «Has been translated» quality check.

ignore-inconsistent

Skip the «Inconsistent» quality check.

ignore-kashida

Skip the «Kashida letter used» quality check.

ignore-md-link

Anashkalo kontroll cilësie për «Lidhje Markdown».

ignore-md-reflink

Anashkalo kontroll cilësie për «Referenca Markdown».

ignore-md-syntax

Anashkalo kontroll cilësie për «Sintaksë Markdown».

ignore-max-length

Skip the «Maximum length of translation» quality check.

ignore-max-size

Skip the «Maximum size of translation» quality check.

ignore-escaped-newline

Anashkalo kontroll cilësie për «Mospërputhje n».

ignore-end-colon

Anashkalo kontroll «Mospërputhje dy pikash» cilësie.

ignore-end-ellipsis

Anashkalo kontroll «Mospërputhje elipsis».

ignore-end-exclamation

Anashkalo kontroll cilësie për «Mospërputhje pikëçuditjesh».

ignore-end-stop

Anashkalo kontroll cilësie për «Mospërputhje pikash».

ignore-end-question

Anashkalo kontroll cilësie për «Mospërputhje pikëpyetjesh».

ignore-end-semicolon

Anashkalo kontroll cilësie për «Mospërputhje pikëpresjesh».

ignore-newline-count

Skip the «Mismatching line breaks» quality check.

ignore-plurals

Anashkalo kontroll cilësie për «Mungesë shumësi».

ignore-placeholders

Anashkalo kontroll cilësie për «Vendmbajtëse».

ignore-punctuation-spacing

Anashkalo kontroll cilësie për «Hapësirë shenjash pikësimi».

ignore-regex

Anashkalo kontroll cilësie për «Shprehje të rregullt».

ignore-same-plurals

Anashkalo kontroll cilësie për «Të njëjtët shumësa».

ignore-begin-newline

Anashkalo kontroll cilësie për «Fillim me simbol rreshti të ri».

ignore-begin-space

Anashkalo kontroll cilësie për «Fillim me hapësira».

ignore-end-newline

Skip the «Trailing newline» quality check.

ignore-end-space

Skip the «Trailing space» quality check.

ignore-same

Anashkalo kontroll cilësie për «Përkthim i pandryshuar».

ignore-safe-html

Anashkalo kontroll cilësie për «HTML jo e parrezik».

ignore-url

Anashkalo kontroll cilësie për «URL».

ignore-xml-tags

Skip the «XML markup» quality check.

ignore-xml-invalid

Anashkalo kontroll cilësie për «Sintaksë XML».

ignore-zero-width-space

Anashkalo kontroll cilësie për «Hapësirë me gjerësi zero».

ignore-ellipsis

Anashkalo kontroll cilësie për «Mospërputhje».

ignore-long-untranslated

Skip the «Long untranslated» quality check.

ignore-multiple-failures

Skip the «Multiple failing checks» quality check.

ignore-unnamed-format

Skip the «Multiple unnamed variables» quality check.

ignore-optional-plural

Skip the «Unpluralised» 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

Të reja në versionin 3.11.

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 ignored in the user interface and any string failing this check is marked as Needs editing (see Translation states).

Administrim shkronjash

Të reja në versionin 3.7.

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:

../_images/font-group-edit.png

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

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

../_images/font-edit.png

You can have a number of fonts loaded into Weblate:

../_images/font-list.png

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

Përcakton gjerësinë maksimum.

font-family:ubuntu

Defines font group to use by specifying its identifier.

font-size:22

Përcakton madhësi shkronjash.

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.

  1. Subclass the weblate.checks.Check

  2. Caktoni ndoca atribute.

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

Disa shembuj:

To install custom checks, provide a fully-qualified path to the Python class in the CHECK_LIST, see Custom quality checks, addons 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 - 2021 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

Check using language info to verify the two plural forms in Czech language are not same.

#
# Copyright © 2012 - 2021 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