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 (Çeviri işaretleri). 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 Değiştirilmemiş çeviri.

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 Salt okunur dizgiler.

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 Çevirinin en çok uzunluğu.

xml-text

Treat text as XML document, affects XML sözdizimi and XML işaretlemesi.

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

ICU MessageFormat nitelik denetiminin davranışını özelleştirmek için bayraklar tanımla.

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 Yer tutucular.

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

Replacements to perform when checking resulting text parameters (for example in Çeviri maksimum boyutu or Çevirinin en çok uzunluğu). 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

Çeviri dosyalarını eşleştirmek için düzenli ifade, baknız Düzenli ifade.

forbidden

Indicates forbidden translation in a glossary, see Yasaklı çeviriler.

strict-same

Make “Unchanged translation” avoid using built-in words blacklist, see Değiştirilmemiş çeviri.

check-glossary

Sözlüğü takip etme nitelik denetimini etkinleştir.

angularjs-format

AngularJS ilişkilendirme dizgisi nitelik denetimini etkinleştir.

c-format

C biçimi nitelik denetimini etkinleştir.

c-sharp-format

C# biçimi nitelik denetimini etkinleştir.

es-format

ECMAScript şablon değişmezleri nitelik denetimini etkinleştir.

i18next-interpolation

Enable the i18next ilişkilendirmesi quality check.

icu-message-format

ICU MessageFormat nitelik denetimini etkinleştir.

java-printf-format

Enable the Java biçimi quality check.

java-format

Java MessageFormat nitelik denetimini etkinleştir.

javascript-format

JavaScript biçimi nitelik denetimini etkinleştir.

lua-format

Lua biçimi nitelik denetimini etkinleştir.

object-pascal-format

Object Pascal biçimi nitelik denetimini etkinleştir.

percent-placeholders

Enable the Yüzde yer tutucuları quality check.

perl-format

Perl biçimi nitelik denetimini etkinleştir.

php-format

PHP biçimi nitelik denetimini etkinleştir.

python-brace-format

Enable the Python ayracı biçimi quality check.

python-format

Enable the Python biçimi quality check.

qt-format

Qt biçimi nitelik denetimini etkinleştir.

qt-plural-format

Qt çoğul biçimi nitelik denetimini etkinleştir.

ruby-format

Ruby biçimi nitelik denetimini etkinleştir.

scheme-format

Şema biçimi nitelik denetimini etkinleştir.

vue-format

Vue I18n biçimlendirmesi nitelik denetimini etkinleştir.

md-text

Treat text as a Markdown document. Enable Markdown bağlantıları, Markdown başvuruları, and Markdown sözdizimi quality checks.

case-insensitive

Adjust checks behavior to be case-insensitive. Currently affects only Yer tutucular quality check.

safe-html

Güvenli olmayan HTML nitelik denetimini etkinleştir.

url

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

ignore-all-checks

Ignore all quality checks.

ignore-bbcode

BBCode işaretlemesi nitelik denetimini atla.

ignore-duplicate

Art arda yinelenen sözcükler nitelik denetimini atla.

ignore-check-glossary

Sözlüğü takip etme nitelik denetimini atla.

ignore-double-space

Çift boşluk nitelik denetimini atla.

ignore-angularjs-format

AngularJS ilişkilendirme dizgisi nitelik denetimini atla.

ignore-c-format

C biçimi nitelik denetimini atla.

ignore-c-sharp-format

C# biçimi nitelik denetimini atla.

ignore-es-format

ECMAScript şablon değişmezleri nitelik denetimini atla.

ignore-i18next-interpolation

check-i18next-format nitelik denetimini atla.

ignore-icu-message-format

ICU MessageFormat nitelik denetimini atla.

ignore-java-format

Java MessageFormat nitelik denetimini atla.

ignore-java-printf-format

Skip the Java biçimi quality check.

ignore-javascript-format

JavaScript biçimi nitelik denetimini atla.

ignore-lua-format

Lua biçimi nitelik denetimini atla.

ignore-object-pascal-format

Object Pascal biçimi nitelik denetimini atla.

ignore-percent-placeholders

Yüzde yer tutucuları nitelik denetimini atla.

