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 (Flamurka 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-textTreat a text as an reStructuredText document, affects Përkthim i pandryshuar.
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 Vargje vetëm për lexim.
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 Gjatësi maksimum e përkthimit.
xml-textTreat text as XML document, affects Sintaksë XML and Markup XML.
font-family:NAMEDefine font-family for rendering checks, see Administrim shkronjash.
font-weight:WEIGHTDefine font-weight for rendering checks, see Administrim shkronjash.
font-size:SIZEDefine font-size for rendering checks, see Administrim shkronjash.
font-spacing:SPACINGDefine letter spacing for rendering checks, see Administrim shkronjash.
icu-flags:FLAGSDefine flags for customizing the behavior of the ICU MessageFormat quality check.
icu-tag-prefix:PREFIXSet a required prefix for XML tags for the ICU MessageFormat quality check.
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:SOURCEMark this string as a variant of string with matching source. See Variante të vargut.
regex:REGEXShprehje e rregullt kundrejt të cilës duhen kërkuar përputhje te kartela përkthimi, shihni Shprehje e rregullt.
forbiddenIndicates forbidden translation in a glossary, see Forbidden translations.
strict-sameMake «Unchanged translation» avoid using built-in words blacklist, see Përkthim i pandryshuar.
check-glossaryEnable the S’ndjek fjalorthin quality check.
angularjs-formatEnable the Varg ndërshtënie AngularJS quality check.
c-formatEnable the Format C quality check.
c-sharp-formatEnable the Format C# quality check.
es-formatEnable the ECMAScript template literals quality check.
i18next-interpolationEnable the Ndërshtënie i18next quality check.
icu-message-formatEnable the ICU MessageFormat quality check.
java-formatEnable the Format Java quality check.
java-messageformatEnable the Java MessageFormat quality check.
javascript-formatEnable the Format JavaScript quality check.
lua-formatEnable the Format Lua quality check.
object-pascal-formatEnable the Format Objektesh Pascal quality check.
percent-placeholdersEnable the Vendmbajtëse përqindjeje quality check.
perl-formatEnable the Format Perl quality check.
php-formatEnable the Format PHP quality check.
python-brace-formatEnable the Format kllapash Python quality check.
python-formatEnable the Format Python quality check.
qt-formatEnable the Format Qt quality check.
qt-plural-formatEnable the Format shumësi Qt quality check.
ruby-formatEnable the Format Ruby quality check.
scheme-formatEnable the Format Schema quality check.
vue-formatEnable the Formatim i18n Vue quality check.
md-textTreat text as a Markdown document. Enable Lidhje Markdown, Referenca Markdown, and Sintaksë Markdown quality checks.
safe-htmlEnable the HTML jo e parrezik quality check.
urlThe string should consist of only a URL. Enable the URL quality check.
ignore-bbcodeSkip the Markup BBCode quality check.
ignore-duplicateSkip the Fjalë të njëpasnjëshme të përsëdytura quality check.
ignore-check-glossarySkip the S’ndjek fjalorthin quality check.
ignore-double-spaceSkip the Hapësirë dyshe quality check.
ignore-angularjs-formatSkip the Varg ndërshtënie AngularJS quality check.
ignore-c-formatSkip the Format C quality check.
ignore-c-sharp-formatSkip the Format C# quality check.
ignore-es-formatSkip the ECMAScript template literals quality check.
ignore-i18next-interpolationSkip the Ndërshtënie i18next quality check.
ignore-icu-message-formatSkip the ICU MessageFormat quality check.
ignore-java-formatSkip the Format Java quality check.
ignore-java-messageformatSkip the Java MessageFormat quality check.
ignore-javascript-formatSkip the Format JavaScript quality check.
ignore-lua-formatSkip the Format Lua quality check.
ignore-object-pascal-formatSkip the Format Objektesh Pascal quality check.
ignore-percent-placeholdersSkip the Vendmbajtëse përqindjeje quality check.
ignore-perl-formatSkip the Format Perl quality check.
ignore-php-formatSkip the Format PHP quality check.
ignore-python-brace-formatSkip the Format kllapash Python quality check.
ignore-python-formatSkip the Format Python quality check.
ignore-qt-formatSkip the Format Qt quality check.
ignore-qt-plural-formatSkip the Format shumësi Qt quality check.
ignore-ruby-formatSkip the Format Ruby quality check.
ignore-scheme-formatSkip the Format Schema quality check.
ignore-vue-formatSkip the Formatim i18n Vue quality check.
ignore-translatedSkip the Është përkthyer quality check.
ignore-inconsistentSkip the Jo i njëtrajtshëm quality check.
ignore-kashidaSkip the Është përdorur shkronjë Kashida quality check.
ignore-md-linkSkip the Lidhje Markdown quality check.
ignore-md-reflinkSkip the Referenca Markdown quality check.
ignore-md-syntaxSkip the Sintaksë Markdown quality check.
ignore-max-lengthSkip the Gjatësi maksimum e përkthimit quality check.
ignore-max-sizeSkip the Madhësi maksimum e përkthimit quality check.
ignore-escaped-newlineSkip the Mospërputhje n quality check.
ignore-end-colonSkip the Mospërputhje dy pikash quality check.
ignore-end-ellipsisSkip the Mospërputhje tre pikash quality check.
ignore-end-exclamationSkip the Mospërputhje pikëçuditjesh quality check.
ignore-end-stopSkip the Mospërputhje pike quality check.
ignore-end-questionSkip the Mospërputhje pikëpyetjesh quality check.
ignore-end-semicolonSkip the Mospërputhje pikëpresjesh quality check.
ignore-newline-countSkip the Mospërputhje ndërprerjesh rreshti quality check.
ignore-pluralsSkip the Mungon shumës quality check.
ignore-placeholdersSkip the Vendmbajtëse quality check.
ignore-punctuation-spacingSkip the Hapësirë pikësimi quality check.
ignore-regexSkip the Shprehje e rregullt quality check.
ignore-same-pluralsSkip the Shumës i njëjtë quality check.
ignore-begin-newlineSkip the Shenjë rresht i ri në fillim quality check.
ignore-begin-spaceSkip the Hapësira fillimi quality check.
ignore-end-newlineSkip the Shenjë rresht i ri në fund quality check.
ignore-end-spaceSkip the Hapësirë në fund quality check.
ignore-sameSkip the Përkthim i pandryshuar quality check.
ignore-safe-htmlSkip the HTML jo e parrezik quality check.
ignore-urlSkip the URL quality check.
ignore-xml-tagsSkip the Markup XML quality check.
ignore-xml-invalidSkip the Sintaksë XML quality check.
ignore-zero-width-spaceSkip the Hapësirë me gjerësi zero quality check.
ignore-ellipsisSkip the Tre pika quality check.
ignore-icu-message-format-syntaxSkip the Sintaksë ICU MessageFormat quality check.
ignore-long-untranslatedSkip the I papërkthyer prej kohësh quality check.
ignore-multiple-failuresSkip the Dështime të shumta kontrollesh quality check.
ignore-unnamed-formatSkip the Ndryshore të shumta të paemërtuara quality check.
ignore-optional-pluralSkip the Pa forma shumësi 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:
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.
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.
Subclass the weblate.checks.Check
Caktoni ndoca atribute.
Implement either the
check(if you want to deal with plurals in your code) or thecheck_singlemethod (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