Weblate

5.17 · active · verified Fri Apr 17

Weblate is a free and open-source web-based continuous localization system that tightly integrates with version control systems (Git, Mercurial, SVN, etc.). It helps streamline the translation workflow for software projects, documentation, and websites. The current stable version is 5.17, and it generally follows Django's release cadence, with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a custom translation check for Weblate. Weblate is a Django application, and its 'library' usage primarily involves extending its functionality (e.g., custom checks, add-ons) by importing its base classes. This code is not standalone runnable but serves as an example of an extension you would integrate into a running Weblate instance by configuring it in `settings.py`.

import os
from weblate.checks.base import BaseCheck
from weblate.checks.base import CheckResult, WARNING

# This example defines a custom Weblate check.
# To run it, you would add it to your Weblate configuration (settings.py).
# It is not directly executable as a standalone script outside a Weblate instance.

class MyCustomLengthCheck(BaseCheck):
    # Unique ID for the check
    check_id = 'my-custom-length-check'
    # Human-readable name
    name = 'Too Long Translation Check'
    # Description for the user interface
    description = 'Checks if a translation exceeds a maximum allowed length.'
    # Default parameters, configurable via Weblate UI
    params = {'max_length': 50}

    def check(self, check_context):
        translation = check_context.translation
        source = check_context.source_string

        if translation and translation.text and source and source.text:
            max_len = self.get_param('max_length')
            if len(translation.text) > max_len:
                yield CheckResult(
                    start=0,
                    end=len(translation.text),
                    severity=WARNING,
                    message=f'Translation is too long ({len(translation.text)} chars), max allowed is {max_len} chars.'
                )

# Example of how you *might* register it (typically done in settings.py):
# WLB_CHECKS = {'my-custom-length-check': 'my_module.my_custom_check.MyCustomLengthCheck'}

print("Custom check 'MyCustomLengthCheck' defined. Register it in your Weblate settings.py to use it.")

view raw JSON →