ignore-perl-format

Perl biçimi nitelik denetimini atla.

ignore-php-format

PHP biçimi nitelik denetimini atla.

ignore-python-brace-format

Python ayracı biçimi nitelik denetimini atla.

ignore-python-format

Python biçimi nitelik denetimini atla.

ignore-qt-format

Qt biçimi nitelik denetimini atla.

ignore-qt-plural-format

Qt çoğul biçimi nitelik denetimini atla.

ignore-ruby-format

Ruby biçimi nitelik denetimini atla.

ignore-scheme-format

Şema biçimi nitelik denetimini atla.

ignore-vue-format

Vue I18n biçimlendirmesi nitelik denetimini atla.

ignore-translated

Çevrilmiş nitelik denetimini atla.

ignore-inconsistent

Tutarsız nitelik denetimini atla.

ignore-kashida

Kashida harfi kullanıldı nitelik denetimini atla.

ignore-md-link

Markdown bağlantıları nitelik denetimini atla.

ignore-md-reflink

Markdown başvuruları nitelik denetimini atla.

ignore-md-syntax

Markdown sözdizimi nitelik denetimini atla.

ignore-max-length

Çevirinin en çok uzunluğu nitelik denetimini atla.

ignore-max-size

Çeviri maksimum boyutu nitelik denetimini atla.

ignore-escaped-newline

\n uyuşmadı nitelik denetimini atla.

ignore-end-colon

İki nokta üst üste uyuşmadı nitelik denetimini atla.

ignore-end-ellipsis

Üç nokta uyuşmadı nitelik denetimini atla.

ignore-end-exclamation

Ünlem işareti uyuşmadı nitelik denetimini atla.

ignore-end-stop

Nokta işareti uyuşmadı nitelik denetimini atla.

ignore-end-question

Soru işareti uyuşmadı nitelik denetimini atla.

ignore-end-semicolon

Noktalı virgül uyuşmadı nitelik denetimini atla.

ignore-newline-count

Uyuşmayan satır sonları nitelik denetimini atla.

ignore-plurals

Eksik çoğul nitelik denetimini atla.

ignore-placeholders

Yer tutucular nitelik denetimini atla.

ignore-punctuation-spacing

Noktalama aralığı nitelik denetimini atla.

ignore-regex

Düzenli ifade nitelik denetimini atla.

ignore-same-plurals

Aynı çoğullar nitelik denetimini atla.

ignore-begin-newline

Baştaki yeni satır nitelik denetimini atla.

ignore-begin-space

Baştaki boşluk nitelik denetimini atla.

ignore-end-newline

Sondaki yeni satır nitelik denetimini atla.

ignore-end-space

Sondaki boşluk nitelik denetimini atla.

ignore-same

Değiştirilmemiş çeviri nitelik denetimini atla.

ignore-safe-html

Güvenli olmayan HTML nitelik denetimini atla.

ignore-url

URL nitelik denetimini atla.

ignore-xml-tags

XML işaretlemesi nitelik denetimini atla.

ignore-xml-invalid

XML sözdizimi nitelik denetimini atla.

ignore-zero-width-space

Sıfır genişlikli boşluk nitelik denetimini atla.

ignore-ellipsis

Üç nokta nitelik denetimini atla.

ignore-icu-message-format-syntax

ICU MessageFormat sözdizimi nitelik denetimini atla.

ignore-long-untranslated

Uzun süre çevrilmeyen nitelik denetimini atla.

ignore-multiple-failures

Birden çok kusur denetimi nitelik denetimini atla.

ignore-unnamed-format

Birden çok adsız değişken nitelik denetimini atla.

ignore-optional-plural

Çoğulsuz nitelik denetimini atla.

Not

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

3.11 sürümünde geldi.

You can configure a list of checks which can not be ignored by setting Zorunlu denetimler 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).

Not

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.

Managing fonts

3.7 sürümünde geldi.

İpucu

Fonts uploaded into Weblate are used purely for purposes of the Çeviri maksimum boyutu check, they do not have an effect in Weblate user interface.

The Çeviri maksimum boyutu 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

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 Quality checks), 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 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

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