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 weblate.trans.autofixes.base import AutoFix
class ReplaceFooWithBar(AutoFix):
"""Replace foo with bar."""
# Might be localized using gettext_lazy
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, 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:
Source string additional flags:
Additional info on source strings describes manual editing.
Masseredigering can be used to apply flags in batch.
Masseredigering 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).File-format specific flags.
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.
Here is a list of flags currently accepted:
read-onlyThe string is read-only and should not be edited in Weblate, see Skrivebeskyttede strenger.
terminologyUsed in Ordliste. 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 Maksimal lengde på oversettelse.
xml-textTreat text as XML document, affects XML-syntaks and XML-oppmerking.
font-family:NAMEDefine font-family for rendering checks, see Håndtering av skrifter.
font-weight:WEIGHTDefine font-weight for rendering checks, see Håndtering av skrifter.
font-size:SIZEDefine font-size for rendering checks, see Håndtering av skrifter.
font-spacing:SPACINGDefine letter spacing for rendering checks, see Håndtering av skrifter.
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 Plassholdere.
replacements:FROM:TO:FROM2:TO2...Replacements to perform when checking resulting text parameters (for example in Maksimal størrelse på oversettelse or Maksimal lengde på oversettelse). 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ært uttrykk.
discard:NAMEDiscards flag defined on a higher level.
forbiddenIndicates forbidden translation in a glossary, see Forbidden translations.
strict-sameMake the Uendret oversettelse 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 Plassholdere quality check.
bbcode-textTreat a text as an Bulletin Board Code (BBCode) document, affects Uendret oversettelse. Enables the BB-kode-oppmerking quality check.
check-glossaryEnables the Følger ikke ordlisten quality check.
fluent-partsEnables the Fluent parts quality check.
fluent-referencesEnables the Fluent references quality check.
fluent-target-inner-htmlEnables the Fluent translation inner HTML quality check.
fluent-target-syntaxEnables the Fluent translation syntax quality check.
angularjs-formatEnables the AngularJS interpoleringsstreng quality check.
automattic-components-formatEnables the Automattic components formatting 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 ECMASkript-mal litteraler quality check.
i18next-interpolationEnables the i18neste-interpolasjon quality check.
icu-message-formatEnables the ICU MessageFormat and ICU MessageFormat syntax quality checks.
java-printf-formatEnables the Java-format quality check.
java-formatEnables the Java-meldingsformat quality check.
auto-java-messageformatTreat a text as conditional Java MessageFormat, enabling Java-meldingsformat only when the source contains Java MessageFormat placeholders. Enables the Java-meldingsformat 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 Object Pascal format quality check.
objc-formatEnables the Objective-C format quality check.
percent-placeholdersEnables the Prosentplassholdere quality check.
perl-brace-formatEnables the Perl brace format quality check.
perl-formatEnables the Perl-format quality check.
php-formatEnables the PHP-format quality check.
python-brace-formatEnables the Python-klammeformat quality check.
python-formatEnables the Python-format quality check.
qt-formatEnables the Qt-format quality check.
qt-plural-formatEnables the Qt-flertallsform quality check.
ruby-formatEnables the Ruby-format quality check.
scheme-formatEnables the Scheme-filformat quality check.
vue-formatEnables the Vue I18n-formatering quality check.
rst-textTreat a text as an reStructuredText document, affects Uendret oversettelse. Enables the Inconsistent reStructuredText and reStructuredText syntax error quality checks.
md-textTreat a text as a Markdown document, and provide Markdown syntax highlighting on the translation text area. Enables the Markdown-lenker, Markdown-referanser and Markdown-syntaks quality checks.
max-lengthEnables the Maksimal lengde på oversettelse quality check.
max-sizeEnables the Maksimal størrelse på oversettelse quality check.
placeholdersEnables the Plassholdere quality check.
regexEnables the Regulært uttrykk quality check.
safe-htmlEnables the Utrygg HTML quality check.
auto-safe-htmlTreat a text as conditional HTML, enabling Utrygg 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 Utrygg HTML quality check.
urlThe string should consist of only a URL. Enables the Nettadresse quality check.
fluent-source-inner-htmlEnables the Fluent source inner HTML quality check.
fluent-source-syntaxEnables the Fluent source syntax quality check.
ignore-all-checksIgnore all quality checks.
ignore-bbcodeSkip the BB-kode-oppmerking quality check.
ignore-xml-chars-around-tagsSkip the Chars around XML tags quality check.
ignore-duplicateSkip the Påfølgende gjentatte ord quality check.
ignore-check-glossarySkip the Følger ikke ordlisten quality check.
ignore-double-spaceSkip the Dobbelt mellomrom quality check.
ignore-fluent-partsSkip the Fluent parts quality check.
ignore-fluent-referencesSkip the Fluent references quality check.
ignore-fluent-target-inner-htmlSkip the Fluent translation inner HTML quality check.
ignore-fluent-target-syntaxSkip the Fluent translation syntax quality check.
ignore-angularjs-formatSkip the AngularJS interpoleringsstreng quality check.
ignore-automattic-components-formatSkip the Automattic components formatting quality check.
ignore-c-formatSkip the C-format quality check.
ignore-c-sharp-formatSkip the C#-format quality check.
ignore-es-formatSkip the ECMASkript-mal litteraler quality check.
ignore-i18next-interpolationSkip the i18neste-interpolasjon quality check.
ignore-icu-message-formatSkip the ICU MessageFormat quality check.
ignore-java-printf-formatSkip the Java-format quality check.
ignore-java-formatSkip the Java-meldingsformat quality check.
ignore-javascript-formatSkip the JavaScript-format quality check.
ignore-laravel-formatSkip the Laravel format quality check.
ignore-lua-formatSkip the Lua-format quality check.
ignore-object-pascal-formatSkip the Object Pascal format quality check.
ignore-objc-formatSkip the Objective-C format quality check.
ignore-percent-placeholdersSkip the Prosentplassholdere quality check.
ignore-perl-brace-formatSkip the Perl brace format quality check.
ignore-perl-formatSkip the Perl-format quality check.
ignore-php-formatSkip the PHP-format quality check.
ignore-python-brace-formatSkip the Python-klammeformat quality check.
ignore-python-formatSkip the Python-format quality check.
ignore-qt-formatSkip the Qt-format quality check.
ignore-qt-plural-formatSkip the Qt-flertallsform quality check.
ignore-ruby-formatSkip the Ruby-format quality check.
ignore-scheme-formatSkip the Scheme-filformat quality check.
ignore-vue-formatSkip the Vue I18n-formatering quality check.
ignore-translatedSkip the Har blitt oversatt quality check.
ignore-inconsistentSkip the Inkonsekvent quality check.
ignore-rst-referencesSkip the Inconsistent reStructuredText quality check.
ignore-kashidaSkip the Kashida-bokstav i bruk quality check.
ignore-md-linkSkip the Markdown-lenker quality check.
ignore-md-reflinkSkip the Markdown-referanser quality check.
ignore-md-syntaxSkip the Markdown-syntaks quality check.
ignore-max-lengthSkip the Maksimal lengde på oversettelse quality check.
ignore-max-sizeSkip the Maksimal størrelse på oversettelse quality check.
ignore-escaped-newlineSkip the Mismatched \n quality check.
ignore-end-colonSkip the Manglende samsvar kolon quality check.
ignore-end-ellipsisSkip the Manglende samsvar utelatelsestegn quality check.
ignore-end-exclamationSkip the Mangler samsvarende utropstegn quality check.
ignore-end-stopSkip the Manglende samsvar avsluttende punktum quality check.
ignore-end-interrobangSkip the Mismatched interrobang quality check.
ignore-end-questionSkip the Manglende spørsmålstegn quality check.
ignore-end-semicolonSkip the Manglende samsvar semikolon quality check.
ignore-newline-countSkip the Ikke samsvarende linjeskift quality check.
ignore-pluralsSkip the Manglende flertall quality check.
ignore-multiple-capitalSkip the Multiple capitals quality check.
ignore-kabyle-charactersSkip the Non‑standard characters in Kabyle quality check.
ignore-placeholdersSkip the Plassholdere quality check.
ignore-prohibited-initial-characterSkip the Prohibited initial character quality check.
ignore-punctuation-spacingSkip the Tegnsettingsavstand quality check.
ignore-regexSkip the Regulært uttrykk quality check.
ignore-rst-syntaxSkip the reStructuredText syntax error quality check.
ignore-reusedSkip the Reused translation quality check.
ignore-same-pluralsSkip the Samme flertallsform quality check.
ignore-begin-newlineSkip the Starter linjeskift quality check.
ignore-begin-spaceSkip the Starter mellomrom quality check.
ignore-end-newlineSkip the Etterfølgende linjeskift quality check.
ignore-end-spaceSkip the Etterfølgende mellomrom quality check.
ignore-sameSkip the Uendret oversettelse quality check.
ignore-safe-htmlSkip the Utrygg HTML quality check.
ignore-urlSkip the Nettadresse quality check.
ignore-xml-tagsSkip the XML-oppmerking quality check.
ignore-xml-invalidSkip the XML-syntaks quality check.
ignore-zero-width-spaceSkip the Rom for Zero-bredde quality check.
ignore-ellipsisSkip the Utelatelsestegn quality check.
ignore-fluent-source-inner-htmlSkip the Fluent source inner HTML quality check.
ignore-fluent-source-syntaxSkip the Fluent source syntax quality check.
ignore-icu-message-formatSkip the ICU MessageFormat syntax quality check.
ignore-long-untranslatedSkip the Lenge uten oversettelse quality check.
ignore-multiple-failuresSkip the Flere kontroller som feiler quality check.
ignore-unnamed-formatSkip the Flere navnløse variabler quality check.
ignore-optional-pluralSkip the Flertall mangler quality check.
Merknad
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 Komponentoppsett 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.
Hint
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 Uendret oversettelse is not recommended because dismissal is sometimes a reasonable approach in these.
The Translation quality filter can then be used to exclude strings needing editing from being committed to the version control.
Håndtering av skrifter¶
Hint
Fonts uploaded into Weblate are used purely for purposes of the Maksimal størrelse på oversettelse check, they do not have an effect in Weblate user interface.
The Maksimal størrelse på oversettelse 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 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:
Du kan ha et antall skrifter innlastet i 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).
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).
Noen eksempler:
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.
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 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
# 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, 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.
"""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
# 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):
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