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 © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
from django.utils.translation import gettext_lazy
from weblate.trans.autofixes.base import AutoFix
class ReplaceFooWithBar(AutoFix):
"""Replace foo with bar."""
name = gettext_lazy("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 Weblate’s behavior by using flags. The flags provide visual feedback to the translators and help them to improve their translation. This can be done on the source string level (see Additional info on source strings), or in the Component configuration (Fordítási jelzők). Some file formats also allow to specify flags directly in the format (see Supported file formats).
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 make sure that internal links are not being translated (i.e. [test](../checks) does not become [test](../chequeos).
Here is a list of flags currently accepted:
rst-textTreat a text as an reStructuredText document, affects Változatlan fordítások.
dos-eolUses DOS end-of-line markers instead of Unix ones (
\r\ninstead of\n).read-onlyThe string is read-only and should not be edited in Weblate, see Csak olvasható szövegek.
terminologyUsed in Szójegyzék. 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.
max-length:NLimit the maximal length for a string to N characters, see Fordítás legnagyobb hossza.
xml-textTreat text as XML document, affects XML szintaxis and XML jelölő.
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.
icu-flags:FLAGSDefine flags for customizing the behavior of the ICU-üzenetformátum quality check.
icu-tag-prefix:PREFIXSet a required prefix for XML tags for the ICU-üzenetformátum quality check.
placeholders:NAME:NAME2:...Placeholder strings expected in translation, see Helykitöltők.
replacements:FROM:TO:FROM2:TO2...Replacements to perform when checking resulting text parameters (for example in Fordítás legnagyobb mérete or Fordítás legnagyobb hossza). 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:REGEXRegular expression to match translation, see Reguláris kifejezés.
forbiddenIndicates forbidden translation in a glossary, see Forbidden translations.
strict-sameMake „Unchanged translation” avoid using built-in words blacklist, see Változatlan fordítások.
strict-formatMake format checks enforce using format even for plural forms with a single value, see Formatted strings.
check-glossaryEnable the Nem követi a szójegyzéket quality check.
angularjs-formatEnable the AngularJS interpolációs szöveg quality check.
c-formatEnable the C formátum quality check.
c-sharp-formatEnable the C# formátum quality check.
es-formatEnable the ECMAScript sablonszövegek quality check.
i18next-interpolationEnable the i18next interpoláció quality check.
icu-message-formatEnable the ICU-üzenetformátum quality check.
java-printf-formatEnable the Java formátum quality check.
java-formatEnable the Java-üzenetformátum quality check.
javascript-formatEnable the JavaScript formátum quality check.
lua-formatEnable the Lua formátum quality check.
object-pascal-formatEnable the Object Pascal formátum quality check.
percent-placeholdersEnable the Százalékos helykitöltők quality check.
perl-formatEnable the Perl formátum quality check.
php-formatEnable the PHP formátum quality check.
python-brace-formatEnable the Python brace formátum quality check.
python-formatEnable the Python formátum quality check.
qt-formatEnable the Qt formátum quality check.
qt-plural-formatEnable the Qt többes számú formátum quality check.
ruby-formatEnable the Ruby formátum quality check.
scheme-formatEnable the Scheme formátum quality check.
vue-formatEnable the Vue I18n formázás quality check.
md-textTreat text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables Markdown hivatkozások, Markdown referenciák, and Markdown szintaxis quality checks.
case-insensitiveAdjust checks behavior to be case-insensitive. Currently affects only Helykitöltők quality check.
safe-htmlEnable the Nem biztonságos HTML quality check.
urlThe string should consist of only a URL. Enable the URL quality check.
ignore-all-checksIgnore all quality checks.
ignore-bbcodeSkip the BBCode jelölő quality check.
ignore-duplicateSkip the Egymás utáni kettőzött szavak quality check.
ignore-check-glossarySkip the Nem követi a szójegyzéket quality check.
ignore-double-spaceSkip the Dupla szóköz quality check.
ignore-angularjs-formatSkip the AngularJS interpolációs szöveg quality check.
ignore-c-formatSkip the C formátum quality check.
ignore-c-sharp-formatSkip the C# formátum quality check.
ignore-es-formatSkip the ECMAScript sablonszövegek quality check.
ignore-i18next-interpolationSkip the i18next interpoláció quality check.
ignore-icu-message-formatSkip the ICU-üzenetformátum quality check.
ignore-java-printf-formatSkip the Java formátum quality check.
ignore-java-formatSkip the Java-üzenetformátum quality check.
ignore-javascript-formatSkip the JavaScript formátum quality check.
ignore-lua-formatSkip the Lua formátum quality check.
ignore-object-pascal-formatSkip the Object Pascal formátum quality check.
ignore-percent-placeholdersSkip the Százalékos helykitöltők quality check.
ignore-perl-formatSkip the Perl formátum quality check.
ignore-php-formatSkip the PHP formátum quality check.
ignore-python-brace-formatSkip the Python brace formátum quality check.
ignore-python-formatSkip the Python formátum quality check.
ignore-qt-formatSkip the Qt formátum quality check.
ignore-qt-plural-formatSkip the Qt többes számú formátum quality check.
ignore-ruby-formatSkip the Ruby formátum quality check.
ignore-scheme-formatSkip the Scheme formátum quality check.
ignore-vue-formatSkip the Vue I18n formázás quality check.
ignore-translatedSkip the Le lett fordítva quality check.
ignore-inconsistentSkip the Következetlen quality check.
ignore-kashidaSkip the Használt kasida betűk quality check.
ignore-md-linkSkip the Markdown hivatkozások quality check.
ignore-md-reflinkSkip the Markdown referenciák quality check.
ignore-md-syntaxSkip the Markdown szintaxis quality check.
ignore-max-lengthSkip the Fordítás legnagyobb hossza quality check.
ignore-max-sizeSkip the Fordítás legnagyobb mérete quality check.
ignore-escaped-newlineSkip the Mismatched \n quality check.
ignore-end-colonSkip the Nem egyező kettőspont quality check.
ignore-end-ellipsisSkip the Nem egyező hármaspont quality check.
ignore-end-exclamationSkip the Nem egyező felkiáltójel quality check.
ignore-end-stopSkip the Nem egyező mondatvégi pont quality check.
ignore-end-questionSkip the Nem egyező kérdőjel quality check.
ignore-end-semicolonSkip the Nem egyező pontosvessző quality check.
ignore-newline-countSkip the Nem egyező sortörések quality check.
ignore-pluralsSkip the Hiányzó többes számok quality check.
ignore-placeholdersSkip the Helykitöltők quality check.
ignore-punctuation-spacingSkip the Írásjel térköze quality check.
ignore-regexSkip the Reguláris kifejezés quality check.
ignore-reusedSkip the Újrahasznált fordítás quality check.
ignore-same-pluralsSkip the Ugyanaz a többes szám quality check.
ignore-begin-newlineSkip the Kezdő soremelés quality check.
ignore-begin-spaceSkip the Kezdő szóközök quality check.
ignore-end-newlineSkip the Lezáró soremelés quality check.
ignore-end-spaceSkip the Lezáró szóköz quality check.
ignore-sameSkip the Változatlan fordítások quality check.
ignore-safe-htmlSkip the Nem biztonságos HTML quality check.
ignore-urlSkip the URL quality check.
ignore-xml-tagsSkip the XML jelölő quality check.
ignore-xml-invalidSkip the XML szintaxis quality check.
ignore-zero-width-spaceSkip the Nulla szélességű szóköz quality check.
ignore-ellipsisSkip the Hármaspont quality check.
ignore-icu-message-format-syntaxSkip the ICU-üzenetformátum szintaxisa quality check.
ignore-long-untranslatedSkip the Régóta lefordítatlan quality check.
ignore-multiple-failuresSkip the Több sikertelen ellenőrzés quality check.
ignore-unnamed-formatSkip the Több névtelen változó quality check.
ignore-optional-pluralSkip the Többes szám nélküli quality check.
Megjegyzés
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#
You can configure a list of checks which can not be ignored by setting Kényszerített ellenőrzések 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).
Megjegyzés
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#
Tipp
Fonts uploaded into Weblate are used purely for purposes of the Fordítás legnagyobb mérete check, they do not have an effect in Weblate user interface.
The Fordítás legnagyobb mérete 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:
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 is 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:500Defines maximal width in pixels.
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 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.
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 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 © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""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
name = gettext_lazy("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.
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""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
name = gettext_lazy("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 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