PyCharm 2024.1 Help

Extract blocks of text from Django templates

Enable the Django plugin

This functionality relies on the Django plugin, which is bundled and enabled in PyCharm by default. If the relevant features aren't available, make sure that you didn't disable the plugin.

  1. Press Ctrl+Alt+S to open the IDE settings and then select Plugins.

  2. Open the Installed tab, find the Django plugin, and select the checkbox next to the plugin name.

PyCharm provides a dedicated intention action to wrap strings in Django templates in {% trans%}, or {% blocktrans%} tags.

The lines with i18n tags are marked with icon in the gutter.

Wrap block of text in translation tags

  1. Open the desired Django template for editing, and select strings to be marked for translation.

  2. Press Alt+Enter, or click the light bulb to reveal the list of available intention actions:

    intention action: wrap with trans tag
  3. Select intention action Wrap with 'trans' tag, and press Enter. PyCharm wraps selected text in translation tags.

    the element is wrapped with the trans tag

    If extracting text is performed for the first time, {% load i18n%} will be added.

Last modified: 28 March 2024