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:
Dodatne oznake za izvorni izraz:
Dodatne informacije o izvornim izrazima describes manual editing.
Skupno uređivanje can be used to apply flags in batch.
Skupno uređivanje add-on can apply flags automatically.
Per-string flags extracted from the file format, see Localization file formats.
Translation flags (currently only
read-onlyflag for bilingual source string or when monolingual template editing is turned off).Oznake specifične za format datoteka.
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-onlyOvaj je izraz samo-za-čitanje i ne smije se mijenjati u Weblateu, pogledaj Izrazi samo-za-čitanje.
terminologyUsed 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:NPriority 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-textTreat text as XML document, affects XML sintaksa and XML označavanje.
font-family:NAMEDefine font-family for rendering checks, see Managing fonts.
font-weight:WEIGHTDefine font-weight for rendering checks, see Managing fonts.
font-size:SIZEDefine font-size for rendering checks, see Managing fonts.
font-spacing:SPACINGDefine letter spacing for rendering checks, see Managing fonts.
font-monospaceDisplay the string in the translation editor using a monospace font. Unlike the
font-family/font-size/font-weight/font-spacingflags, 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:FLAGSDefiniraj oznake za prilagođavanje ponašanja provjere kvalitete ICU MessageFormat.
icu-tag-prefix:PREFIXPostavi 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:SOURCEMark this string as a variant of string with matching source. See String variants.
regex:REGEXRegularni izraz za poklapanje prijevoda, pogledaj Regularni izraz.
discard:NAMEDiscards flag defined on a higher level.
forbiddenIndicates forbidden translation in a glossary, see Zabranjeni prijevodi.
strict-sameMake the Nepromijenjen prijevod avoid using the built-in words exceptions.
strict-formatMake format checks enforce using format even for plural forms with a single value, see Formatted strings.
case-insensitiveAdjust checks behavior to be case-insensitive. Currently affects only Rezervirana mjesta quality check.
acceleratorSpecify the single punctuation accelerator marker, for example
accelerator:&,accelerator:_, oraccelerator:~. Enables the Accelerator key quality check.asciidoc-textTreat a text as an AsciiDoc document, affects Nepromijenjen prijevod. Enables the AsciiDoc markup quality check.
bbcode-textTreat a text as an Bulletin Board Code (BBCode) document, affects Nepromijenjen prijevod. Enables the BBCode označavanje quality check.
check-glossaryEnables the Ne odgovara glosaru quality check.
fluent-partsEnables the Fluent dijelovi quality check.
fluent-referencesEnables the Fluent reference quality check.
fluent-target-inner-htmlEnables the HTML unutar Fluent prijevoda quality check.
fluent-target-syntaxEnables the Sintaksa Fluent prijevoda quality check.
angularjs-formatEnables the Znakovni niz AngularJS interpolacije quality check.
automattic-components-formatEnables the Automatsko formatiranje komponenti quality check.
c-formatEnables the C format quality check.
c-sharp-formatEnables the C# format quality check.
csharp-formatEnables the C# format quality check.
es-formatEnables the ECMAScript literali predloška quality check.
i18next-interpolationEnables the i18next interpolacija quality check.
icu-message-formatEnables the ICU MessageFormat and ICU MessageFormat sintaksa quality checks.
java-printf-formatEnables the Java format quality check.
java-formatEnables the Java MessageFormat quality check.
auto-java-messageformatTreat a text as conditional Java MessageFormat, enabling Java MessageFormat only when the source contains Java MessageFormat placeholders. Enables the Java MessageFormat quality check.
javascript-formatEnables the JavaScript format quality check.
laravel-formatEnables the Laravel format quality check.
lua-formatEnables the Lua format quality check.
object-pascal-formatEnables the Objekt u Pascal formatu quality check.
objc-formatEnables the Objective-C format quality check.
percent-placeholdersEnables the Rezervirana mjesta između znakova postotka quality check.
perl-brace-formatEnables the Perl format s vitičastim zagradama quality check.
perl-formatEnables the Perl format quality check.
php-formatEnables the PHP format quality check.
python-brace-formatEnables the Python format vitičastih zagrada quality check.
python-formatEnables the Python format quality check.
qt-formatEnables the Qt format quality check.
qt-plural-formatEnables the Oblici množine u Qt formatu quality check.
ruby-formatEnables the Ruby format quality check.
scheme-formatEnables the Format sheme quality check.
vue-formatEnables the Vue I18n formatiranje quality check.
rst-textTreat a text as an reStructuredText document, affects Nepromijenjen prijevod. Enables the Nedosljedni reStructuredText and Greška reStructuredText sintakse quality checks.
md-textTreat 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-lengthEnables the Maksimalna dužina prijevoda quality check.
max-linesEnables the Maximum number of lines quality check.
max-sizeEnables the Maksimalna dužina prijevoda quality check.
placeholdersEnables the Rezervirana mjesta quality check.
regexEnables the Regularni izraz quality check.
safe-mdxEnables the Safe MDX quality check.
safe-htmlEnables the Nesiguran HTML quality check.
auto-safe-htmlTreat 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.
urlThe string should consist of only a URL. Enables the URL quality check.
fluent-source-inner-htmlEnables the Unutarnji HTML Fluent izvora quality check.
fluent-source-syntaxEnables the Sintaksa Fluent izvora quality check.
ignore-all-checksZanemari sve provjere kvalitete.
ignore-acceleratorSkip the Accelerator key quality check.
ignore-ai-accuracySkip the AI: Accuracy quality check.
ignore-ai-fluencySkip the AI: Fluency quality check.
ignore-ai-formattingSkip the AI: Formatting quality check.
ignore-ai-styleSkip the AI: Style quality check.
ignore-ai-terminologySkip the AI: Terminology quality check.
ignore-asciidoc-markupSkip the AsciiDoc markup quality check.
ignore-bbcodePreskoči provjeru BBCode označavanje.
ignore-xml-chars-around-tagsSkip the Znakovi oko XML oznaka quality check.
ignore-duplicatePreskoči provjeru Uzastopne jednake riječi.
ignore-check-glossaryPreskoči provjeru Ne odgovara glosaru.
ignore-double-spacePreskoči provjeru Dvostruki razmak.
ignore-fluent-partsPreskoči provjeru kvalitete Fluent dijelovi.
ignore-fluent-referencesPreskoči provjeru kvalitete Fluent reference.
ignore-fluent-target-inner-htmlPreskoči provjeru kvalitete HTML unutar Fluent prijevoda.
ignore-fluent-target-syntaxPreskoči provjeru kvalitete Sintaksa Fluent prijevoda.
ignore-angularjs-formatPreskoči provjeru Znakovni niz AngularJS interpolacije.
ignore-automattic-components-formatPreskoči provjeru kvalitete Automatsko formatiranje komponenti.
ignore-c-formatPreskoči provjeru C format.
ignore-c-sharp-formatPreskoči provjeru C# format.
ignore-es-formatPreskoči provjeru ECMAScript literali predloška.
ignore-i18next-interpolationPreskoči provjeru i18next interpolacija.
ignore-icu-message-formatPreskoči provjeru ICU MessageFormat.
ignore-java-printf-formatPreskoči provjeru Java format.
ignore-java-formatPreskoči provjeru Java MessageFormat.
ignore-javascript-formatPreskoči provjeru JavaScript format.
ignore-laravel-formatSkip the Laravel format quality check.
ignore-lua-formatPreskoči provjeru Lua format.
ignore-object-pascal-formatPreskoči provjeru Objekt u Pascal formatu.
ignore-objc-formatSkip the Objective-C format quality check.
ignore-percent-placeholdersPreskoči provjeru Rezervirana mjesta između znakova postotka.
ignore-perl-brace-formatPreskoči provjeru Perl format s vitičastim zagradama.
ignore-perl-formatPreskoči provjeru Perl format.
ignore-php-formatPreskoči provjeru PHP format.
ignore-python-brace-formatPreskoči provjeru Python format vitičastih zagrada.
ignore-python-formatPreskoči provjeru Python format.
ignore-qt-formatPreskoči provjeru Qt format.
ignore-qt-plural-formatPreskoči provjeru Oblici množine u Qt formatu.
ignore-ruby-formatPreskoči provjeru Ruby format.
ignore-scheme-formatPreskoči provjeru Format sheme.
ignore-vue-formatPreskoči provjeru Vue I18n formatiranje.
ignore-translatedPreskoči provjeru Prevedeno.
ignore-inconsistentPreskoči provjeru Nedosljednost.
ignore-rst-referencesPreskoči provjeru kvalitete Nedosljedni reStructuredText.
ignore-kashidaPreskoči provjeru Koristi se kashida znak.
ignore-md-linkPreskoči provjeru Markdown poveznice.
ignore-md-reflinkPreskoči provjeru Markdown reference.
ignore-md-syntaxPreskoči provjeru Markdown sintaksa.
ignore-max-lengthPreskoči provjeru Maksimalna dužina prijevoda.
ignore-max-linesSkip the Maximum number of lines quality check.
ignore-max-sizePreskoči provjeru Maksimalna dužina prijevoda.
ignore-escaped-newlinePreskoči provjeru Mismatched \n.
ignore-end-colonPreskoči provjeru Nepoklapanje dvotočke.
ignore-end-ellipsisPreskoči provjeru Nepoklapanje trotočke.
ignore-end-exclamationPreskoči provjeru Nepoklapanje uskličnika.
ignore-end-stopPreskoči provjeru Nepoklapanje točke.
ignore-end-interrobangPreskoči kvalitativnu provjeru Nepoklapanje interrobang znaka.
ignore-end-questionPreskoči provjeru Nepoklapanje upitnika.
ignore-end-semicolonPreskoči provjeru Nepoklapanje točka-zareza.
ignore-newline-countPreskoči provjeru Nepoklapanje prekida redaka.
ignore-pluralsPreskoči provjeru Nedostaju oblici množine.
ignore-multiple-capitalSkip the Višestruka velika slova quality check.
ignore-kabyle-charactersPreskoči provjeru kvalitete Nestandardni znakovi u kabilskom jeziku.
ignore-placeholdersPreskoči provjeru Rezervirana mjesta.
ignore-prohibited-initial-characterPreskoči provjeru kvalitete Zabranjen početni znak.
ignore-punctuation-spacingPreskoči provjeru Razmaci interpunkcija.
ignore-regexPreskoči provjeru Regularni izraz.
ignore-rst-syntaxPreskoči provjeru kvalitete Greška reStructuredText sintakse.
ignore-reusedPreskoči provjeru Ponovo korišten prijevod.
ignore-safe-mdxSkip the Safe MDX quality check.
ignore-same-pluralsPreskoči provjeru Jednake množine.
ignore-begin-newlinePreskoči provjeru Početni novi redak.
ignore-begin-spacePreskoči provjeru Početni razmaci.
ignore-end-newlinePreskoči provjeru Završni novi redak.
ignore-end-spacePreskoči provjeru Završni razmaci.
ignore-samePreskoči provjeru Nepromijenjen prijevod.
ignore-safe-htmlPreskoči provjeru Nesiguran HTML.
ignore-urlPreskoči provjeru URL.
ignore-xml-tagsPreskoči provjeru XML označavanje.
ignore-xml-invalidPreskoči provjeru XML sintaksa.
ignore-zero-width-spacePreskoči provjeru Razmak bez širine.
ignore-ellipsisPreskoči provjeru Trotočka.
ignore-fluent-source-inner-htmlPreskoči provjeru kvalitete Unutarnji HTML Fluent izvora.
ignore-fluent-source-syntaxPreskoči provjeru kvalitete Sintaksa Fluent izvora.
ignore-icu-message-formatPreskoči provjeru ICU MessageFormat sintaksa.
ignore-long-untranslatedPreskoči provjeru Dugo neprevedeno.
ignore-multiple-failuresPreskoči provjeru Višestruke neuspjele provjere.
ignore-unnamed-formatPreskoči provjeru Višestruke neimenovane varijable.
ignore-source-max-lengthSkip the Duljina izvornog izraza quality check.
ignore-optional-pluralPreskoč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:
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 are 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:5Defines maximal width in pixels and, optionally, the maximum number of lines. Word wrapping is applied when more than one line is configured.
font-family:ubuntuDefines font group to use by specifying its identifier.
font-size:22Defines 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.
Subclass the weblate.checks.Check
Set a few attributes.
Implement either the
check(if you want to deal with plurals in your code) or thecheck_singlemethod (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