Weblate frontend

The frontend is currently built using Bootstrap, jQuery and few third-party libraries.

Supported browsers

Weblate supports the latest, stable releases of all major browsers and platforms.

Alternative browsers which use the latest version of WebKit, Blink, or Gecko, whether directly or via the platform’s web view API, are not explicitly supported. However, Weblate should (in most cases) display and function correctly in these browsers as well.

Older browsers might work, but some features might be limited.

Accessibility

Weblate targets WCAG 2.2 Level AA for new and changed user-facing functionality where practical. Use semantic HTML and Bootstrap components before adding custom interaction code.

When changing the frontend:

  • Make all interactive controls reachable and usable with a keyboard.

  • Keep focus order logical and preserve visible focus styling.

  • Prefer native buttons, links, inputs, selects, and tables over custom widgets.

  • Associate every form control with a label, help text, and validation errors where applicable.

  • Do not use color, icon shape, or position as the only way to convey state.

  • Announce dynamic status changes that are not otherwise visible to assistive technology.

  • Respect reduced-motion preferences for animation or scrolling behavior.

  • Test changed workflows with keyboard-only navigation and, when practical, a screen reader spot check.

User interface conventions

Dependency management

Installing and managing 3rd party libraries in the client of a Django project can be a bit tricky. This section provides a step-by-step guide on how to install and manage 3rd party libraries used by the client side of Weblate using Webpack.

Prerequisites

Before proceeding with an installation, make sure you have the following prerequisites:

  • A supported Node.js release.

  • The yarn package manager is installed on your system.

  • Run cd client.

  • Run yarn install --check-files.

The development container supplies Node.js and Yarn. Use ./scripts/devcontainer verify --check frontend to install dependencies with the frozen lockfile and build assets into a temporary directory without replacing the tracked vendor files.

Installation

To install a library, first run the following command:

yarn add <lib-name>

Importing the Library

Then, there are two ways to import the library:

  1. If it is a project-wide library (it is used/needed in all/most pages):
    • Import the library in src/main.js.

    • And declare it in the global scope (if needed).

  2. If it is page-specific library (library is used in a specific page or template):
    • Create a new file named src/<lib-name>.js.

    • Import the library in it. Then inject it into the window object to be globally accessible.

    • Add an entry in webpack.config.js: <lib-name>: "src/<lib-name>.js".

    • Add library name in excludePrefixes array in mainLicenseTransform in webpack.config.js.

    • Add license file name in additionalFiles in LicensePlugin in plugins array in webpack.config.js.

    • Create a <lib-name>LicenseTransform function for the license file introduced in the previous steps and use it.

    Note: Replace <lib-name> with the actual name of the 3rd party library.

Building the Library

Build the libraries used by the project, by running the following command:

yarn build

Including the Library

Now the library is built and ready for use. To include it follow these steps:

  1. If the library was imported in src/main.js, no further steps are required (as it is already included in base.html).

  2. If the library was imported in its specific file src/<lib-name>.js, in weblate/templates use the include tags to link to the built static JavaScript file:

{% load static %}
<script src="{% static 'js/vendor/<lib-name>.js' %}"></script>

Coding style

Weblate relies on Biome for formatting and linting the JavaScript and CSS code. Django templates are formatted and linted separately by djade and djlint.

Ruff bans crispy_forms.layout.HTML because crispy compiles its argument as template source. Use ContextDiv with a named Django template to add markup to a crispy form layout. Pass runtime values as template context so Django renders them as data with HTML autoescaping.

Crispy also compiles Fieldset legends and Submit labels as template source. Use application-defined strings for these arguments and check them during code review. The Ruff ban applies only to crispy_forms.layout.HTML.

Localization

Should you need any user visible text in the frontend code, it should be localizable. In most cases, all you need is to wrap your text inside gettext function, but there are more complex features available:

document.write(gettext("this is to be translated"));

var object_count = 1 // or 0, or 2, or 3, ...
s = ngettext("literal for the singular case",
        "literal for the plural case", object_count);

fmts = ngettext("There is %s object. Remaining: %s",
        "There are %s objects. Remaining: %s", 11);
s = interpolate(fmts, [11, 20]);
// s is "There are 11 objects. Remaining: 20"

Use force_escape on literal translations in quoted HTML attributes so that quotes in the translation cannot end the attribute.

<span title="{% translate 'Example tooltip'|force_escape %}">…</span>

When translating text with blocktranslate, account for the escaping of interpolated values. Applying force_escape to a rendered block can escape those values twice.

Place blocktranslate in element content when the translated text is a visible or visually hidden label. For text needed in an HTML attribute, use blocktranslate asvar in a narrow autoescape off block and apply force_escape when inserting the variable into the quoted attribute. This escapes the whole message once, including the interpolated values. For a URL query value, apply urlencode:"" to the assembled text.

Icons

Weblate currently uses Material Design Icons, in case you are looking for new symbol, check that.

Additionally, there is scripts/optimize-svg to reduce size of the SVG as most of the icons are embedded inside the HTML to allow styling of the paths.